refactor: rewrite project from Rust to Go

- Replace Axum with Chi router
- Replace sqlx with pgx for PostgreSQL
- Replace tonic/prost with grpc-go
- Replace tracing with zerolog
- Update flake.nix for Go build with protoc generation
- Preserve all existing endpoints and functionality

Stack: Chi, pgx, grpc-go, zerolog, yaml.v3
This commit is contained in:
Alexander
2026-04-29 10:45:05 +02:00
parent f24543f401
commit 41fb033d30
48 changed files with 2306 additions and 6652 deletions
+54
View File
@@ -0,0 +1,54 @@
package api
import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
)
func NewRouter(h *Handlers) *chi.Mux {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"},
AllowCredentials: true,
MaxAge: 300,
}))
r.Get("/health", h.Health)
r.Route("/api", func(r chi.Router) {
r.Route("/indexers", func(r chi.Router) {
r.Get("/", h.ListIndexers)
r.Post("/search", h.SearchIndexers)
})
r.Route("/torrents", func(r chi.Router) {
r.Get("/", h.ListTorrents)
r.Post("/", h.AddTorrent)
r.Get("/{hash}", h.GetTorrent)
r.Delete("/{hash}", h.RemoveTorrent)
r.Post("/{hash}/pause", h.PauseTorrent)
r.Post("/{hash}/resume", h.ResumeTorrent)
})
r.Route("/metadata", func(r chi.Router) {
r.Post("/artists/search", h.SearchArtists)
r.Get("/artists/{id}/albums", h.GetArtistAlbums)
})
r.Post("/sync", h.Sync)
r.Route("/library", func(r chi.Router) {
r.Get("/artists", h.ListLibraryArtists)
r.Get("/albums", h.ListLibraryAlbums)
r.Get("/stats", h.LibraryStats)
})
})
return r
}