Integration Echo: ok
- commit
- 654acb67ca3a378231b722b4d43b21d4c1b26708
- author
- bnema · · 2023-09-13 16:07 UTC
- parent
- 8151903
- signature
- unsigned
6 files · +44 -40
M .gitignore +2 -5
| @@ -1,10 +1,7 @@ | |||
| 1 | 1 | .env | |
| 2 | 2 | node_modules/ | |
| 3 | 3 | tmp/* | |
| 4 | - | logs/ | |
| 5 | - | logs/app.log | |
| 6 | - | logs/error.log | |
| 7 | - | logs/http.log | |
| 8 | - | logs/docker.log | |
| 9 | 4 | gordon.yml | |
| 10 | 5 | bun.lockb | |
| 6 | + | *.log | |
| 7 | + | ||
| @@ -1,10 +1,7 @@ | |||||
| 1 | .env | 1 | .env | ||
| 2 | node_modules/ | 2 | node_modules/ | ||
| 3 | tmp/* | 3 | tmp/* | ||
| 4 | - | logs/ | |||
| 5 | - | logs/app.log | |||
| 6 | - | logs/error.log | |||
| 7 | - | logs/http.log | |||
| 8 | - | logs/docker.log | |||
| 9 | gordon.yml | 4 | gordon.yml | ||
| 10 | bun.lockb | 5 | bun.lockb | ||
| 6 | + | *.log | |||
| 7 | + | ||||
M cmd/main.go +11 -1
| @@ -1,10 +1,20 @@ | |||
| 1 | 1 | package main | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | + | "fmt" | |
| 5 | + | "log/slog" | |
| 6 | + | ||
| 4 | 7 | "github.com/bnema/gordon/internal/app" | |
| 8 | + | "github.com/bnema/gordon/internal/httpserve" | |
| 9 | + | "github.com/labstack/echo/v4" | |
| 5 | 10 | ) | |
| 6 | 11 | ||
| 7 | 12 | func main() { | |
| 8 | 13 | a := app.NewApp() | |
| 9 | - | a.Start() | |
| 14 | + | e := echo.New() | |
| 15 | + | e.HideBanner = true | |
| 16 | + | e.HidePort = true | |
| 17 | + | e = httpserve.RegisterRoutes(e, a) | |
| 18 | + | slog.Info("Starting server", "port", a.HttpPort) | |
| 19 | + | slog.Error("Server error", e.Start(fmt.Sprintf(":%d", a.HttpPort))) | |
| 10 | 20 | } | |
| @@ -1,10 +1,20 @@ | |||||
| 1 | package main | 1 | package main | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | + | "fmt" | |||
| 5 | + | "log/slog" | |||
| 6 | + | ||||
| 4 | "github.com/bnema/gordon/internal/app" | 7 | "github.com/bnema/gordon/internal/app" | ||
| 8 | + | "github.com/bnema/gordon/internal/httpserve" | |||
| 9 | + | "github.com/labstack/echo/v4" | |||
| 5 | ) | 10 | ) | ||
| 6 | 11 | ||||
| 7 | func main() { | 12 | func main() { | ||
| 8 | a := app.NewApp() | 13 | a := app.NewApp() | ||
| 9 | - | a.Start() | 14 | + | e := echo.New() |
| 15 | + | e.HideBanner = true | |||
| 16 | + | e.HidePort = true | |||
| 17 | + | e = httpserve.RegisterRoutes(e, a) | |||
| 18 | + | slog.Info("Starting server", "port", a.HttpPort) | |||
| 19 | + | slog.Error("Server error", e.Start(fmt.Sprintf(":%d", a.HttpPort))) | |||
| 10 | } | 20 | } | ||
M internal/app/app.go +13 -32
| @@ -1,7 +1,6 @@ | |||
| 1 | 1 | package app | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "fmt" | |
| 5 | 4 | "io/fs" | |
| 6 | 5 | ||
| 7 | 6 | "github.com/bnema/gordon/internal/gotemplate" | |
| @@ -11,6 +10,11 @@ import ( | |||
| 11 | 10 | const ( | |
| 12 | 11 | BuildVersion = "0.0.2" | |
| 13 | 12 | BuildDir = "tmp" | |
| 13 | + | // Those configs should be read from a config file | |
| 14 | + | HttpPort = 1323 | |
| 15 | + | TopDomain = "example.com" | |
| 16 | + | SubDomain = "gordon" | |
| 17 | + | AdminPath = "/admin" | |
| 14 | 18 | ) | |
| 15 | 19 | ||
| 16 | 20 | type App struct { | |
| @@ -18,22 +22,10 @@ type App struct { | |||
| 18 | 22 | PublicFS fs.FS | |
| 19 | 23 | BuildVersion string | |
| 20 | 24 | BuildDir string | |
| 21 | - | } | |
| 22 | - | ||
| 23 | - | func (*App) GetTemplateFS() fs.FS { | |
| 24 | - | return gotemplate.TemplateFS | |
| 25 | - | } | |
| 26 | - | ||
| 27 | - | func (*App) GetPublicFS() fs.FS { | |
| 28 | - | return webui.PublicFS | |
| 29 | - | } | |
| 30 | - | ||
| 31 | - | func (*App) GetBuildVersion() string { | |
| 32 | - | return BuildVersion | |
| 33 | - | } | |
| 34 | - | ||
| 35 | - | func (*App) GetBuildDir() string { | |
| 36 | - | return BuildDir | |
| 25 | + | TopDomain string | |
| 26 | + | SubDomain string | |
| 27 | + | AdminPath string | |
| 28 | + | HttpPort int16 | |
| 37 | 29 | } | |
| 38 | 30 | ||
| 39 | 31 | func NewApp() *App { | |
| @@ -42,20 +34,9 @@ func NewApp() *App { | |||
| 42 | 34 | PublicFS: webui.PublicFS, | |
| 43 | 35 | BuildVersion: BuildVersion, | |
| 44 | 36 | BuildDir: BuildDir, | |
| 45 | - | } | |
| 46 | - | } | |
| 47 | - | ||
| 48 | - | func (a *App) Start() { | |
| 49 | - | fmt.Println("Starting app") | |
| 50 | - | ||
| 51 | - | // LS in the template directory | |
| 52 | - | entries, err := fs.ReadDir(a.TemplateFS, ".") // List the root directory | |
| 53 | - | if err != nil { | |
| 54 | - | fmt.Println("Error reading directory:", err) | |
| 55 | - | return | |
| 56 | - | } | |
| 57 | - | ||
| 58 | - | for _, entry := range entries { | |
| 59 | - | fmt.Println(entry.Name()) | |
| 37 | + | TopDomain: TopDomain, | |
| 38 | + | SubDomain: SubDomain, | |
| 39 | + | AdminPath: AdminPath, | |
| 40 | + | HttpPort: HttpPort, | |
| 60 | 41 | } | |
| 61 | 42 | } | |
| @@ -1,7 +1,6 @@ | |||||
| 1 | package app | 1 | package app | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | - | "fmt" | |||
| 5 | "io/fs" | 4 | "io/fs" | ||
| 6 | 5 | ||||
| 7 | "github.com/bnema/gordon/internal/gotemplate" | 6 | "github.com/bnema/gordon/internal/gotemplate" | ||
| @@ -11,6 +10,11 @@ import ( | |||||
| 11 | const ( | 10 | const ( | ||
| 12 | BuildVersion = "0.0.2" | 11 | BuildVersion = "0.0.2" | ||
| 13 | BuildDir = "tmp" | 12 | BuildDir = "tmp" | ||
| 13 | + | // Those configs should be read from a config file | |||
| 14 | + | HttpPort = 1323 | |||
| 15 | + | TopDomain = "example.com" | |||
| 16 | + | SubDomain = "gordon" | |||
| 17 | + | AdminPath = "/admin" | |||
| 14 | ) | 18 | ) | ||
| 15 | 19 | ||||
| 16 | type App struct { | 20 | type App struct { | ||
| @@ -18,22 +22,10 @@ type App struct { | |||||
| 18 | PublicFS fs.FS | 22 | PublicFS fs.FS | ||
| 19 | BuildVersion string | 23 | BuildVersion string | ||
| 20 | BuildDir string | 24 | BuildDir string | ||
| 21 | - | } | 25 | + | TopDomain string |
| 22 | - | 26 | + | SubDomain string | |
| 23 | - | func (*App) GetTemplateFS() fs.FS { | 27 | + | AdminPath string |
| 24 | - | return gotemplate.TemplateFS | 28 | + | HttpPort int16 |
| 25 | - | } | |||
| 26 | - | ||||
| 27 | - | func (*App) GetPublicFS() fs.FS { | |||
| 28 | - | return webui.PublicFS | |||
| 29 | - | } | |||
| 30 | - | ||||
| 31 | - | func (*App) GetBuildVersion() string { | |||
| 32 | - | return BuildVersion | |||
| 33 | - | } | |||
| 34 | - | ||||
| 35 | - | func (*App) GetBuildDir() string { | |||
| 36 | - | return BuildDir | |||
| 37 | } | 29 | } | ||
| 38 | 30 | ||||
| 39 | func NewApp() *App { | 31 | func NewApp() *App { | ||
| @@ -42,20 +34,9 @@ func NewApp() *App { | |||||
| 42 | PublicFS: webui.PublicFS, | 34 | PublicFS: webui.PublicFS, | ||
| 43 | BuildVersion: BuildVersion, | 35 | BuildVersion: BuildVersion, | ||
| 44 | BuildDir: BuildDir, | 36 | BuildDir: BuildDir, | ||
| 45 | - | } | 37 | + | TopDomain: TopDomain, |
| 46 | - | } | 38 | + | SubDomain: SubDomain, |
| 47 | - | 39 | + | AdminPath: AdminPath, | |
| 48 | - | func (a *App) Start() { | 40 | + | HttpPort: HttpPort, |
| 49 | - | fmt.Println("Starting app") | |||
| 50 | - | ||||
| 51 | - | // LS in the template directory | |||
| 52 | - | entries, err := fs.ReadDir(a.TemplateFS, ".") // List the root directory | |||
| 53 | - | if err != nil { | |||
| 54 | - | fmt.Println("Error reading directory:", err) | |||
| 55 | - | return | |||
| 56 | - | } | |||
| 57 | - | ||||
| 58 | - | for _, entry := range entries { | |||
| 59 | - | fmt.Println(entry.Name()) | |||
| 60 | } | 41 | } | ||
| 61 | } | 42 | } | ||
D internal/httpserve/middleware/tmp/build-errors.log +0 -1
| @@ -1,1 +0,0 @@ | |||
| 1 | - | exit status 1⏎̸ | |
| @@ -1,1 +0,0 @@ | |||||
| 1 | - | exit status 1⏎̸ | |||
M internal/httpserve/router.go +17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | + | package httpserve | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "github.com/bnema/gordon/internal/app" | |
| 5 | + | "github.com/labstack/echo/v4" | |
| 6 | + | ) | |
| 7 | + | ||
| 8 | + | func RegisterRoutes(e *echo.Echo, a *app.App) *echo.Echo { | |
| 9 | + | AdminPath := a.AdminPath | |
| 10 | + | // Hello world on the admin path | |
| 11 | + | e.GET(AdminPath, helloWorld) | |
| 12 | + | return e | |
| 13 | + | } | |
| 14 | + | ||
| 15 | + | func helloWorld(c echo.Context) error { | |
| 16 | + | return c.String(200, "Hello world") | |
| 17 | + | } | |
| @@ -0,0 +1,17 @@ | |||||
| 1 | + | package httpserve | |||
| 2 | + | ||||
| 3 | + | import ( | |||
| 4 | + | "github.com/bnema/gordon/internal/app" | |||
| 5 | + | "github.com/labstack/echo/v4" | |||
| 6 | + | ) | |||
| 7 | + | ||||
| 8 | + | func RegisterRoutes(e *echo.Echo, a *app.App) *echo.Echo { | |||
| 9 | + | AdminPath := a.AdminPath | |||
| 10 | + | // Hello world on the admin path | |||
| 11 | + | e.GET(AdminPath, helloWorld) | |||
| 12 | + | return e | |||
| 13 | + | } | |||
| 14 | + | ||||
| 15 | + | func helloWorld(c echo.Context) error { | |||
| 16 | + | return c.String(200, "Hello world") | |||
| 17 | + | } | |||
M internal/webui/embed.go +1 -1
| @@ -11,4 +11,4 @@ import ( | |||
| 11 | 11 | //go:embed public/* | |
| 12 | 12 | var public embed.FS | |
| 13 | 13 | ||
| 14 | - | var PublicFS = echo.MustSubFS(public, "internal/webui/public") | |
| 14 | + | var PublicFS = echo.MustSubFS(public, "public") | |
| @@ -11,4 +11,4 @@ import ( | |||||
| 11 | //go:embed public/* | 11 | //go:embed public/* | ||
| 12 | var public embed.FS | 12 | var public embed.FS | ||
| 13 | 13 | ||||
| 14 | - | var PublicFS = echo.MustSubFS(public, "internal/webui/public") | 14 | + | var PublicFS = echo.MustSubFS(public, "public") |