mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
Simplify API routes mounting
This commit is contained in:
parent
5acc9c7a22
commit
48b465f2fb
2 changed files with 11 additions and 3 deletions
12
api/api.go
12
api/api.go
|
@ -26,17 +26,25 @@ type Router struct {
|
||||||
Scrobbler engine.Scrobbler
|
Scrobbler engine.Scrobbler
|
||||||
Search engine.Search
|
Search engine.Search
|
||||||
MediaFileRepository domain.MediaFileRepository
|
MediaFileRepository domain.MediaFileRepository
|
||||||
|
|
||||||
|
mux http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRouter(browser engine.Browser, cover engine.Cover, listGenerator engine.ListGenerator,
|
func NewRouter(browser engine.Browser, cover engine.Cover, listGenerator engine.ListGenerator,
|
||||||
playlists engine.Playlists, ratings engine.Ratings, scrobbler engine.Scrobbler, search engine.Search,
|
playlists engine.Playlists, ratings engine.Ratings, scrobbler engine.Scrobbler, search engine.Search,
|
||||||
mediaFileRepository domain.MediaFileRepository) *Router {
|
mediaFileRepository domain.MediaFileRepository) *Router {
|
||||||
|
|
||||||
return &Router{Browser: browser, Cover: cover, ListGenerator: listGenerator, Playlists: playlists,
|
r := &Router{Browser: browser, Cover: cover, ListGenerator: listGenerator, Playlists: playlists,
|
||||||
Ratings: ratings, Scrobbler: scrobbler, Search: search, MediaFileRepository: mediaFileRepository}
|
Ratings: ratings, Scrobbler: scrobbler, Search: search, MediaFileRepository: mediaFileRepository}
|
||||||
|
r.mux = r.routes()
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *Router) Routes() http.Handler {
|
func (api *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
api.mux.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *Router) routes() http.Handler {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
r.Use(checkRequiredParameters)
|
r.Use(checkRequiredParameters)
|
||||||
|
|
2
main.go
2
main.go
|
@ -12,6 +12,6 @@ func main() {
|
||||||
fmt.Printf("\nCloudSonic Server v%s\n\n", "0.2")
|
fmt.Printf("\nCloudSonic Server v%s\n\n", "0.2")
|
||||||
|
|
||||||
a := createApp(conf.Sonic.MusicFolder)
|
a := createApp(conf.Sonic.MusicFolder)
|
||||||
a.MountRouter("/rest/", initRouter().Routes())
|
a.MountRouter("/rest/", initRouter())
|
||||||
a.Run(":" + conf.Sonic.Port)
|
a.Run(":" + conf.Sonic.Port)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue