mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-31 17:10:11 +08:00
add doc strings
This commit is contained in:
parent
d0b72f135c
commit
cb4ccea025
@ -13,6 +13,7 @@ import (
|
|||||||
// MiddlewareFunc helps chain http.Handler(s).
|
// MiddlewareFunc helps chain http.Handler(s).
|
||||||
type MiddlewareFunc func(http.Handler) http.Handler
|
type MiddlewareFunc func(http.Handler) http.Handler
|
||||||
|
|
||||||
|
// Options can be used to customise HTTPHandler.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
RedisConnOpt asynq.RedisConnOpt
|
RedisConnOpt asynq.RedisConnOpt
|
||||||
Middlewares []MiddlewareFunc
|
Middlewares []MiddlewareFunc
|
||||||
@ -20,15 +21,18 @@ type Options struct {
|
|||||||
StaticContentHandler http.Handler
|
StaticContentHandler http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTTPHandler can serve the API and UI required for asynq monitoring.
|
||||||
type HTTPHandler struct {
|
type HTTPHandler struct {
|
||||||
router *mux.Router
|
router *mux.Router
|
||||||
closers []func() error
|
closers []func() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServeHTTP will serve the API request as well as any static resources.
|
||||||
func (a *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (a *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
a.router.ServeHTTP(w, r)
|
a.router.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates an HTTPHandler that can be used to serve asynqmon web API with static contents.
|
||||||
func New(opts Options) *HTTPHandler {
|
func New(opts Options) *HTTPHandler {
|
||||||
rc, ok := opts.RedisConnOpt.MakeRedisClient().(redis.UniversalClient)
|
rc, ok := opts.RedisConnOpt.MakeRedisClient().(redis.UniversalClient)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -38,6 +42,7 @@ func New(opts Options) *HTTPHandler {
|
|||||||
return &HTTPHandler{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}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close will close connections to redis.
|
||||||
func (a *HTTPHandler) Close() error {
|
func (a *HTTPHandler) Close() error {
|
||||||
for _, f := range a.closers {
|
for _, f := range a.closers {
|
||||||
if err := f(); err != nil {
|
if err := f(); err != nil {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewStaticContentHandler creates a http.Handler which can be used to serve static files.
|
||||||
func NewStaticContentHandler(contents embed.FS, staticDirPath, indexFileName string) http.Handler {
|
func NewStaticContentHandler(contents embed.FS, staticDirPath, indexFileName string) http.Handler {
|
||||||
return &staticContentHandler{
|
return &staticContentHandler{
|
||||||
contents: contents,
|
contents: contents,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user