Remove Time display in menu bar
This commit is contained in:
@@ -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")
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
@@ -18,7 +18,6 @@ package server
|
|||||||
type PageData struct {
|
type PageData struct {
|
||||||
Title string
|
Title string
|
||||||
MenuGroups []MenuGroup
|
MenuGroups []MenuGroup
|
||||||
ShowClock bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MenuGroup represents a dropdown menu in the navbar.
|
// MenuGroup represents a dropdown menu in the navbar.
|
||||||
@@ -37,7 +36,6 @@ type MenuItem struct {
|
|||||||
// DefaultMenuBar returns the standard menu configuration.
|
// DefaultMenuBar returns the standard menu configuration.
|
||||||
func DefaultMenuBar() PageData {
|
func DefaultMenuBar() PageData {
|
||||||
return PageData{
|
return PageData{
|
||||||
ShowClock: true,
|
|
||||||
MenuGroups: []MenuGroup{
|
MenuGroups: []MenuGroup{
|
||||||
{
|
{
|
||||||
Label: "Game",
|
Label: "Game",
|
||||||
|
|||||||
@@ -18,8 +18,5 @@
|
|||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
{{if .ShowClock}}
|
|
||||||
<span class="tui-datetime" data-format="h:m:s a"></span>
|
|
||||||
{{end}}
|
|
||||||
</nav>
|
</nav>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
Reference in New Issue
Block a user