-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.go
68 lines (53 loc) · 1.65 KB
/
web.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"html/template"
"io"
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
// Web shiz yo
// Needs to get current server ip and query port from ENV on start
// Should display a error page in browser if those are not present, explaining
// how to create those and to restart the server.
// Look at using vue.js to make it all pretty
// TemplateRegistry struct
type TemplateRegistry struct {
templates *template.Template
}
// Render Implement e.Renderer interface
func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}
func initWeb(p string) {
e := echo.New()
e.Static("/css", "frontend/css")
e.Static("/js", "frontend/js")
e.File("/favicon.ico", "favicon.ico")
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.HideBanner = true
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET, echo.PUT, echo.POST, echo.DELETE},
}))
e.Renderer = &TemplateRegistry{
templates: template.Must(template.ParseGlob("frontend/*.html")),
}
e.GET("/", hello)
e.GET("/live", liveHandler)
e.Logger.Fatal(e.Start(":" + p))
}
// Handlers
func hello(c echo.Context) error {
// return c.String(http.StatusOK, "Hello, World!")
return c.Render(http.StatusOK, "index.html", map[string]interface{}{
"name": "Go Gaming Automated Server Manager",
"msg": "Hello, Yeeter",
"author": "Bobblehead",
"desc": "Manager for Atlas Server Grid on Docker",
})
}
func liveHandler(c echo.Context) error {
return c.String(http.StatusOK, "Live Stuff Goes Here")
}