62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"InfrantrySkillCalculator/controllers"
|
|
"InfrantrySkillCalculator/models"
|
|
"InfrantrySkillCalculator/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gorilla/sessions"
|
|
_ "github.com/gorilla/sessions"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
var store = sessions.NewCookieStore([]byte("f0q0qew0!)§(ds9713lsda231"))
|
|
|
|
const LoginSessionName = "session"
|
|
|
|
func main() {
|
|
//gin.SetMode(gin.ReleaseMode) // uncomment upon release
|
|
|
|
router := gin.New()
|
|
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, "/update"),
|
|
gin.Recovery(),
|
|
)
|
|
|
|
router.Static("/static", "./static")
|
|
|
|
router.GET("/login", loginPage)
|
|
router.POST("/login", loginPost)
|
|
router.GET("/logout", logout)
|
|
|
|
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)
|
|
|
|
log.Println("Running on 8000...")
|
|
log.Fatal(router.Run(":8000"))
|
|
}
|