You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
704 B

  1. package endpoint
  2. import (
  3. "github.com/arnaucube/gogame/config"
  4. "github.com/arnaucube/gogame/database"
  5. "github.com/arnaucube/gogame/services/usersrv"
  6. "github.com/gin-contrib/cors"
  7. "github.com/gin-gonic/gin"
  8. )
  9. var serverConfig config.Config
  10. var db *database.Db
  11. var userservice *usersrv.Service
  12. func newApiService() *gin.Engine {
  13. api := gin.Default()
  14. api.Use(cors.Default())
  15. api.GET("/", handleMain)
  16. api.GET("/info", handleInfo)
  17. api.POST("/register", handleRegister)
  18. api.POST("/login", handleLogin)
  19. return api
  20. }
  21. func Serve(cnfg config.Config, _db *database.Db, _userservice *usersrv.Service) *gin.Engine {
  22. serverConfig = cnfg
  23. db = _db
  24. userservice = _userservice
  25. return newApiService()
  26. }