detached 9004ced

Add some testing functions for the docker client.

Add a renderer for txt templates (yaml and json)
Misc bug fixes
commit
9004ced0028425b0886f6d6ccbe552f4300b7d25
author
bnema · · 2023-09-04 19:32 UTC
parent
ac608b2
signature
unsigned
8 files · +83 -13
R internal/http/routes/admin_routes.go → internal/http/routes/admin-routes.go +0 -13 renamed, 67% similar
@@ -3,7 +3,6 @@ package routes
33 import (
44 "fmt"
55 "net/http"
6- "os"
76
87 "github.com/labstack/echo/v4"
98 "gogs.bnema.dev/gordon-echo/internal/http/middlewares"
@@ -35,15 +34,3 @@ func AdminRoute(c echo.Context) error {
3534
3635 return c.HTML(http.StatusOK, html)
3736 }
38-
39-func StaticRoute(c echo.Context) error {
40-
41- // Set the cache-control header to cache the static files for 1 day if PROD env is set to true
42-
43- if os.Getenv("PROD") == "true" {
44- c.Response().Header().Set("Cache-Control", "public, max-age=86400")
45- } else {
46- c.Response().Header().Set("Cache-Control", "no-cache")
47- }
48- return echo.StaticDirectoryHandler(ui.PublicFS, false)(c)
49-}
@@ -3,7 +3,6 @@ package routes
3 import (3 import (
4 "fmt"4 "fmt"
5 "net/http"5 "net/http"
6- "os"
7 6
8 "github.com/labstack/echo/v4"7 "github.com/labstack/echo/v4"
9 "gogs.bnema.dev/gordon-echo/internal/http/middlewares"8 "gogs.bnema.dev/gordon-echo/internal/http/middlewares"
@@ -35,15 +34,3 @@ func AdminRoute(c echo.Context) error {
35 34
36 return c.HTML(http.StatusOK, html)35 return c.HTML(http.StatusOK, html)
37 }36 }
38-
39-func StaticRoute(c echo.Context) error {
40-
41- // Set the cache-control header to cache the static files for 1 day if PROD env is set to true
42-
43- if os.Getenv("PROD") == "true" {
44- c.Response().Header().Set("Cache-Control", "public, max-age=86400")
45- } else {
46- c.Response().Header().Set("Cache-Control", "no-cache")
47- }
48- return echo.StaticDirectoryHandler(ui.PublicFS, false)(c)
49-}
A internal/http/routes/static-routes.go +20 -0
@@ -0,0 +1,20 @@
1+package routes
2+
3+import (
4+ "os"
5+
6+ "github.com/labstack/echo/v4"
7+ "gogs.bnema.dev/gordon-echo/internal/ui"
8+)
9+
10+func StaticRoute(c echo.Context) error {
11+
12+ // Set the cache-control header to cache the static files for 1 day if PROD env is set to true
13+
14+ if os.Getenv("PROD") == "true" {
15+ c.Response().Header().Set("Cache-Control", "public, max-age=86400")
16+ } else {
17+ c.Response().Header().Set("Cache-Control", "no-cache")
18+ }
19+ return echo.StaticDirectoryHandler(ui.PublicFS, false)(c)
20+}
@@ -0,0 +1,20 @@
1+package routes
2+
3+import (
4+ "os"
5+
6+ "github.com/labstack/echo/v4"
7+ "gogs.bnema.dev/gordon-echo/internal/ui"
8+)
9+
10+func StaticRoute(c echo.Context) error {
11+
12+ // Set the cache-control header to cache the static files for 1 day if PROD env is set to true
13+
14+ if os.Getenv("PROD") == "true" {
15+ c.Response().Header().Set("Cache-Control", "public, max-age=86400")
16+ } else {
17+ c.Response().Header().Set("Cache-Control", "no-cache")
18+ }
19+ return echo.StaticDirectoryHandler(ui.PublicFS, false)(c)
20+}
A pkg/docker/daemon.json +11 -0
@@ -0,0 +1,11 @@
1+{
2+ "log-driver": "json-file",
3+ "log-opts": {
4+ "max-size": "100m",
5+ "max-file": "5"
6+ },
7+ "features": {
8+ "buildkit": true
9+ },
10+ "live-restore": true
11+}
@@ -0,0 +1,11 @@
1+{
2+ "log-driver": "json-file",
3+ "log-opts": {
4+ "max-size": "100m",
5+ "max-file": "5"
6+ },
7+ "features": {
8+ "buildkit": true
9+ },
10+ "live-restore": true
11+}
R pkg/utils/fragments.go → pkg/utils/html-fragments.go +0 -0 renamed, 100% similar

renamed, 100% similar

R pkg/utils/render.go → pkg/utils/html-render.go +0 -0 renamed, 100% similar

renamed, 100% similar

R internal/http/services/sqlite.go → pkg/utils/services/sqlite.go +0 -0 renamed, 100% similar

renamed, 100% similar

R pkg/utils/terminal.go → pkg/utils/tty.go +0 -0 renamed, 100% similar

renamed, 100% similar

A pkg/utils/txt-render.go +52 -0
@@ -0,0 +1,52 @@
1+package utils
2+
3+import (
4+ "bytes"
5+ "errors"
6+ "io/fs"
7+ "text/template"
8+)
9+
10+type TXTRenderer struct {
11+ Models *template.Template
12+ Format string
13+ ParseError error
14+ Logger *Logger
15+}
16+
17+// Render function renders the template with the given data
18+func (r *TXTRenderer) TXTRender(data interface{}) (string, error) {
19+ if r.ParseError != nil {
20+ r.Logger.Error().Err(r.ParseError).Msg("Parse error")
21+ return "", r.ParseError
22+ }
23+
24+ if r.Models == nil {
25+ err := errors.New("invalid or nil template")
26+ r.Logger.Error().Err(r.ParseError).Msg("Parse error")
27+
28+ return "", err
29+ }
30+
31+ buf := new(bytes.Buffer)
32+ err := r.Models.Execute(buf, data)
33+ if err != nil {
34+ r.Logger.Error().Err(err).Msg("Render error")
35+ return "", err
36+ }
37+
38+ return buf.String(), nil
39+}
40+
41+// GetRenderer function returns a new Renderer instance
42+func GetTXTRenderer(filename string, fs fs.FS, logger *Logger) (*TXTRenderer, error) {
43+ mdls, err := template.New(filename).ParseFS(fs, filename)
44+ if err != nil {
45+ logger.Error().Err(err).Msg("Failed to parse template")
46+ return nil, err
47+ }
48+ return &TXTRenderer{
49+ Models: mdls,
50+ Logger: logger,
51+ }, nil
52+}
@@ -0,0 +1,52 @@
1+package utils
2+
3+import (
4+ "bytes"
5+ "errors"
6+ "io/fs"
7+ "text/template"
8+)
9+
10+type TXTRenderer struct {
11+ Models *template.Template
12+ Format string
13+ ParseError error
14+ Logger *Logger
15+}
16+
17+// Render function renders the template with the given data
18+func (r *TXTRenderer) TXTRender(data interface{}) (string, error) {
19+ if r.ParseError != nil {
20+ r.Logger.Error().Err(r.ParseError).Msg("Parse error")
21+ return "", r.ParseError
22+ }
23+
24+ if r.Models == nil {
25+ err := errors.New("invalid or nil template")
26+ r.Logger.Error().Err(r.ParseError).Msg("Parse error")
27+
28+ return "", err
29+ }
30+
31+ buf := new(bytes.Buffer)
32+ err := r.Models.Execute(buf, data)
33+ if err != nil {
34+ r.Logger.Error().Err(err).Msg("Render error")
35+ return "", err
36+ }
37+
38+ return buf.String(), nil
39+}
40+
41+// GetRenderer function returns a new Renderer instance
42+func GetTXTRenderer(filename string, fs fs.FS, logger *Logger) (*TXTRenderer, error) {
43+ mdls, err := template.New(filename).ParseFS(fs, filename)
44+ if err != nil {
45+ logger.Error().Err(err).Msg("Failed to parse template")
46+ return nil, err
47+ }
48+ return &TXTRenderer{
49+ Models: mdls,
50+ Logger: logger,
51+ }, nil
52+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close