This repository has been archived on 2024-08-30. You can view files and clone it, but cannot push or open issues or pull requests.
RaceBot/api/server.go
2023-04-16 12:21:01 +07:00

48 lines
1.1 KiB
Go

package api
import (
"fmt"
"git.rouggy.com/rouggy/RaceBot/controllers"
"git.rouggy.com/rouggy/RaceBot/internal/domain"
"github.com/gin-gonic/gin"
)
type Server struct {
listenAddr string
}
func NewServer(listenAddr string) *Server {
return &Server{
listenAddr: listenAddr,
}
}
func (s *Server) Start(cfg *domain.Config) error {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
s.SetupRoutes(r)
fmt.Println("Server is running on port:", cfg.Port)
err := r.Run(s.listenAddr)
if err != nil {
return err
}
return nil
}
func (s *Server) 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)
}