moved packages out of pkg

This commit is contained in:
2026-02-04 18:57:33 +11:00
parent d2b1a252ea
commit 20308fe35c
24 changed files with 41 additions and 36 deletions

View File

@@ -4,7 +4,7 @@
BINARY_NAME=oslstats BINARY_NAME=oslstats
build: 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 && \ go mod tidy && \
templ generate && \ templ generate && \
go generate ./cmd/${BINARY_NAME} && \ go generate ./cmd/${BINARY_NAME} && \
@@ -17,7 +17,7 @@ run:
dev: dev:
templ generate --watch &\ templ generate --watch &\
air &\ 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: clean:
go clean go clean

View File

@@ -8,9 +8,9 @@ import (
"git.haelnorr.com/h/golib/hws" "git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/golib/hwsauth" "git.haelnorr.com/h/golib/hwsauth"
"git.haelnorr.com/h/oslstats/internal/config" "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/db"
"git.haelnorr.com/h/oslstats/internal/rbac" "git.haelnorr.com/h/oslstats/internal/rbac"
"git.haelnorr.com/h/oslstats/pkg/contexts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/uptrace/bun" "github.com/uptrace/bun"

View File

@@ -13,8 +13,8 @@ import (
"git.haelnorr.com/h/oslstats/internal/config" "git.haelnorr.com/h/oslstats/internal/config"
"git.haelnorr.com/h/oslstats/internal/discord" "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/internal/store"
"git.haelnorr.com/h/oslstats/pkg/embedfs"
) )
// Initializes and runs the server // Initializes and runs the server

View File

@@ -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
}

13
internal/contexts/keys.go Normal file
View File

@@ -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")
)

View File

@@ -1,4 +1,3 @@
// Package contexts provides utilities for loading and extracting structs from contexts
package contexts package contexts
import ( import (
@@ -8,30 +7,6 @@ import (
"git.haelnorr.com/h/oslstats/internal/roles" "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) // Permissions retrieves the permission cache from context (type-safe)
func Permissions(ctx context.Context) *PermissionCache { func Permissions(ctx context.Context) *PermissionCache {
cache, ok := ctx.Value(PermissionCacheKey).(*PermissionCache) cache, ok := ctx.Value(PermissionCacheKey).(*PermissionCache)

View File

@@ -1,3 +1,4 @@
// Package embedfs creates an embedded filesystem with the static web assets
package embedfs package embedfs
import ( import (
@@ -7,12 +8,12 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
//go:embed files/* //go:embed web/*
var embeddedFiles embed.FS var embeddedFiles embed.FS
// Gets the embedded files // GetEmbeddedFS gets the embedded files
func GetEmbeddedFS() (fs.FS, error) { func GetEmbeddedFS() (fs.FS, error) {
subFS, err := fs.Sub(embeddedFiles, "files") subFS, err := fs.Sub(embeddedFiles, "web")
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fs.Sub") return nil, errors.Wrap(err, "fs.Sub")
} }

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@@ -6,10 +6,10 @@ import (
"time" "time"
"git.haelnorr.com/h/golib/hws" "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/db"
"git.haelnorr.com/h/oslstats/internal/permissions" "git.haelnorr.com/h/oslstats/internal/permissions"
"git.haelnorr.com/h/oslstats/internal/roles" "git.haelnorr.com/h/oslstats/internal/roles"
"git.haelnorr.com/h/oslstats/pkg/contexts"
"github.com/pkg/errors" "github.com/pkg/errors"
) )

View File

@@ -4,10 +4,10 @@ import (
"context" "context"
"git.haelnorr.com/h/golib/hws" "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/db"
"git.haelnorr.com/h/oslstats/internal/permissions" "git.haelnorr.com/h/oslstats/internal/permissions"
"git.haelnorr.com/h/oslstats/internal/roles" "git.haelnorr.com/h/oslstats/internal/roles"
"git.haelnorr.com/h/oslstats/pkg/contexts"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/uptrace/bun" "github.com/uptrace/bun"
) )

View File

@@ -2,8 +2,8 @@ package nav
import ( import (
"context" "context"
"git.haelnorr.com/h/oslstats/internal/contexts"
"git.haelnorr.com/h/oslstats/internal/db" "git.haelnorr.com/h/oslstats/internal/db"
"git.haelnorr.com/h/oslstats/pkg/contexts"
) )
type ProfileItem struct { type ProfileItem struct {

View File

@@ -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/popup"
import "git.haelnorr.com/h/oslstats/internal/view/component/nav" 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/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 // Global page layout. Includes HTML document settings, header tags
// navbar and footer // navbar and footer

Binary file not shown.

Before

Width:  |  Height:  |  Size: 834 B