added nats + worker modules

This commit is contained in:
2025-12-19 09:59:00 -05:00
parent b457c74d49
commit ca758cc708
12 changed files with 559 additions and 31 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/gob"
"fmt"
"log/slog"
"net/http"
"net/url"
@@ -16,45 +17,27 @@ func init() {
gob.Register(SessionUser{})
}
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Error(msg string, args ...any)
}
type SessionManager interface {
Get(ctx context.Context, key string) any
Put(ctx context.Context, key string, value any)
}
type Config struct {
Logger Logger
Logger *slog.Logger
Sessions SessionManager
}
type Option func(deps *Config)
func WithLogger(l Logger) Option {
return func(cfg *Config) {
cfg.Logger = l
}
}
func WithSessions(s SessionManager) Option {
return func(cfg *Config) {
cfg.Sessions = s
}
}
type deps struct {
auth *authenticator.Authenticator
logoutBase *url.URL
log Logger
log *slog.Logger
sessions SessionManager
}
func New(opts ...Option) (func(chi.Router), Middleware, error) {
cfg := Config{}
cfg := Config{
Logger: slog.Default(),
}
for _, opt := range opts {
opt(&cfg)

View File

@@ -2,6 +2,7 @@ package auth0
import (
"context"
"log/slog"
"net/http/httptest"
"strings"
"sync"
@@ -12,12 +13,6 @@ import (
"git.citc.tech/go/web/auth/auth0/authenticator"
)
type mockLogger struct{}
func (m *mockLogger) Debug(msg string, args ...any) {}
func (m *mockLogger) Info(msg string, args ...any) {}
func (m *mockLogger) Error(msg string, args ...any) {}
type mockSessionManager struct {
store map[string]any
mu sync.RWMutex
@@ -65,7 +60,7 @@ func TestHandleLogic(t *testing.T) {
}
d := &deps{
log: &mockLogger{},
log: slog.Default(),
sessions: mockSessions,
auth: &authenticator.Authenticator{
Config: oauth2.Config{

17
auth/auth0/options.go Normal file
View File

@@ -0,0 +1,17 @@
package auth0
import "log/slog"
type Option func(deps *Config)
func WithLogger(l *slog.Logger) Option {
return func(cfg *Config) {
cfg.Logger = l
}
}
func WithSessions(s SessionManager) Option {
return func(cfg *Config) {
cfg.Sessions = s
}
}