feat: add request timeout #12

Open
bissendorf wants to merge 1 commits from feat/timeout into dev
3 changed files with 11 additions and 4 deletions
Showing only changes of commit 2abebfd01b - Show all commits

View File

@ -1,8 +1,11 @@
package cmd
const DefaultRequestTimeout uint = 30
type AppConfig struct {
OutputVerbose bool
OutputFormatter string
OutputOrderReverse bool
PrintConfig bool
RequestTimeoutSeconds uint
}

View File

@ -34,6 +34,7 @@ func initRootCmd() {
rootCmd.PersistentFlags().StringVarP(&appConfig.OutputFormatter, "output", "o", "table", "Set output format")
rootCmd.PersistentFlags().BoolVar(&appConfig.OutputOrderReverse, "reverse", false, "Reverses output item order")
rootCmd.PersistentFlags().BoolVar(&appConfig.PrintConfig, "print-config", false, "Enable printing the application config")
rootCmd.PersistentFlags().UintVar(&appConfig.RequestTimeoutSeconds, "timeout", DefaultRequestTimeout, "Set the request timeout in seconds")
logger := jlog.New(slog.LevelDebug)
ctx := jlog.ContextWith(context.Background(), logger)

View File

@ -8,6 +8,7 @@ import (
"os"
"slices"
"strings"
"time"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces/params"
@ -92,6 +93,8 @@ func getVerbs(ctx context.Context, config *AppConfig) (commands []*cobra.Command
}
logger := jlog.New(logLevel)
ctx := jlog.ContextWith(context.Background(), logger)
ctx, cancel := context.WithTimeout(ctx, time.Duration(config.RequestTimeoutSeconds)*time.Second)
defer cancel()
// Print config
if config.PrintConfig {