diff --git a/Makefile b/Makefile index d34702a..aeeab39 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ BINARY_NAME=oslstats build: - tailwindcss -i ./pkg/embedfs/files/css/input.css -o ./pkg/embedfs/files/css/output.css && \ + tailwindcss -i ./internal/embedfs/web/css/input.css -o ./internal/embedfs/web/css/output.css && \ go mod tidy && \ templ generate && \ go generate ./cmd/${BINARY_NAME} && \ @@ -17,7 +17,7 @@ run: dev: templ generate --watch &\ air &\ - tailwindcss -i ./pkg/embedfs/files/css/input.css -o ./pkg/embedfs/files/css/output.css --watch + tailwindcss -i ./internal/embedfs/web/css/input.css -o ./internal/embedfs/web/css/output.css --watch clean: go clean diff --git a/cmd/oslstats/middleware.go b/cmd/oslstats/middleware.go index 81d92c6..6af763b 100644 --- a/cmd/oslstats/middleware.go +++ b/cmd/oslstats/middleware.go @@ -8,9 +8,9 @@ import ( "git.haelnorr.com/h/golib/hws" "git.haelnorr.com/h/golib/hwsauth" "git.haelnorr.com/h/oslstats/internal/config" + "git.haelnorr.com/h/oslstats/internal/contexts" "git.haelnorr.com/h/oslstats/internal/db" "git.haelnorr.com/h/oslstats/internal/rbac" - "git.haelnorr.com/h/oslstats/pkg/contexts" "github.com/pkg/errors" "github.com/uptrace/bun" diff --git a/cmd/oslstats/run.go b/cmd/oslstats/run.go index 90babaf..4c0eef0 100644 --- a/cmd/oslstats/run.go +++ b/cmd/oslstats/run.go @@ -13,8 +13,8 @@ import ( "git.haelnorr.com/h/oslstats/internal/config" "git.haelnorr.com/h/oslstats/internal/discord" + "git.haelnorr.com/h/oslstats/internal/embedfs" "git.haelnorr.com/h/oslstats/internal/store" - "git.haelnorr.com/h/oslstats/pkg/embedfs" ) // Initializes and runs the server diff --git a/internal/contexts/devmode.go b/internal/contexts/devmode.go new file mode 100644 index 0000000..ea1c20e --- /dev/null +++ b/internal/contexts/devmode.go @@ -0,0 +1,16 @@ +package contexts + +import "context" + +func DevMode(ctx context.Context) DevInfo { + devmode, ok := ctx.Value(DevModeKey).(DevInfo) + if !ok { + return DevInfo{} + } + return devmode +} + +type DevInfo struct { + WebsocketBase string + HTMXLog bool +} diff --git a/internal/contexts/keys.go b/internal/contexts/keys.go new file mode 100644 index 0000000..74fbe70 --- /dev/null +++ b/internal/contexts/keys.go @@ -0,0 +1,13 @@ +// Package contexts provides utilities for loading and extracting structs from contexts +package contexts + +type Key string + +func (c Key) String() string { + return "oslstats context key " + string(c) +} + +var ( + DevModeKey Key = Key("devmode") + PermissionCacheKey Key = Key("permissions") +) diff --git a/pkg/contexts/keys.go b/internal/contexts/permissions.go similarity index 50% rename from pkg/contexts/keys.go rename to internal/contexts/permissions.go index 4ec539f..8950073 100644 --- a/pkg/contexts/keys.go +++ b/internal/contexts/permissions.go @@ -1,4 +1,3 @@ -// Package contexts provides utilities for loading and extracting structs from contexts package contexts import ( @@ -8,30 +7,6 @@ import ( "git.haelnorr.com/h/oslstats/internal/roles" ) -type Key string - -func (c Key) String() string { - return "oslstats context key " + string(c) -} - -var ( - DevModeKey Key = Key("devmode") - PermissionCacheKey Key = Key("permissions") -) - -func DevMode(ctx context.Context) DevInfo { - devmode, ok := ctx.Value(DevModeKey).(DevInfo) - if !ok { - return DevInfo{} - } - return devmode -} - -type DevInfo struct { - WebsocketBase string - HTMXLog bool -} - // Permissions retrieves the permission cache from context (type-safe) func Permissions(ctx context.Context) *PermissionCache { cache, ok := ctx.Value(PermissionCacheKey).(*PermissionCache) diff --git a/pkg/embedfs/embedfs.go b/internal/embedfs/embedfs.go similarity index 55% rename from pkg/embedfs/embedfs.go rename to internal/embedfs/embedfs.go index e730359..4e9720d 100644 --- a/pkg/embedfs/embedfs.go +++ b/internal/embedfs/embedfs.go @@ -1,3 +1,4 @@ +// Package embedfs creates an embedded filesystem with the static web assets package embedfs import ( @@ -7,12 +8,12 @@ import ( "github.com/pkg/errors" ) -//go:embed files/* +//go:embed web/* var embeddedFiles embed.FS -// Gets the embedded files +// GetEmbeddedFS gets the embedded files func GetEmbeddedFS() (fs.FS, error) { - subFS, err := fs.Sub(embeddedFiles, "files") + subFS, err := fs.Sub(embeddedFiles, "web") if err != nil { return nil, errors.Wrap(err, "fs.Sub") } diff --git a/pkg/embedfs/files/assets/error.png b/internal/embedfs/web/assets/error.png similarity index 100% rename from pkg/embedfs/files/assets/error.png rename to internal/embedfs/web/assets/error.png diff --git a/internal/embedfs/web/assets/favicon.ico b/internal/embedfs/web/assets/favicon.ico new file mode 100644 index 0000000..b6215aa Binary files /dev/null and b/internal/embedfs/web/assets/favicon.ico differ diff --git a/internal/embedfs/web/assets/logo.png b/internal/embedfs/web/assets/logo.png new file mode 100644 index 0000000..457d36b Binary files /dev/null and b/internal/embedfs/web/assets/logo.png differ diff --git a/pkg/embedfs/files/css/input.css b/internal/embedfs/web/css/input.css similarity index 100% rename from pkg/embedfs/files/css/input.css rename to internal/embedfs/web/css/input.css diff --git a/pkg/embedfs/files/css/output.css b/internal/embedfs/web/css/output.css similarity index 100% rename from pkg/embedfs/files/css/output.css rename to internal/embedfs/web/css/output.css diff --git a/pkg/embedfs/files/js/copytoclipboard.js b/internal/embedfs/web/js/copytoclipboard.js similarity index 100% rename from pkg/embedfs/files/js/copytoclipboard.js rename to internal/embedfs/web/js/copytoclipboard.js diff --git a/pkg/embedfs/files/js/pagination.js b/internal/embedfs/web/js/pagination.js similarity index 100% rename from pkg/embedfs/files/js/pagination.js rename to internal/embedfs/web/js/pagination.js diff --git a/pkg/embedfs/files/js/theme.js b/internal/embedfs/web/js/theme.js similarity index 100% rename from pkg/embedfs/files/js/theme.js rename to internal/embedfs/web/js/theme.js diff --git a/pkg/embedfs/files/js/toasts.js b/internal/embedfs/web/js/toasts.js similarity index 100% rename from pkg/embedfs/files/js/toasts.js rename to internal/embedfs/web/js/toasts.js diff --git a/pkg/embedfs/files/vendored/alpinejs@3.15.4.min.js b/internal/embedfs/web/vendored/alpinejs@3.15.4.min.js similarity index 100% rename from pkg/embedfs/files/vendored/alpinejs@3.15.4.min.js rename to internal/embedfs/web/vendored/alpinejs@3.15.4.min.js diff --git a/pkg/embedfs/files/vendored/htmx-ext-ws.min.js b/internal/embedfs/web/vendored/htmx-ext-ws.min.js similarity index 100% rename from pkg/embedfs/files/vendored/htmx-ext-ws.min.js rename to internal/embedfs/web/vendored/htmx-ext-ws.min.js diff --git a/pkg/embedfs/files/vendored/htmx@2.0.8.min.js b/internal/embedfs/web/vendored/htmx@2.0.8.min.js similarity index 100% rename from pkg/embedfs/files/vendored/htmx@2.0.8.min.js rename to internal/embedfs/web/vendored/htmx@2.0.8.min.js diff --git a/internal/rbac/cache_middleware.go b/internal/rbac/cache_middleware.go index 817f749..5b642d3 100644 --- a/internal/rbac/cache_middleware.go +++ b/internal/rbac/cache_middleware.go @@ -6,10 +6,10 @@ import ( "time" "git.haelnorr.com/h/golib/hws" + "git.haelnorr.com/h/oslstats/internal/contexts" "git.haelnorr.com/h/oslstats/internal/db" "git.haelnorr.com/h/oslstats/internal/permissions" "git.haelnorr.com/h/oslstats/internal/roles" - "git.haelnorr.com/h/oslstats/pkg/contexts" "github.com/pkg/errors" ) diff --git a/internal/rbac/checker.go b/internal/rbac/checker.go index 54f9632..5b88594 100644 --- a/internal/rbac/checker.go +++ b/internal/rbac/checker.go @@ -4,10 +4,10 @@ import ( "context" "git.haelnorr.com/h/golib/hws" + "git.haelnorr.com/h/oslstats/internal/contexts" "git.haelnorr.com/h/oslstats/internal/db" "git.haelnorr.com/h/oslstats/internal/permissions" "git.haelnorr.com/h/oslstats/internal/roles" - "git.haelnorr.com/h/oslstats/pkg/contexts" "github.com/pkg/errors" "github.com/uptrace/bun" ) diff --git a/internal/view/component/nav/navbarright.templ b/internal/view/component/nav/navbarright.templ index 58d8e26..6a3d53e 100644 --- a/internal/view/component/nav/navbarright.templ +++ b/internal/view/component/nav/navbarright.templ @@ -2,8 +2,8 @@ package nav import ( "context" + "git.haelnorr.com/h/oslstats/internal/contexts" "git.haelnorr.com/h/oslstats/internal/db" - "git.haelnorr.com/h/oslstats/pkg/contexts" ) type ProfileItem struct { diff --git a/internal/view/layout/global.templ b/internal/view/layout/global.templ index b2b1f26..5e08d78 100644 --- a/internal/view/layout/global.templ +++ b/internal/view/layout/global.templ @@ -3,7 +3,7 @@ package layout import "git.haelnorr.com/h/oslstats/internal/view/component/popup" import "git.haelnorr.com/h/oslstats/internal/view/component/nav" import "git.haelnorr.com/h/oslstats/internal/view/component/footer" -import "git.haelnorr.com/h/oslstats/pkg/contexts" +import "git.haelnorr.com/h/oslstats/internal/contexts" // Global page layout. Includes HTML document settings, header tags // navbar and footer diff --git a/pkg/embedfs/files/favicon.ico b/pkg/embedfs/files/favicon.ico deleted file mode 100644 index f052478..0000000 Binary files a/pkg/embedfs/files/favicon.ico and /dev/null differ