diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2017-02-05 17:59:11 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2017-02-05 17:59:11 -0500 |
| commit | c7ab6d7782486fda6d6327ba8306e474daef677a (patch) | |
| tree | c4f1c238def681df7d4732400a64f31a58db54ac /web.go | |
| parent | 9ff47bdc17c70f87c78520d0636b2ff22918a408 (diff) | |
| download | steam-export-c7ab6d7782486fda6d6327ba8306e474daef677a.tar.gz steam-export-c7ab6d7782486fda6d6327ba8306e474daef677a.tar.xz | |
Initial development on web GUI
Diffstat (limited to 'web.go')
| -rw-r--r-- | web.go | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -0,0 +1,64 @@ +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]) + } +} |
