mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 15:51:09 +00:00
init
This commit is contained in:
43
internal/utl/configs/config.go
Normal file
43
internal/utl/configs/config.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package configs
|
||||
|
||||
import (
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
JellyfinURL string `envconfig:"JELLYFIN_URL" required:"true"`
|
||||
JellyfinAPIKey string `envconfig:"JELLYFIN_API_KEY" required:"true"`
|
||||
JellyfinUserID string `envconfig:"JELLYFIN_USER_ID" required:"true"`
|
||||
TMDbAPIKey string `envconfig:"TMDB_API_KEY" required:"true"`
|
||||
|
||||
LLMEnabled bool `envconfig:"LLM_ENABLED" default:"false"`
|
||||
LLMBaseURL string `envconfig:"LLM_BASE_URL" default:"http://localhost:11434/v1"`
|
||||
LLMAPIKey string `envconfig:"LLM_API_KEY" default:""`
|
||||
LLMModel string `envconfig:"LLM_MODEL" default:"llama3"`
|
||||
|
||||
RadarrEnabled bool `envconfig:"RADARR_ENABLED" default:"false"`
|
||||
RadarrURL string `envconfig:"RADARR_URL"`
|
||||
RadarrAPIKey string `envconfig:"RADARR_API_KEY"`
|
||||
RadarrQualityProfile int `envconfig:"RADARR_QUALITY_PROFILE_ID" default:"1"`
|
||||
RadarrRootFolder string `envconfig:"RADARR_ROOT_FOLDER" default:"/movies"`
|
||||
|
||||
CronEnabled bool `envconfig:"CRON_ENABLED" default:"false"`
|
||||
CronSchedule string `envconfig:"CRON_SCHEDULE" default:"0 3 * * *"`
|
||||
|
||||
APIEnabled bool `envconfig:"API_ENABLED" default:"true"`
|
||||
APIPort int `envconfig:"API_PORT" default:"8080"`
|
||||
|
||||
RecommendCount int `envconfig:"RECOMMEND_COUNT" default:"10"`
|
||||
MinRatedMovies int `envconfig:"MIN_RATED_MOVIES" default:"5"`
|
||||
}
|
||||
|
||||
// Load reads .env (best-effort) then processes environment variables into a Config.
|
||||
func Load() (*Config, error) {
|
||||
_ = godotenv.Load()
|
||||
var cfg Config
|
||||
if err := envconfig.Process("", &cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
16
internal/utl/httputil/httputil.go
Normal file
16
internal/utl/httputil/httputil.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package httputil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func WriteJSON(w http.ResponseWriter, status int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
_ = json.NewEncoder(w).Encode(v)
|
||||
}
|
||||
|
||||
func WriteError(w http.ResponseWriter, status int, msg string) {
|
||||
WriteJSON(w, status, map[string]string{"error": msg})
|
||||
}
|
||||
21
internal/utl/server/server.go
Normal file
21
internal/utl/server/server.go
Normal file
@@ -0,0 +1,21 @@
|
||||
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/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)
|
||||
return http.ListenAndServe(addr, mux)
|
||||
}
|
||||
Reference in New Issue
Block a user