Documentation
¶
Index ¶
- Constants
- Variables
- func BaseMiddleware(next http.Handler) http.Handler
- func CachingMiddleware(maxAge int) func(next http.Handler) http.Handler
- func ContentTypeMiddleware(contentType string) func(next http.Handler) http.Handler
- func SetAuth(ctx context.Context, auth Auth) context.Context
- func StaticContentMiddleware(next http.Handler) http.Handler
- type Auth
- type AuthRepository
- type Authenticator
- type BBoltAuthRepository
- func (r *BBoltAuthRepository) FindSession(id SessionID) (Session, error)
- func (r *BBoltAuthRepository) FindToken(id TokenID) (Token, error)
- func (r *BBoltAuthRepository) ResolveUserID(email mail.Address) (UserID, error)
- func (r *BBoltAuthRepository) StoreSession(s Session) error
- func (r *BBoltAuthRepository) StoreToken(t Token) error
- type BoltStatisticsRepository
- type CloseHandler
- type Controller
- type Controller2
- type Endpoint
- type ErrorHandler
- type ErrorHandler2
- type ErrorHandlerChain
- type Handler
- type InMemoryAuthRepository
- func (r *InMemoryAuthRepository) FindSession(id SessionID) (Session, error)
- func (r *InMemoryAuthRepository) FindToken(id TokenID) (Token, error)
- func (r *InMemoryAuthRepository) ResolveUserID(email mail.Address) (UserID, error)
- func (r *InMemoryAuthRepository) StoreSession(s Session) error
- func (r *InMemoryAuthRepository) StoreToken(t Token) error
- type Mailer
- type MessageHandler
- type Middleware
- type SMTPMailer
- type Session
- type SessionID
- type SitemapController
- type StatisticsModule
- type StatisticsRepository
- type StubMailer
- type Template
- type TemplateData
- type TemplateModule
- type Templater
- type Token
- type TokenID
- type UserAuth
- type UserID
- type WSClient
Constants ¶
View Source
const ( CacheControlHeader = "Cache-Control" ContentTypeHeader = "Content-Type" ETagHeader = "ETag" LocationHeader = "Location" ContentTypeAtom = "application/atom+xml" ContentTypeHTML = "text/html" ContentTypeJSON = "application/json" ContentTypeText = "text/plain; charset=UTF-8" ContentTypeOctetStream = "application/octet-stream" ContentTypeJavascript = "text/javascript" )
View Source
const CacheDurationImmutable = -1
View Source
const (
LoginPath = "/login.html"
)
Variables ¶
View Source
var (
ErrUnauthenticated = errors.New("no authentication found")
)
Functions ¶
func CachingMiddleware ¶
CachingMiddleware returns a handler that sets the Cache-Control header with the specified max-age. If the given value is negative, max-age will be set to one year and 'immutable' will be added to the Cache-Control value.
func ContentTypeMiddleware ¶
Types ¶
type AuthRepository ¶
type Authenticator ¶
type Authenticator struct {
TokenCallback func(mail.Address, TokenID) error
RedirectTarget string
// contains filtered or unexported fields
}
func NewAuthenticator ¶
func NewAuthenticator(domain string, redirectTarget string, repo AuthRepository, templateFS, assetsFS fs.FS) *Authenticator
func (*Authenticator) Controller ¶
func (a *Authenticator) Controller() *Controller
func (*Authenticator) GenerateToken ¶
func (a *Authenticator) GenerateToken(length int) (TokenID, error)
func (*Authenticator) Middleware ¶
func (a *Authenticator) Middleware(next http.Handler) http.Handler
type BBoltAuthRepository ¶
type BBoltAuthRepository struct {
// contains filtered or unexported fields
}
func NewBBoltAuthRepository ¶
func NewBBoltAuthRepository(db *bbolt.DB) *BBoltAuthRepository
TODO: Rather return the errors here?
func (*BBoltAuthRepository) FindSession ¶
func (r *BBoltAuthRepository) FindSession(id SessionID) (Session, error)
func (*BBoltAuthRepository) FindToken ¶
func (r *BBoltAuthRepository) FindToken(id TokenID) (Token, error)
func (*BBoltAuthRepository) ResolveUserID ¶
func (r *BBoltAuthRepository) ResolveUserID(email mail.Address) (UserID, error)
func (*BBoltAuthRepository) StoreSession ¶
func (r *BBoltAuthRepository) StoreSession(s Session) error
func (*BBoltAuthRepository) StoreToken ¶
func (r *BBoltAuthRepository) StoreToken(t Token) error
type BoltStatisticsRepository ¶
type BoltStatisticsRepository struct {
// contains filtered or unexported fields
}
func NewBoltStatisticsRepository ¶
func NewBoltStatisticsRepository(db *bbolt.DB) (*BoltStatisticsRepository, error)
func (*BoltStatisticsRepository) AddView ¶
func (r *BoltStatisticsRepository) AddView(page string) error
type CloseHandler ¶
type CloseHandler func()
type Controller ¶
type Controller struct {
BasePath string
Handlers map[Endpoint]Handler
Middleware []Middleware
ErrorHandler ErrorHandler
}
func NewAssetController ¶
func NewAssetController(basePath string, fileSystem fs.FS) *Controller
func NewCacheBustingAssetController ¶
func NewCacheBustingAssetController(basePath string, fileSystem fs.FS) *Controller
func (*Controller) AddMiddleware ¶
func (c *Controller) AddMiddleware(m Middleware) *Controller
func (*Controller) Register ¶
func (c *Controller) Register(router chi.Router)
type Controller2 ¶
type Controller2 struct {
ErrorHandler func(handler Handler) http.Handler
// contains filtered or unexported fields
}
func NewController ¶
func NewController() *Controller2
func (*Controller2) AddMiddleware ¶
func (c *Controller2) AddMiddleware(m Middleware)
func (*Controller2) GET ¶
func (c *Controller2) GET(path string, handler Handler)
func (*Controller2) Handler ¶
func (c *Controller2) Handler() http.Handler
func (*Controller2) POST ¶
func (c *Controller2) POST(path string, handler Handler)
type ErrorHandler ¶
type ErrorHandler2 ¶
type ErrorHandlerChain ¶
type ErrorHandlerChain []ErrorHandler2
func (*ErrorHandlerChain) AddErrorHandler ¶
func (chain *ErrorHandlerChain) AddErrorHandler(handler ErrorHandler2)
func (ErrorHandlerChain) BuildErrorHandler ¶
func (chain ErrorHandlerChain) BuildErrorHandler(errorTemplate *Template) func(Handler) http.Handler
type InMemoryAuthRepository ¶
type InMemoryAuthRepository struct {
// contains filtered or unexported fields
}
func NewInMemoryAuthRepository ¶
func NewInMemoryAuthRepository() *InMemoryAuthRepository
func (*InMemoryAuthRepository) FindSession ¶
func (r *InMemoryAuthRepository) FindSession(id SessionID) (Session, error)
func (*InMemoryAuthRepository) FindToken ¶
func (r *InMemoryAuthRepository) FindToken(id TokenID) (Token, error)
func (*InMemoryAuthRepository) ResolveUserID ¶
func (r *InMemoryAuthRepository) ResolveUserID(email mail.Address) (UserID, error)
func (*InMemoryAuthRepository) StoreSession ¶
func (r *InMemoryAuthRepository) StoreSession(s Session) error
func (*InMemoryAuthRepository) StoreToken ¶
func (r *InMemoryAuthRepository) StoreToken(t Token) error
type MessageHandler ¶
type SMTPMailer ¶
type SMTPMailer struct {
// contains filtered or unexported fields
}
type SitemapController ¶
type SitemapController struct {
Controller
// contains filtered or unexported fields
}
func NewSitemapController ¶
func NewSitemapController() *SitemapController
func (*SitemapController) AddSite ¶
func (sc *SitemapController) AddSite(url url.URL)
type StatisticsModule ¶
type StatisticsModule struct {
// contains filtered or unexported fields
}
func NewStatisticsModule ¶
func NewStatisticsModule(repo StatisticsRepository) *StatisticsModule
func (*StatisticsModule) Controller ¶
func (m *StatisticsModule) Controller() *Controller
func (*StatisticsModule) Middleware ¶
func (m *StatisticsModule) Middleware(next http.Handler) http.Handler
type StatisticsRepository ¶
type StubMailer ¶
type StubMailer struct{}
type TemplateData ¶
type TemplateModule ¶
type TemplateModule struct {
// contains filtered or unexported fields
}
func NewTemplateModule ¶
func NewTemplateModule(templateFS, assetsFS fs.FS, data any) *TemplateModule
func (*TemplateModule) Controller ¶
func (m *TemplateModule) Controller() *Controller
type Templater ¶
type Templater struct {
// contains filtered or unexported fields
}
func NewTemplater ¶
type WSClient ¶
type WSClient struct {
// contains filtered or unexported fields
}
func NewWSClient ¶
func NewWSClient(conn *websocket.Conn, onMessage MessageHandler, onClose CloseHandler) *WSClient
func (*WSClient) WriteMessage ¶
Click to show internal directories.
Click to hide internal directories.