A fork of https://github.com/teal-fm/piper

fix build errors

+9 -7
+1 -1
.air.toml
··· 5 [build] 6 args_bin = [] 7 bin = "./tmp/main" 8 - cmd = "go build -o ./tmp/main ./cmd/main.go" 9 delay = 1000 10 exclude_dir = ["assets", "tmp", "vendor", "testdata"] 11 exclude_file = []
··· 5 [build] 6 args_bin = [] 7 bin = "./tmp/main" 8 + cmd = "go build -o ./tmp/main ./cmd" 9 delay = 1000 10 exclude_dir = ["assets", "tmp", "vendor", "testdata"] 11 exclude_file = []
+2 -2
cmd/main.go
··· 99 mbService: mbService, 100 spotifyService: spotifyService, 101 atprotoService: atprotoService, 102 - } // MusicBrainz (public?) 103 104 trackerInterval := time.Duration(viper.GetInt("tracker.interval")) * time.Second 105 lastfmInterval := time.Duration(viper.GetInt("lastfm.interval_seconds")) * time.Second // Add config for Last.fm interval ··· 117 serverAddr := fmt.Sprintf("%s:%s", viper.GetString("server.host"), viper.GetString("server.port")) 118 server := &http.Server{ 119 Addr: serverAddr, 120 - Handler: routes(app), 121 IdleTimeout: time.Minute, 122 ReadTimeout: 5 * time.Second, 123 WriteTimeout: 10 * time.Second,
··· 99 mbService: mbService, 100 spotifyService: spotifyService, 101 atprotoService: atprotoService, 102 + } 103 104 trackerInterval := time.Duration(viper.GetInt("tracker.interval")) * time.Second 105 lastfmInterval := time.Duration(viper.GetInt("lastfm.interval_seconds")) * time.Second // Add config for Last.fm interval ··· 117 serverAddr := fmt.Sprintf("%s:%s", viper.GetString("server.host"), viper.GetString("server.port")) 118 server := &http.Server{ 119 Addr: serverAddr, 120 + Handler: app.routes(), 121 IdleTimeout: time.Minute, 122 ReadTimeout: 5 * time.Second, 123 WriteTimeout: 10 * time.Second,
+6 -4
cmd/routes.go
··· 3 import ( 4 "net/http" 5 6 "github.com/spf13/viper" 7 "github.com/teal-fm/piper/session" 8 ) 9 10 - func routes(app *application) http.Handler { 11 mux := http.NewServeMux() 12 13 mux.HandleFunc("/", session.WithPossibleAuth(home(app.database), app.sessionManager)) ··· 29 30 mux.HandleFunc("/api/v1/current-track", session.WithAPIAuth(apiCurrentTrack(app.spotifyService), app.sessionManager)) // Spotify Current 31 mux.HandleFunc("/api/v1/history", session.WithAPIAuth(apiTrackHistory(app.spotifyService), app.sessionManager)) // Spotify History 32 - mux.HandleFunc("/api/v1/musicbrainz/search", apiMusicBrainzSearch(app.mbService)) 33 34 serverUrlRoot := viper.GetString("server.root_url") 35 atpClientId := viper.GetString("atproto.client_id") 36 atpCallbackUrl := viper.GetString("atproto.callback_url") 37 - http.HandleFunc("/.well-known/client-metadata.json", func(w http.ResponseWriter, r *http.Request) { 38 app.atprotoService.HandleClientMetadata(w, r, serverUrlRoot, atpClientId, atpCallbackUrl) 39 }) 40 mux.HandleFunc("/oauth/jwks.json", app.atprotoService.HandleJwks) 41 42 - return mux 43 }
··· 3 import ( 4 "net/http" 5 6 + "github.com/justinas/alice" 7 "github.com/spf13/viper" 8 "github.com/teal-fm/piper/session" 9 ) 10 11 + func (app *application) routes() http.Handler { 12 mux := http.NewServeMux() 13 14 mux.HandleFunc("/", session.WithPossibleAuth(home(app.database), app.sessionManager)) ··· 30 31 mux.HandleFunc("/api/v1/current-track", session.WithAPIAuth(apiCurrentTrack(app.spotifyService), app.sessionManager)) // Spotify Current 32 mux.HandleFunc("/api/v1/history", session.WithAPIAuth(apiTrackHistory(app.spotifyService), app.sessionManager)) // Spotify History 33 + mux.HandleFunc("/api/v1/musicbrainz/search", apiMusicBrainzSearch(app.mbService)) // MusicBrainz (public?) 34 35 serverUrlRoot := viper.GetString("server.root_url") 36 atpClientId := viper.GetString("atproto.client_id") 37 atpCallbackUrl := viper.GetString("atproto.callback_url") 38 + mux.HandleFunc("/.well-known/client-metadata.json", func(w http.ResponseWriter, r *http.Request) { 39 app.atprotoService.HandleClientMetadata(w, r, serverUrlRoot, atpClientId, atpCallbackUrl) 40 }) 41 mux.HandleFunc("/oauth/jwks.json", app.atprotoService.HandleJwks) 42 43 + standard := alice.New() 44 + return standard.Then(mux) 45 }