diff --git a/README.md b/README.md index cd58e5c..0b72829 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ import ( var staticContents embed.FS func main() { - api := asynqmon.NewAPI(asynqmon.APIOptions{ + api := asynqmon.NewHTTPHandler(asynqmon.Options{ RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, StaticContentHandler: asynqmon.NewStaticContentHandler( staticContents, diff --git a/api.go b/api.go index 66e6995..60916ac 100644 --- a/api.go +++ b/api.go @@ -13,32 +13,32 @@ import ( // MiddlewareFunc helps chain http.Handler(s). type MiddlewareFunc func(http.Handler) http.Handler -type APIOptions struct { +type Options struct { RedisConnOpt asynq.RedisConnOpt Middlewares []MiddlewareFunc PayloadFormatter PayloadFormatter StaticContentHandler http.Handler } -type API struct { +type HTTPHandler struct { router *mux.Router closers []func() error } -func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request) { +func (a *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { a.router.ServeHTTP(w, r) } -func NewAPI(opts APIOptions) *API { +func NewHTTPHandler(opts Options) *HTTPHandler { rc, ok := opts.RedisConnOpt.MakeRedisClient().(redis.UniversalClient) if !ok { - panic(fmt.Sprintf("asnyqmon.API: unsupported RedisConnOpt type %T", opts.RedisConnOpt)) + panic(fmt.Sprintf("asnyqmon.HTTPHandler: unsupported RedisConnOpt type %T", opts.RedisConnOpt)) } i := asynq.NewInspector(opts.RedisConnOpt) - return &API{router: muxRouter(opts, rc, i), closers: []func() error{rc.Close, i.Close}} + return &HTTPHandler{router: muxRouter(opts, rc, i), closers: []func() error{rc.Close, i.Close}} } -func (a *API) Close() error { +func (a *HTTPHandler) Close() error { for _, f := range a.closers { if err := f(); err != nil { return err @@ -48,7 +48,7 @@ func (a *API) Close() error { return nil } -func muxRouter(opts APIOptions, rc redis.UniversalClient, inspector *asynq.Inspector) *mux.Router { +func muxRouter(opts Options, rc redis.UniversalClient, inspector *asynq.Inspector) *mux.Router { router := mux.NewRouter() var pf PayloadFormatter = defaultPayloadFormatter diff --git a/cmd/asynqmon/main.go b/cmd/asynqmon/main.go index 6767637..9f550b1 100644 --- a/cmd/asynqmon/main.go +++ b/cmd/asynqmon/main.go @@ -105,7 +105,7 @@ func main() { } } - api := asynqmon.NewAPI(asynqmon.APIOptions{ + api := asynqmon.NewHTTPHandler(asynqmon.Options{ RedisConnOpt: redisConnOpt, Middlewares: []asynqmon.MiddlewareFunc{loggingMiddleware}, StaticContentHandler: asynqmon.NewStaticContentHandler( diff --git a/example_test.go b/example_test.go index 058cd04..e617e1a 100644 --- a/example_test.go +++ b/example_test.go @@ -12,8 +12,8 @@ import ( //go:embed ui-assets/* var staticContents embed.FS -func ExampleNewAPI() { - api := asynqmon.NewAPI(asynqmon.APIOptions{ +func ExampleNewHTTPHandler() { + api := asynqmon.NewHTTPHandler(asynqmon.Options{ RedisConnOpt: asynq.RedisClientOpt{Addr: ":6379"}, StaticContentHandler: asynqmon.NewStaticContentHandler( staticContents, diff --git a/go.mod b/go.mod index d6df67b..5975abf 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.16 require ( github.com/go-redis/redis/v8 v8.11.3 github.com/gorilla/mux v1.8.0 - github.com/hibiken/asynq v0.18.6-0.20210902125602-b3ef9e91a9ce + github.com/hibiken/asynq v0.18.6 github.com/rs/cors v1.7.0 ) diff --git a/go.sum b/go.sum index 1f72289..fd055f2 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,8 @@ github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/hibiken/asynq v0.18.6-0.20210902125602-b3ef9e91a9ce h1:pIvLWFWEkd6HcNQ3yVNb71hNcLBiwSFepxqJHOroNnk= -github.com/hibiken/asynq v0.18.6-0.20210902125602-b3ef9e91a9ce/go.mod h1:tyc63ojaW8SJ5SBm8mvI4DDONsguP5HE85EEl4Qr5Ig= +github.com/hibiken/asynq v0.18.6 h1:pBjtGh2QhDe1+/0yaSc56ANpdQ77BQgVfMIrj+NJrUM= +github.com/hibiken/asynq v0.18.6/go.mod h1:tyc63ojaW8SJ5SBm8mvI4DDONsguP5HE85EEl4Qr5Ig= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=