44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"git.rouggy.com/rouggy/RaceBot/config"
|
|
"git.rouggy.com/rouggy/RaceBot/controllers"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Server struct {
|
|
listenAddr string
|
|
}
|
|
|
|
func NewServer(listenAddr string) *Server {
|
|
return &Server{
|
|
listenAddr: listenAddr,
|
|
}
|
|
}
|
|
|
|
func (s *Server) Start() error {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
r := gin.Default()
|
|
SetupRoutes(r)
|
|
fmt.Println("Server is running on port:", config.HTTPPort)
|
|
r.Run(":" + config.HTTPPort)
|
|
}
|
|
|
|
func SetupRoutes(app *gin.Engine) {
|
|
|
|
api := app.Group("/api")
|
|
v1 := api.Group("/v1")
|
|
|
|
v1.GET("/races", controllers.GetAllRaces)
|
|
//v1.GET("/races/:id", controllers.GetReleaseById)
|
|
//v1.POST("/races", controllers.CreateRace)
|
|
//v1.PUT("/races/:id", controllers.UpdateRace)
|
|
//v1.DELETE("/races/:id", controllers.DeleteRace)
|
|
//v1.GET("/releases", controllers.GetReleases)
|
|
//v1.GET("/releases/:id", controllers.GetReleaseById)
|
|
v1.POST("/preraces", controllers.CreatePreRace)
|
|
//v1.PUT("/releases/:id", controllers.UpdateRelease)
|
|
//v1.DELETE("/releases/:id", controllers.DeleteRelease)
|
|
}
|