mirror of
https://github.com/cubixle/tuukoti-cli.git
synced 2026-04-24 21:24:48 +01:00
add cmd dir and move templates over
This commit is contained in:
2
cmd/tuukoti/templates/config.yml
Normal file
2
cmd/tuukoti/templates/config.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
host: localhost:8080
|
||||
debug: false
|
||||
43
cmd/tuukoti/templates/main.go.tmpl
Normal file
43
cmd/tuukoti/templates/main.go.tmpl
Normal 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
|
||||
}
|
||||
25
cmd/tuukoti/templates/resources/default.go
Normal file
25
cmd/tuukoti/templates/resources/default.go
Normal 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)
|
||||
}
|
||||
}
|
||||
18
cmd/tuukoti/templates/resources/resources.go
Normal file
18
cmd/tuukoti/templates/resources/resources.go
Normal 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)
|
||||
}
|
||||
0
cmd/tuukoti/templates/views/error.html
Normal file
0
cmd/tuukoti/templates/views/error.html
Normal file
11
cmd/tuukoti/templates/views/index.html
Normal file
11
cmd/tuukoti/templates/views/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Tuukoti</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Tuukoti</h1>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user