Documentation
¶
Overview ¶
Package server implements HTTP routing, middleware, and request handling.
It provides handler composition utilities (Wrap, WrapAuth) for type-safe routes with JWT authentication, role-based access control, and automatic JSON marshaling. It also serves the embedded SolidJS frontend.
Index ¶
- func NewRouter(fileStore *content.FileStore, userService *identity.UserService, ...) http.Handler
- func Wrap[In any, PtrIn interface{ ... }, Out any](fn func(context.Context, PtrIn) (*Out, error)) http.Handler
- func WrapAuth[In any, PtrIn interface{ ... }, Out any](userService *identity.UserService, memService *identity.MembershipService, ...) http.Handler
- func WrapAuthRaw(userService *identity.UserService, memService *identity.MembershipService, ...) http.Handler
- func WrapGlobalAdmin[In any, PtrIn interface{ ... }, Out any](userService *identity.UserService, jwtSecret []byte, ...) http.Handler
- type EmbeddedSPAHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRouter ¶
func NewRouter(fileStore *content.FileStore, userService *identity.UserService, orgService *identity.OrganizationService, invService *identity.InvitationService, memService *identity.MembershipService, jwtSecret, baseURL, googleClientID, googleClientSecret, msClientID, msClientSecret string) http.Handler
NewRouter creates and configures the HTTP router. Serves API endpoints at /api/* and static SolidJS frontend at /. baseURL is used for constructing OAuth callback URLs (e.g., "http://localhost:8080" or "https://example.com").
func Wrap ¶
func Wrap[In any, PtrIn interface { *In dto.Validatable }, Out any](fn func(context.Context, PtrIn) (*Out, error)) http.Handler
Wrap wraps a handler function to work as an http.Handler. The function must have signature: func(context.Context, *In) (*Out, error) where In can be unmarshalled from JSON and Out is a struct. Path parameters can be extracted by tagging struct fields with `path:"name"`. *In must implement dto.Validatable.
Example:
type GetPageRequest struct {
ID string `path:"id"`
}
func (h *Handler) GetPage(ctx context.Context, req *GetPageRequest) (*Response, error)
func WrapAuth ¶
func WrapAuth[In any, PtrIn interface { *In dto.Validatable }, Out any]( userService *identity.UserService, memService *identity.MembershipService, jwtSecret []byte, requiredRole identity.UserRole, fn func(context.Context, jsonldb.ID, *identity.User, PtrIn) (*Out, error), ) http.Handler
WrapAuth wraps an authenticated handler function to work as an http.Handler. It combines JWT validation, organization membership checking, and request parsing. The function must have signature: func(context.Context, jsonldb.ID, *identity.User, *In) (*Out, error) where orgID is the organization ID from the path (zero if not present), user is the authenticated user, In can be unmarshalled from JSON, and Out is a struct. *In must implement dto.Validatable.
func WrapAuthRaw ¶
func WrapAuthRaw( userService *identity.UserService, memService *identity.MembershipService, jwtSecret []byte, requiredRole identity.UserRole, fn http.HandlerFunc, ) http.Handler
WrapAuthRaw wraps a raw http.HandlerFunc with authentication and role checking. Use this for handlers that need to handle requests directly (e.g., multipart forms). The wrapped handler receives the request with validated auth - the handler should extract orgID from the path via r.PathValue("orgID") if needed.
func WrapGlobalAdmin ¶
func WrapGlobalAdmin[In any, PtrIn interface { *In dto.Validatable }, Out any]( userService *identity.UserService, jwtSecret []byte, fn func(context.Context, *identity.User, PtrIn) (*Out, error), ) http.Handler
WrapGlobalAdmin wraps a handler that requires global admin privileges. These endpoints are for server-wide administration (stats, all users, all orgs). No organization context is required - just valid JWT and IsGlobalAdmin flag. *In must implement dto.Validatable.
Types ¶
type EmbeddedSPAHandler ¶
type EmbeddedSPAHandler struct {
// contains filtered or unexported fields
}
EmbeddedSPAHandler serves an embedded single-page application with fallback to index.html.
func NewEmbeddedSPAHandler ¶
func NewEmbeddedSPAHandler(f embed.FS) *EmbeddedSPAHandler
NewEmbeddedSPAHandler creates a handler for the embedded frontend.
func (*EmbeddedSPAHandler) ServeHTTP ¶
func (h *EmbeddedSPAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler for embedded SPA routing.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dto defines API request/response types and error handling.
|
Package dto defines API request/response types and error handling. |
|
Package handlers provides HTTP request handlers for the REST API.
|
Package handlers provides HTTP request handlers for the REST API. |