clearcase/internal/setup/webui_handler.go

49 lines
1.4 KiB
Go

package setup
import (
"context"
"forge.cadoles.com/wpetit/clearcase/internal/config"
"forge.cadoles.com/wpetit/clearcase/internal/http/handler/webui"
"forge.cadoles.com/wpetit/clearcase/internal/http/handler/webui/common"
"github.com/pkg/errors"
)
func NewWebUIHandlerFromConfig(ctx context.Context, conf *config.Config) (*webui.Handler, error) {
opts := make([]webui.OptionFunc, 0)
// Configure auth handler
authHandler, err := NewAuthHandlerFromConfig(ctx, conf)
if err != nil {
return nil, errors.Wrap(err, "could not configure auth handler from config")
}
authMiddleware := authHandler.Middleware()
opts = append(opts, webui.WithMount("/auth/", authHandler))
// Configure issue handler
issueHandler, err := NewIssueHandlerFromConfig(ctx, conf)
if err != nil {
return nil, errors.Wrap(err, "could not configure issue handler from config")
}
opts = append(opts, webui.WithMount("/", authMiddleware(issueHandler)))
// Configure common handler
commonHandler, err := NewCommonHandlerFromConfig(ctx, conf)
if err != nil {
return nil, errors.Wrap(err, "could not configure common handler from config")
}
opts = append(opts, webui.WithMount("/assets/", commonHandler))
handler := webui.NewHandler(opts...)
return handler, nil
}
func NewCommonHandlerFromConfig(ctx context.Context, conf *config.Config) (*common.Handler, error) {
return common.NewHandler(), nil
}