diff --git a/cmd/luxtools/main.go b/cmd/luxtools/main.go deleted file mode 100644 index 8859dce..0000000 --- a/cmd/luxtools/main.go +++ /dev/null @@ -1,119 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "flag" - "log" - "net/http" - "os" - "os/signal" - "path/filepath" - "syscall" - "time" - - "estus-shots/internal/server" -) - -type appConfig struct { - MediaDir string `json:"media_dir"` -} - -func main() { - cfg := resolveConfig() - - srv, err := server.New(server.Config{MediaDir: cfg.MediaDir}) - if err != nil { - log.Fatalf("failed to configure server: %v", err) - } - - httpServer := &http.Server{ - Addr: srv.Address(), - Handler: srv.Router(), - ReadTimeout: 15 * time.Second, - WriteTimeout: 15 * time.Second, - IdleTimeout: 60 * time.Second, - } - - log.Printf( - "Estus Shots web server running on http://127.0.0.1%s (media: %s)", - srv.Address(), - cfg.MediaDir, - ) - - go func() { - if err := httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { - log.Fatalf("server error: %v", err) - } - }() - - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) - defer stop() - - <-ctx.Done() - shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - if err := httpServer.Shutdown(shutdownCtx); err != nil { - log.Printf("graceful shutdown failed: %v", err) - } else { - log.Println("server stopped") - } -} - -func resolveConfig() appConfig { - mediaDirFlag := flag.String("media-dir", "", "path to the media directory served at /media") - configPath := flag.String("config", "", "optional path to a JSON config file") - flag.Parse() - - cfg := appConfig{} - if *configPath != "" { - fileCfg, err := loadConfig(*configPath) - if err != nil { - log.Fatalf("failed to read config file: %v", err) - } - cfg = fileCfg - } - - if *mediaDirFlag != "" { - cfg.MediaDir = *mediaDirFlag - } - - if cfg.MediaDir == "" { - cfg.MediaDir = defaultMediaDir() - } - - return cfg -} - -func loadConfig(path string) (appConfig, error) { - data, err := os.ReadFile(path) - if err != nil { - return appConfig{}, err - } - - cfg := appConfig{} - if err := json.Unmarshal(data, &cfg); err != nil { - return appConfig{}, err - } - return cfg, nil -} - -func defaultMediaDir() string { - if cwd, err := os.Getwd(); err == nil { - candidate := filepath.Join(cwd, "media") - if info, err := os.Stat(candidate); err == nil && info.IsDir() { - return candidate - } - } - - if exe, err := os.Executable(); err == nil { - candidate := filepath.Join(filepath.Dir(exe), "media") - if info, err := os.Stat(candidate); err == nil && info.IsDir() { - return candidate - } - } - - return filepath.Join(".", "media") -} diff --git a/deploy/luxtools.service b/deploy/luxtools.service deleted file mode 100644 index 72a2244..0000000 --- a/deploy/luxtools.service +++ /dev/null @@ -1,19 +0,0 @@ -[Unit] -Description=estus-shots web service -After=network.target - -[Service] -Type=simple -ExecStart=/opt/estus-shots/bin/estus-shots -WorkingDirectory=/opt/estus-shots -Restart=on-failure -RestartSec=5 -User=estus-shots -Group=estus-shots -Environment=LOG_LEVEL=info -Environment=PORT=9000 -StandardOutput=journal -StandardError=journal - -[Install] -WantedBy=multi-user.target diff --git a/internal/server/template_data.go b/internal/server/template_data.go index 36b9382..f0cd85c 100644 --- a/internal/server/template_data.go +++ b/internal/server/template_data.go @@ -18,7 +18,6 @@ package server type PageData struct { Title string MenuGroups []MenuGroup - ShowClock bool } // MenuGroup represents a dropdown menu in the navbar. @@ -37,7 +36,6 @@ type MenuItem struct { // DefaultMenuBar returns the standard menu configuration. func DefaultMenuBar() PageData { return PageData{ - ShowClock: true, MenuGroups: []MenuGroup{ { Label: "Game", diff --git a/web/templates/menubar.html b/web/templates/menubar.html index 62c86be..806b606 100644 --- a/web/templates/menubar.html +++ b/web/templates/menubar.html @@ -18,8 +18,5 @@ {{end}} - {{if .ShowClock}} - - {{end}} {{end}}