feat: initial commit

This commit is contained in:
2025-06-15 23:22:54 +02:00
parent 21b334bc70
commit b080f3eb55
12 changed files with 355 additions and 23 deletions

View File

@ -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