remake in Golang
This commit is contained in:
40
api/routes/handler.go
Normal file
40
api/routes/handler.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"gitea.iceberg-gaming.com/17th-Ranger-Battalion-ORG/17th-UnitTracker-API/db"
|
||||
"gitea.iceberg-gaming.com/17th-Ranger-Battalion-ORG/17th-UnitTracker-API/ops"
|
||||
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var ErrInvalidPath = errors.New("invalid path")
|
||||
|
||||
func SetupRoutes(
|
||||
e *echo.Echo,
|
||||
) {
|
||||
|
||||
cfg := viper.GetViper()
|
||||
prefixURL := strings.TrimRight(cfg.GetString("API_PREFIX"), "/")
|
||||
mainPrefix := e.Group(prefixURL, func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// do something before the next handler
|
||||
// ensure we always have a db connection
|
||||
_, err := db.GetDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return next(c)
|
||||
}
|
||||
})
|
||||
|
||||
// MEMBER OPERATIONS
|
||||
g := mainPrefix.Group("/members")
|
||||
|
||||
g.GET("", ops.GetMembers)
|
||||
g.GET("/:id", ops.GetMember)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user