package main import ( "net/http" "os" "log" "regexp" . "git.1750studios.com/gronkhDE/gogronkh/gserver/utlis" "git.1750studios.com/gronkhDE/gogronkh/gserver/apiv3" "git.1750studios.com/gronkhDE/gogronkh/config" "git.1750studios.com/gronkhDE/gogronkh/database" "github.com/gin-gonic/gin" ) var descRegEx *regexp.Regexp func initRouter() *gin.Engine { router := gin.Default() router.Use(PiwikRequest()) router.Static("/assets", config.C.AssetsDirectory) router.Static("/art", config.C.ImageDirectory) router.LoadHTMLGlob(config.C.TemplatesDirectory + "*") // Web UI router.GET("/", GetIndex) router.GET("/lets-play/:lslug/:eslug", GetLEpisode) router.GET("/lets-play/:lslug", GetLEpisode) router.GET("/lets-play", GetLps) router.GET("/testet", GetLt) router.GET("/testet/:tslug", GetLt) router.GET("/zeige", GetAt) router.GET("/zeige/:aslug", GetAt) router.GET("/zeige/:aslug/lets-play", GetAtLps) router.GET("/zeige/:aslug/testet", GetAtLts) router.GET("/zeige/:aslug/episoden", GetAtEps) // API api := router.Group("/api") api.GET("/version", func(c *gin.Context) { var current int = 3 var deprecated []int = []int{} var deleted []int = []int{2, 1, 0,} c.JSON(http.StatusOK, gin.H{"current": current, "deprecated": deprecated, "deleted": deleted}) }) // API Version: v3 v3 := api.Group("/v3") { v3.GET("/author/:aid/tests", apiv3.GetAuthorTests) v3.GET("/author/:aid/lets-plays", apiv3.GetAuthorLps) v3.GET("/authors/*aid", apiv3.GetAuthors) v3.GET("/tests/*tid", apiv3.GetTests) v3.GET("/lets-play/:lid/episodes/*eid", apiv3.GetLpEpisodes) v3.GET("/lets-plays/*lid", apiv3.GetLps) v3.GET("/recent/*limit", apiv3.GetRecent) v3.GET("/search/:type/:query", apiv3.GetSearch) } return router } func main() { log.SetFlags(log.Lshortfile) log.SetOutput(os.Stderr) var err error if os.Getenv("GIN_MODE") == "release" { err = config.LoadConfig("/etc/gogronkh/gronkh.json") } else { err = config.LoadConfig("/home/andreas/.gronkh.json") } if err != nil { log.Fatalf("FAT Config error: %+v", err) return } descRegEx = regexp.MustCompile("(?m)^\u00B7{5,}$") err = database.InitDb(config.C.DatabaseConnection) router := initRouter() if config.C.UseSocket { router.RunUnix(config.C.BindSocket) } else { router.Run(config.C.BindAddress) } }