lavender/auth/authContext/template.go

43 lines
936 B
Go
Raw Normal View History

2025-01-19 12:04:25 +00:00
package authContext
import (
"context"
"github.com/1f349/lavender/database"
"net/http"
)
2025-01-25 19:49:57 +00:00
func NewTemplateContext(req *http.Request, user *database.User) *BaseTemplateContext {
2025-01-19 12:04:25 +00:00
return &BaseTemplateContext{
req: req,
user: user,
}
}
type TemplateContext interface {
Context() context.Context
Request() *http.Request
User() *database.User
Render(data any)
__templateContext()
2025-01-25 19:49:57 +00:00
}
var _ TemplateContext = &BaseTemplateContext{}
2025-01-19 12:04:25 +00:00
type BaseTemplateContext struct {
req *http.Request
user *database.User
data any
}
2025-01-25 19:49:57 +00:00
func (t *BaseTemplateContext) Context() context.Context { return t.req.Context() }
2025-01-19 12:04:25 +00:00
2025-01-25 19:49:57 +00:00
func (t *BaseTemplateContext) Request() *http.Request { return t.req }
2025-01-19 12:04:25 +00:00
2025-01-25 19:49:57 +00:00
func (t *BaseTemplateContext) User() *database.User { return t.user }
2025-01-19 12:04:25 +00:00
2025-01-25 19:49:57 +00:00
func (t *BaseTemplateContext) Render(data any) { t.data = data }
2025-01-19 12:04:25 +00:00
func (t *BaseTemplateContext) Data() any { return t.data }
func (t *BaseTemplateContext) __templateContext() {}