backseat-music/backseat/main.go
2025-07-22 20:35:12 +01:00

33 lines
853 B
Go

package main
import (
"fmt"
"git.akpain.net/codemicro/backseat-music/backseat/components/recentlyListened"
"git.akpain.net/codemicro/backseat-music/backseat/components/spotifyAuth"
"git.akpain.net/codemicro/backseat-music/backseat/config"
"git.akpain.net/codemicro/backseat-music/backseat/data"
"log/slog"
"net/http"
"os"
)
func main() {
if err := run(); err != nil {
slog.Error("unhandled error", "error", err)
os.Exit(1)
}
}
func run() error {
dataStore, err := data.NewStore(config.DataFileName)
if err != nil {
return fmt.Errorf("create data store: %w", err)
}
mux := http.NewServeMux()
mux.Handle("/recentlyListened/", recentlyListened.New(dataStore))
mux.Handle("/spotify/", spotifyAuth.New(dataStore))
slog.Info("server alive", "address", "http://"+config.HTTPAddr)
return http.ListenAndServe(config.HTTPAddr, mux)
}