实现音频服务api

This commit is contained in:
2026-01-09 23:33:14 +08:00
parent aae6a08850
commit 0e72dc7b6a
10 changed files with 240 additions and 150 deletions

10
main.go
View File

@@ -21,8 +21,12 @@ func main() {
r.Use(middleware.Logger)
libraryRepo := repository.NewLibraryRepository(GetDB())
songRepo := repository.NewSongRepository(GetDB())
mediaRepo := repository.NewMediaRepository(GetDB())
libraryService := service.NewLibraryService(libraryRepo)
songService := service.NewSongService(songRepo, mediaRepo)
libraryController := controller.NewLibraryController(libraryService)
songController := controller.NewSongController(songService)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
@@ -39,8 +43,12 @@ func main() {
r.Get("/{id}/songs", libraryController.GetSongs)
})
r.Route("/api/songs", func(r chi.Router) {
r.Get("/", songController.GetAllWithDetails)
r.Get("/{id}/stream", songController.Stream)
})
r.Route("/api", func(r chi.Router) {
r.Get("/songs", libraryController.GetAllSongs)
r.Get("/artists", libraryController.GetArtists)
r.Get("/albums", libraryController.GetAlbums)
})