From 02a22b1a5b3d1b79028d933ff9e264f3a03e920d Mon Sep 17 00:00:00 2001 From: lczaplinski Date: Sun, 19 Mar 2017 21:09:55 +0100 Subject: [PATCH] PoC for UI --- actions/handlers/index.go | 95 +++++++++++++++++++++++++++++++++++++++ actions/http_server.go | 1 + http/context.go | 1 + http/iris.go | 4 ++ 4 files changed, 101 insertions(+) create mode 100644 actions/handlers/index.go diff --git a/actions/handlers/index.go b/actions/handlers/index.go new file mode 100644 index 0000000..6b25b6d --- /dev/null +++ b/actions/handlers/index.go @@ -0,0 +1,95 @@ +package handlers + +import "github.com/scoiatael/archai/http" + +const index = ` + + + + + + + Archai + + + + + + + +
+

React is loading...

+
+ + + + + + + + +` + +func (gs Handler) Index(ctx http.GetContext) { + ctx.SendHtml(index) +} diff --git a/actions/http_server.go b/actions/http_server.go index 1f86269..9f27c17 100644 --- a/actions/http_server.go +++ b/actions/http_server.go @@ -39,6 +39,7 @@ func (hs HttpServer) Run(c Context) error { jobs := c.BackgroundJobs() handler_context := handlers.Handler{HandlerContext{c}} handler.Get("/_check", func(ctx http.GetContext) { ctx.SendJson("OK") }) + handler.Get("/", handler_context.Index) handler.Get("/streams", handler_context.GetStreams) handler.Get("/stream/:id", handler_context.GetStream) handler.Post("/bulk/stream/:id", func(ctx http.PostContext) { diff --git a/http/context.go b/http/context.go index e8b49a9..b9ac4e2 100644 --- a/http/context.go +++ b/http/context.go @@ -10,6 +10,7 @@ type Context interface { type HttpContext interface { SendJson(interface{}) + SendHtml(string) GetSegment(string) string ServerErr(error) } diff --git a/http/iris.go b/http/iris.go index aa92d79..7fcbe91 100644 --- a/http/iris.go +++ b/http/iris.go @@ -17,6 +17,10 @@ func (hc IrisHttpContext) SendJson(response interface{}) { hc.JSON(iris.StatusOK, response) } +func (hc IrisHttpContext) SendHtml(response string) { + hc.HTML(iris.StatusOK, response) +} + func (hc IrisHttpContext) ServerErr(err error) { hc.context.HandleErr(err) hc.JSON(iris.StatusInternalServerError, iris.Map{"error": err.Error()})