feat: initial commit
This commit is contained in:
@ -2,25 +2,37 @@ package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/config"
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/http"
|
||||
kouizHTTP "forge.cadoles.com/wpetit/kouiz/internal/http"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func NewHTTPServerFromConfig(ctx context.Context, conf *config.Config) (*http.Server, error) {
|
||||
func NewHTTPServerFromConfig(ctx context.Context, conf *config.Config) (*kouizHTTP.Server, error) {
|
||||
// Configure Web UI handler
|
||||
webui, err := NewWebUIHandlerFromConfig(ctx, conf)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not configure webui handler from config")
|
||||
}
|
||||
|
||||
// Configure API handler
|
||||
api, err := NewAPIHandlerFromConfig(ctx, conf)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not configure webui handler from config")
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/", webui)
|
||||
mux.Handle("/api/", http.StripPrefix("/api", api))
|
||||
|
||||
// Create HTTP server
|
||||
|
||||
server := http.NewServer(
|
||||
webui,
|
||||
http.WithAddress(conf.HTTP.Address),
|
||||
http.WithBaseURL(conf.HTTP.BaseURL),
|
||||
server := kouizHTTP.NewServer(
|
||||
mux,
|
||||
kouizHTTP.WithAddress(conf.HTTP.Address),
|
||||
kouizHTTP.WithBaseURL(conf.HTTP.BaseURL),
|
||||
)
|
||||
|
||||
return server, nil
|
||||
|
Reference in New Issue
Block a user