-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (37 loc) · 1016 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"amirhossein-shakeri/gin-boilerplate/auth"
"amirhossein-shakeri/gin-boilerplate/db"
"log"
"os"
"github.com/gin-gonic/gin"
_ "github.com/joho/godotenv/autoload"
)
var PORT = os.Getenv("PORT")
var ADDRESS = os.Getenv("DOMAIN") + ":" + PORT
var APP_NAME = os.Getenv("APP_NAME")
func main() {
log.Printf("🚀 Starting %v Server ...\n", APP_NAME)
if PORT == "" || ADDRESS == ":" {
log.Panicln("Please set environment variables ...")
}
db.InitMGM()
gin.ForceConsoleColor()
mainRouter := gin.Default()
setupRoutes(mainRouter)
mainRouter.Run(ADDRESS)
}
func setupRoutes(router *gin.Engine) {
router.Any("/health", healthHandler)
authRouter := router.Group("/auth")
{
authRouter.GET("/", auth.AuthorizeJWT(), auth.GetInfo) // get session info
authRouter.POST("/", auth.Login) // login
authRouter.POST("/signup", auth.Signup) // signup
}
}
func healthHandler(ctx *gin.Context) {
ctx.JSON(200, gin.H{
"message": "I'm Alive!",
})
}