Configure routing

This commit is contained in:
Alexander
2026-05-03 16:10:24 +02:00
parent 58aa4ef23b
commit 6baa895c6c
5 changed files with 55 additions and 5 deletions
+23
View File
@@ -4,3 +4,26 @@ config.yaml
/server /server
/vendor /vendor
pkg/metadatapb/ pkg/metadatapb/
# Ignore all
*
# Unignore all with extensions
!*.*
# Unignore all dirs
!*/
### Above combination will ignore all files without extension ###
# Ignore files with extension `.class` & `.sm`
*.class
*.sm
# Ignore `bin` dir
bin/
# or
*/bin/*
# Ignore config.yaml
config.yaml
+3 -2
View File
@@ -11,12 +11,12 @@ import (
// My modules // My modules
"homelab.lan/music-agregator/internal/config" "homelab.lan/music-agregator/internal/config"
appRouter "homelab.lan/music-agregator/internal/router"
) )
func main() { func main() {
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}). log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).
With().Timestamp().Logger() With().Timestamp().Logger()
router := gin.Default()
configPath := flag.String("config", "", "Path to the config file") configPath := flag.String("config", "", "Path to the config file")
flag.Parse() flag.Parse()
@@ -27,12 +27,13 @@ func main() {
} }
log.Info().Interface("config", cfg).Msg("Loaded config") log.Info().Interface("config", cfg).Msg("Loaded config")
router := gin.Default()
appRouter.SetupRoutes(router)
router.GET("/ping", func(c *gin.Context) { router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"message": "pong", "message": "pong",
}) })
}) })
router.Run() router.Run()
} }
+13
View File
@@ -0,0 +1,13 @@
package indexer
import (
"net/http"
"github.com/gin-gonic/gin"
)
func SetupRoutes(r *gin.RouterGroup) {
r.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "hello from indexer"})
})
}
+1 -3
View File
@@ -1,8 +1,6 @@
package indexer package indexer
import ( import ()
"fmt"
)
type Indexer interface { type Indexer interface {
} }
+15
View File
@@ -0,0 +1,15 @@
package router
import (
"homelab.lan/music-agregator/internal/indexer"
"github.com/gin-gonic/gin"
)
func SetupRoutes(r *gin.Engine) {
api := r.Group("/api/v1")
indexerGroup := api.Group("/indexer")
indexer.SetupRoutes(indexerGroup)
}