apply task package
This commit is contained in:
parent
46b2bb796f
commit
a10a04e1ce
4 changed files with 9 additions and 16 deletions
|
|
@ -15,6 +15,8 @@ import (
|
|||
"time"
|
||||
|
||||
"git.ronmi.tw/ronmi/forgejo-pages/lib"
|
||||
"github.com/raohwork/task"
|
||||
"github.com/raohwork/task/httptask"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -83,14 +85,7 @@ is up to you, eg. Nginx, Apache, or even a simple Go server.
|
|||
defer stop()
|
||||
|
||||
fmt.Println("starting server")
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
stop()
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
|
||||
defer cancel()
|
||||
s.Shutdown(ctx)
|
||||
}()
|
||||
s.ListenAndServe()
|
||||
httptask.Server(s, task.Timeout(10*time.Second)).Run(ctx)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
11
cmd/serve.go
11
cmd/serve.go
|
|
@ -14,6 +14,8 @@ import (
|
|||
"time"
|
||||
|
||||
"git.ronmi.tw/ronmi/forgejo-pages/lib"
|
||||
"github.com/raohwork/task"
|
||||
"github.com/raohwork/task/httptask"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -70,14 +72,7 @@ cache/protection layer like Cloudflare in front of the server.
|
|||
defer stop()
|
||||
|
||||
fmt.Println("starting server")
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
stop()
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
|
||||
defer cancel()
|
||||
s.Shutdown(ctx)
|
||||
}()
|
||||
s.ListenAndServe()
|
||||
httptask.Server(s, task.Timeout(10*time.Second)).Run(ctx)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
1
go.mod
1
go.mod
|
|
@ -14,6 +14,7 @@ require (
|
|||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/raohwork/task v0.3.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -26,6 +26,8 @@ github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h
|
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/raohwork/task v0.3.0 h1:4j0jT1a+f5O+g6q22o42sFEdSlYGYtgUHLbg3cF/7VE=
|
||||
github.com/raohwork/task v0.3.0/go.mod h1:QkVxY/Q/w6bW5Xjhcp8vn5qLgoS+70jUTyGueI0nzMo=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue