add cmd dir and move templates over

This commit is contained in:
cubixle
2022-08-03 15:29:35 +01:00
parent 6a93d24444
commit 1ad835f11f
6 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
host: localhost:8080
debug: false

View File

@@ -0,0 +1,43 @@
package main
import (
"log"
"os"
"{{resources_pkg}}"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
"github.com/tuukoti/framework/config"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
cfgPath := getEnv("TUUKOTI_CONFIG", "./config.yml")
cfg, err := config.Load(cfgPath)
if err != nil {
return err
}
log := logrus.New()
e := echo.New()
http.RegisterRoutes(e, log)
return e.Start(cfg.Host)
}
func getEnv(name, defaultValue string) string {
v := os.Getenv(name)
if v == "" {
return defaultValue
}
return v
}

View File

@@ -0,0 +1,25 @@
package http
import (
"net/http"
"github.com/labstack/echo/v4"
)
func (h *HTTP) DefaultHandler(c echo.Context) error {
return c.Render(http.StatusOK, "index.html", nil)
}
func (h *HTTP) DefaultErrorHandler(err error, c echo.Context) {
code := http.StatusInternalServerError
if he, ok := err.(*echo.HTTPError); ok {
code = he.Code
}
h.log.Error(err)
err = c.Render(code, "error.html", nil)
if err != nil {
h.log.Error(err)
}
}

View File

@@ -0,0 +1,18 @@
package http
import (
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)
type HTTP struct {
log *logrus.Logger
}
func RegisterRoutes(e *echo.Echo, log *logrus.Logger) {
h := HTTP{log: log}
e.HTTPErrorHandler = h.DefaultErrorHandler
e.GET("/", h.DefaultHandler)
}

View File

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Tuukoti</title>
</head>
<body>
<h1>Tuukoti</h1>
</body>
</html>