package main import ( "log" "git.riedstra.us/mitch/steam-export/lib/config" "git.riedstra.us/mitch/steam-export/lib/steam" "github.com/kataras/iris" ) func main() { config, err := config.LoadConfig() if err != nil { log.Fatal(err) } api := iris.New() api.Get("/api/libraries/", listLibraries(config)) api.Get("/api/libraries/:id", listLibrary(config)) api.Get("/data/:value/:and/:some/:giggles", dataTest()) api.Get("/data/:value/:and", dataTest()) api.Get("/data/:value", dataTest()) api.Listen(config.Listen) } func dataTest() iris.HandlerFunc { return func(ctx *iris.Context) { ctx.JSON(200, ctx.ParamsSentence()) } } func listLibraries(c *config.Config) iris.HandlerFunc { return func(ctx *iris.Context) { libs, err := steam.ProcessMultipleLibraries(c.SteamRepositories) if err != nil { ctx.JSON(500, err) } ctx.JSON(200, libs) } } func listLibrary(c *config.Config) iris.HandlerFunc { return func(ctx *iris.Context) { id, err := ctx.ParamInt("id") if err != nil { ctx.JSON(500, err) } libs, err := steam.ProcessMultipleLibraries(c.SteamRepositories) if err != nil { ctx.JSON(500, err) } if id >= len(libs) { ctx.JSON(500, &struct{ Error string }{Error: "Index out of bounds"}) } ctx.JSON(200, libs[id]) } }