73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"InfantrySkillCalculator/controllers"
|
|
"InfantrySkillCalculator/models"
|
|
"InfantrySkillCalculator/utils"
|
|
"github.com/gin-gonic/gin"
|
|
_ "github.com/gorilla/sessions"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
//gin.SetMode(gin.ReleaseMode) // uncomment upon release
|
|
|
|
router := gin.New()
|
|
err := router.SetTrustedProxies([]string{"127.0.0.1"})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
router.LoadHTMLGlob("templates/**/*")
|
|
protected := router.Group("/")
|
|
protected.Use(AuthRequired())
|
|
|
|
models.ConnectDatabase()
|
|
|
|
f, _ := os.OpenFile("isc_rest.log", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
|
|
utils.GinWriter = io.MultiWriter(f, os.Stdout)
|
|
router.Use(
|
|
gin.LoggerWithWriter(utils.GinWriter, "/static"),
|
|
gin.Recovery(),
|
|
)
|
|
protected.Use(
|
|
gin.LoggerWithWriter(utils.GinWriter),
|
|
gin.Recovery(),
|
|
)
|
|
|
|
router.Static("/static", "./static")
|
|
|
|
router.GET("/login", loginPage)
|
|
router.POST("/login", loginPost)
|
|
router.GET("/logout", logout)
|
|
router.GET("/register", registerPage)
|
|
router.POST("/register", registerPost)
|
|
|
|
protected.GET("/", mainPage)
|
|
|
|
protected.GET("/clans", controllers.GetAllClans)
|
|
protected.GET("/clans_html", controllers.GetAllClansHTML)
|
|
protected.GET("/clan/:id", controllers.GetClanByID)
|
|
protected.POST("/clan", controllers.AddClan)
|
|
protected.PATCH("/clan/:id", controllers.UpdateClanByID)
|
|
protected.DELETE("/clan/:id", controllers.DeleteClanByID)
|
|
|
|
protected.GET("/players", controllers.GetAllPlayers)
|
|
protected.GET("/players_html", controllers.GetPlayersByClanHTML)
|
|
protected.GET("/player/:id", controllers.GetPlayerByID)
|
|
protected.GET("/playerid/:name", controllers.GetPlayerIDByName)
|
|
protected.POST("/player", controllers.AddPlayer)
|
|
protected.PATCH("/player/:id", controllers.UpdatePlayerByID)
|
|
protected.DELETE("/player/:id", controllers.DeletePlayerByID)
|
|
|
|
protected.GET("/game", controllers.GetGames)
|
|
protected.GET("/game_html", controllers.GetGamesHTML)
|
|
|
|
protected.GET("/settings", controllers.GetSettings)
|
|
protected.PATCH("/settings", controllers.UpdateSettings)
|
|
|
|
log.Println("Running on 8000...")
|
|
log.Fatal(router.Run(":8000"))
|
|
}
|