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)
|
||||
|
||||
Reference in New Issue
Block a user