mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 15:51:09 +00:00
26 lines
736 B
Go
26 lines
736 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/fjurmanovic/sugarr/internal/api"
|
|
"github.com/fjurmanovic/sugarr/internal/service"
|
|
"github.com/fjurmanovic/sugarr/internal/utl/configs"
|
|
"github.com/fjurmanovic/sugarr/internal/utl/httputil"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// Start registers all routes and begins listening. Blocks until the server exits.
|
|
func Start(cfg *configs.Config, rec *service.Recommender) error {
|
|
mux := http.NewServeMux()
|
|
api.Init(mux, cfg, rec)
|
|
|
|
addr := fmt.Sprintf(":%d", cfg.APIPort)
|
|
log.Info().Msgf("HTTP API listening on %s", addr)
|
|
if cfg.APISecretKey != "" {
|
|
log.Info().Msg("Secret key auth enabled")
|
|
}
|
|
return http.ListenAndServe(addr, httputil.AuthMiddleware(cfg.APISecretKey, mux))
|
|
}
|