start of creating a new project cmd

This commit is contained in:
cubixle
2022-07-22 13:15:26 +01:00
commit 2bd76a9b96
11 changed files with 410 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
host: localhost:8080
debug: false
+25
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)
}
}
+18
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)
}
+43
View File
@@ -0,0 +1,43 @@
package main
import (
"log"
"os"
"github.com/cubixle/testing/internal/http"
"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
+11
View File
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Tuukoti</title>
</head>
<body>
<h1>Tuukoti</h1>
</body>
</html>