added nats + worker modules
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
17
auth/auth0/options.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user