80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"InfrantrySkillCalculator/controllers"
|
|
"InfrantrySkillCalculator/models"
|
|
"InfrantrySkillCalculator/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"html/template"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
//gin.SetMode(gin.ReleaseMode) // uncomment upon release
|
|
|
|
router := gin.New()
|
|
|
|
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("/", func(c *gin.Context) {
|
|
files := []string{
|
|
"./templates/index.html",
|
|
"./templates/components/home_clan_bar.html",
|
|
"./templates/components/opp_clan_bar.html",
|
|
"./templates/components/home_player_list.html",
|
|
"./templates/components/opp_player_list.html",
|
|
"./templates/components/bottom_controls.html",
|
|
"./templates/modals/delete_clan.html",
|
|
"./templates/modals/add_clan.html",
|
|
"./templates/modals/edit_clan.html",
|
|
"./templates/modals/add_player.html",
|
|
"./templates/components/header.html",
|
|
}
|
|
tmpl, err := template.ParseFiles(files...)
|
|
|
|
var clans []models.Clan
|
|
models.DB.Find(&clans)
|
|
|
|
data := map[string]interface{}{
|
|
"clans": clans,
|
|
}
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
err = tmpl.Execute(c.Writer, data)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
})
|
|
|
|
router.GET("/clans", controllers.GetAllClans)
|
|
router.GET("/clans_html", controllers.GetAllClansHTML)
|
|
router.GET("/clan/:id", controllers.GetClanByID)
|
|
router.POST("/clan", controllers.AddClan)
|
|
router.PATCH("/clan/:id", controllers.UpdateClanByID)
|
|
router.DELETE("/clan/:id", controllers.DeleteClanByID)
|
|
|
|
router.GET("/players", controllers.GetAllPlayers)
|
|
router.GET("/players_html", controllers.GetPlayersByClanHTML)
|
|
router.GET("/player/:id", controllers.GetPlayerByID)
|
|
router.GET("/playerid/:name", controllers.GetPlayerIDByName)
|
|
router.POST("/player", controllers.AddPlayer)
|
|
router.PATCH("/player/:id", controllers.UpdatePlayerByID)
|
|
router.DELETE("/player/:id", controllers.DeletePlayerByID)
|
|
|
|
log.Println("Running on 8000...")
|
|
log.Fatal(router.Run(":8000"))
|
|
}
|