mirror of
https://github.com/tgdrive/teldrive.git
synced 2024-09-20 08:15:55 +08:00
refactor: readd server timeouts
This commit is contained in:
parent
5ff157aabc
commit
e7865a7637
13
cmd/run.go
13
cmd/run.go
|
@ -54,6 +54,8 @@ func NewRun() *cobra.Command {
|
|||
runCmd.Flags().IntVarP(&config.Server.Port, "server-port", "p", 8080, "Server port")
|
||||
duration.DurationVar(runCmd.Flags(), &config.Server.GracefulShutdown, "server-graceful-shutdown", 15*time.Second, "Server graceful shutdown timeout")
|
||||
runCmd.Flags().BoolVar(&config.Server.EnablePprof, "server-enable-pprof", false, "Enable Pprof Profiling")
|
||||
duration.DurationVar(runCmd.Flags(), &config.Server.ReadTimeout, "server-read-timeout", 1*time.Hour, "Server read timeout")
|
||||
duration.DurationVar(runCmd.Flags(), &config.Server.WriteTimeout, "server-write-timeout", 1*time.Hour, "Server write timeout")
|
||||
|
||||
runCmd.Flags().BoolVar(&config.CronJobs.Enable, "cronjobs-enable", true, "Run cron jobs")
|
||||
|
||||
|
@ -233,10 +235,15 @@ func initApp(lc fx.Lifecycle, cfg *config.Config, c *controller.Controller) *gin
|
|||
|
||||
r.Use(gin.Recovery())
|
||||
|
||||
skipPathRegexps := []*regexp.Regexp{
|
||||
regexp.MustCompile(`^/assets/.*`),
|
||||
regexp.MustCompile(`^/images/.*`),
|
||||
}
|
||||
|
||||
r.Use(ginzap.GinzapWithConfig(logging.DefaultLogger().Desugar(), &ginzap.Config{
|
||||
TimeFormat: time.RFC3339,
|
||||
UTC: true,
|
||||
SkipPaths: []string{"/favicon.ico", "/assets"},
|
||||
SkipPathRegexps: skipPathRegexps,
|
||||
}))
|
||||
|
||||
r.Use(middleware.Cors())
|
||||
|
@ -255,6 +262,10 @@ func initApp(lc fx.Lifecycle, cfg *config.Config, c *controller.Controller) *gin
|
|||
srv := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", cfg.Server.Port),
|
||||
Handler: r,
|
||||
ReadTimeout: cfg.Server.ReadTimeout,
|
||||
WriteTimeout: cfg.Server.WriteTimeout,
|
||||
ReadHeaderTimeout: 10 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
}
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
[server]
|
||||
graceful-shutdown = "15s"
|
||||
port = 8080
|
||||
read-timeout = "1h"
|
||||
write-timeout = "1h"
|
||||
|
||||
[tg]
|
||||
app-hash = ""
|
||||
|
@ -47,5 +49,5 @@
|
|||
threads = 8
|
||||
[tg.stream]
|
||||
multi-threads = 0
|
||||
buffers = 16
|
||||
buffers = 8
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ type ServerConfig struct {
|
|||
Port int
|
||||
GracefulShutdown time.Duration
|
||||
EnablePprof bool
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
}
|
||||
|
||||
type CronJobConfig struct {
|
||||
|
|
Loading…
Reference in a new issue