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, 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_bar.html", "./templates/components/opp_player_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/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("/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) log.Println("Running on 8000...") log.Fatal(router.Run(":8000")) }