fix: move shit to parent folder
This commit is contained in:
parent
7a5d8edfc6
commit
7d869ea36d
6 changed files with 3 additions and 0 deletions
26
internal/api/api.go
Normal file
26
internal/api/api.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"stereo.cat/backend/internal/types"
|
||||
)
|
||||
|
||||
func Register(cfg *types.StereoConfig) []types.Route {
|
||||
routes := []types.Route{
|
||||
{
|
||||
Path: "/ping",
|
||||
Method: http.MethodGet,
|
||||
Exec: func(cfg *types.StereoConfig) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.String(http.StatusOK, "Pong!")
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
types.RegisterRoutes("/api", routes, cfg)
|
||||
|
||||
return routes
|
||||
}
|
24
internal/types/types.go
Normal file
24
internal/types/types.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Route struct {
|
||||
Path string
|
||||
Method string
|
||||
Exec func(cfg *StereoConfig) gin.HandlerFunc
|
||||
}
|
||||
|
||||
type StereoConfig struct {
|
||||
Router *gin.Engine
|
||||
ImagePath string
|
||||
}
|
||||
|
||||
func RegisterRoutes(groupName string, routes []Route, cfg *StereoConfig) {
|
||||
group := cfg.Router.Group(groupName)
|
||||
|
||||
for _, route := range routes {
|
||||
group.Handle(route.Method, route.Path, route.Exec(cfg))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue