add doc strings

This commit is contained in:
ajatprabha 2021-10-04 20:54:37 +05:30 committed by Ken Hibino
parent d0b72f135c
commit cb4ccea025
2 changed files with 6 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import (
// MiddlewareFunc helps chain http.Handler(s).
type MiddlewareFunc func(http.Handler) http.Handler
// Options can be used to customise HTTPHandler.
type Options struct {
RedisConnOpt asynq.RedisConnOpt
Middlewares []MiddlewareFunc
@ -20,15 +21,18 @@ type Options struct {
StaticContentHandler http.Handler
}
// HTTPHandler can serve the API and UI required for asynq monitoring.
type HTTPHandler struct {
router *mux.Router
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) {
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 {
rc, ok := opts.RedisConnOpt.MakeRedisClient().(redis.UniversalClient)
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}}
}
// Close will close connections to redis.
func (a *HTTPHandler) Close() error {
for _, f := range a.closers {
if err := f(); err != nil {

View File

@ -8,6 +8,7 @@ import (
"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 {
return &staticContentHandler{
contents: contents,