初始化项目

This commit is contained in:
2026-01-08 20:48:55 +08:00
commit 0cc737a8dd
66 changed files with 7410 additions and 0 deletions

49
main.go Normal file
View File

@@ -0,0 +1,49 @@
package main
import (
"butterfliu/internal/controller"
"butterfliu/internal/repository"
"butterfliu/internal/service"
"log"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
func main() {
err := InitDB("./butterfliu.db")
if err != nil {
log.Fatal(err)
}
r := chi.NewRouter()
r.Use(middleware.Logger)
libraryRepo := repository.NewLibraryRepository(GetDB())
libraryService := service.NewLibraryService(libraryRepo)
libraryController := controller.NewLibraryController(libraryService)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
})
r.Route("/api/libraries", func(r chi.Router) {
r.Get("/", libraryController.GetAll)
r.Post("/", libraryController.Create)
r.Put("/{id}/name", libraryController.UpdateName)
r.Put("/{id}/path", libraryController.UpdatePath)
r.Post("/{id}/scan", libraryController.Scan)
r.Get("/scan-status", libraryController.GetScanStatus)
r.Delete("/{id}", libraryController.Delete)
r.Get("/{id}/songs", libraryController.GetSongs)
})
r.Route("/api", func(r chi.Router) {
r.Get("/songs", libraryController.GetAllSongs)
r.Get("/artists", libraryController.GetArtists)
r.Get("/albums", libraryController.GetAlbums)
})
http.ListenAndServe(":8102", r)
}