Documentation
¶
Overview ¶
Package server provides shared HTTP server utilities for mote-server.
Index ¶
- func AppendEntryHandler(pool *pgxpool.Pool) http.HandlerFunc
- func CORSMiddleware(next http.Handler) http.Handler
- func CreateAPIKeyHandler(pool *pgxpool.Pool) http.HandlerFunc
- func CreateCommentHandler(pool *pgxpool.Pool) http.HandlerFunc
- func CreateMoteHandler(pool *pgxpool.Pool) http.HandlerFunc
- func DeleteCommentHandler(pool *pgxpool.Pool) http.HandlerFunc
- func DeleteEntryHandler(pool *pgxpool.Pool) http.HandlerFunc
- func DeleteMoteHandler(pool *pgxpool.Pool) http.HandlerFunc
- func HealthHandler(pool *pgxpool.Pool) http.HandlerFunc
- func ListAPIKeysHandler(pool *pgxpool.Pool) http.HandlerFunc
- func ListMotesHandler(pool *pgxpool.Pool) http.HandlerFunc
- func NewRouter(pool *pgxpool.Pool, jwtCfg auth.JWTConfig) http.Handler
- func RequireIdentity(next http.Handler) http.Handler
- func ResolveIdentity(pool *pgxpool.Pool, jwtCfg auth.JWTConfig) func(http.Handler) http.Handler
- func RevokeAPIKeyHandler(pool *pgxpool.Pool) http.HandlerFunc
- func SPAHandler(pool *pgxpool.Pool) http.Handler
- func ShowMoteHandler(pool *pgxpool.Pool) http.HandlerFunc
- func SignInHandler(pool *pgxpool.Pool, jwtCfg auth.JWTConfig) http.HandlerFunc
- func SignUpHandler(pool *pgxpool.Pool, jwtCfg auth.JWTConfig) http.HandlerFunc
- func UpdateCommentHandler(pool *pgxpool.Pool) http.HandlerFunc
- func UpdateEntryHandler(pool *pgxpool.Pool) http.HandlerFunc
- func UpdateMoteTitleHandler(pool *pgxpool.Pool) http.HandlerFunc
- func UpdatePermissionHandler(pool *pgxpool.Pool) http.HandlerFunc
- func WhoamiHandler(pool *pgxpool.Pool) http.HandlerFunc
- type AppendEntryRequest
- type CreateAPIKeyRequest
- type CreateCommentRequest
- type CreateMoteRequest
- type Identity
- type SignInRequest
- type SignUpRequest
- type SignUpResponse
- type UpdateCommentRequest
- type UpdateEntryRequest
- type UpdateMoteTitleRequest
- type UpdatePermissionRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendEntryHandler ¶
func AppendEntryHandler(pool *pgxpool.Pool) http.HandlerFunc
AppendEntryHandler appends a new entry to a Mote. POST /api/workspaces/{workspaceSlug}/motes/{shortID}/entries
func CORSMiddleware ¶
CORSMiddleware returns a middleware that adds CORS headers for development. In production, origins should be restricted to the configured app origin.
func CreateAPIKeyHandler ¶
func CreateAPIKeyHandler(pool *pgxpool.Pool) http.HandlerFunc
func CreateCommentHandler ¶
func CreateCommentHandler(pool *pgxpool.Pool) http.HandlerFunc
CreateCommentHandler adds a new comment to a Mote. POST /api/workspaces/{workspaceSlug}/motes/{shortID}/comments
func CreateMoteHandler ¶
func CreateMoteHandler(pool *pgxpool.Pool) http.HandlerFunc
CreateMoteHandler creates a new Mote in the authenticated user's workspace. POST /api/workspaces/{workspaceSlug}/motes
func DeleteCommentHandler ¶
func DeleteCommentHandler(pool *pgxpool.Pool) http.HandlerFunc
DeleteCommentHandler allows the mote owner to delete a comment. DELETE /api/workspaces/{workspaceSlug}/motes/{shortID}/comments/{commentID}
func DeleteEntryHandler ¶
func DeleteEntryHandler(pool *pgxpool.Pool) http.HandlerFunc
DeleteEntryHandler allows the mote owner to delete an entry. DELETE /api/workspaces/{workspaceSlug}/motes/{shortID}/entries/{entryID}
func DeleteMoteHandler ¶
func DeleteMoteHandler(pool *pgxpool.Pool) http.HandlerFunc
DeleteMoteHandler allows the owner to delete a Mote. DELETE /api/workspaces/{workspaceSlug}/motes/{shortID}
func HealthHandler ¶
func HealthHandler(pool *pgxpool.Pool) http.HandlerFunc
HealthHandler returns an http.HandlerFunc that checks database connectivity. If pool is nil, it reports degraded status.
func ListAPIKeysHandler ¶
func ListAPIKeysHandler(pool *pgxpool.Pool) http.HandlerFunc
func ListMotesHandler ¶
func ListMotesHandler(pool *pgxpool.Pool) http.HandlerFunc
ListMotesHandler returns the Motes visible to the authenticated caller in the given workspace, using the same permission model as show/read. GET /api/workspaces/{workspaceSlug}/motes
Visibility rules:
- The workspace owner sees all Motes.
- Authenticated non-owners see only public Motes (public-readable, public-commentable, public-editable).
- Anonymous callers are rejected (authentication required).
func RequireIdentity ¶
RequireIdentity is middleware that rejects requests without a resolved identity.
func ResolveIdentity ¶
ResolveIdentity extracts and validates authentication credentials from the request. It supports JWT (Authorization: Bearer <token>) and API key (Authorization: Bearer mote_...) authentication.
If both JWT and API key credentials are present, it rejects the request with 400 Bad Request (mixed-credential rule).
func RevokeAPIKeyHandler ¶
func RevokeAPIKeyHandler(pool *pgxpool.Pool) http.HandlerFunc
func ShowMoteHandler ¶
func ShowMoteHandler(pool *pgxpool.Pool) http.HandlerFunc
ShowMoteHandler returns a single Mote with its entries and comments. GET /api/workspaces/{workspaceSlug}/motes/{shortID}
func SignInHandler ¶
func SignUpHandler ¶
func UpdateCommentHandler ¶
func UpdateCommentHandler(pool *pgxpool.Pool) http.HandlerFunc
UpdateCommentHandler allows the comment author or mote owner to update comment content. PATCH /api/workspaces/{workspaceSlug}/motes/{shortID}/comments/{commentID}
func UpdateEntryHandler ¶
func UpdateEntryHandler(pool *pgxpool.Pool) http.HandlerFunc
UpdateEntryHandler allows the entry author or mote owner to update entry content. PATCH /api/workspaces/{workspaceSlug}/motes/{shortID}/entries/{entryID}
func UpdateMoteTitleHandler ¶
func UpdateMoteTitleHandler(pool *pgxpool.Pool) http.HandlerFunc
UpdateMoteTitleHandler allows the owner to update a Mote's title. PATCH /api/workspaces/{workspaceSlug}/motes/{shortID}
func UpdatePermissionHandler ¶
func UpdatePermissionHandler(pool *pgxpool.Pool) http.HandlerFunc
UpdatePermissionHandler allows the owner to update a Mote's permission mode. PATCH /api/workspaces/{workspaceSlug}/motes/{shortID}/permissions
func WhoamiHandler ¶
func WhoamiHandler(pool *pgxpool.Pool) http.HandlerFunc
Types ¶
type AppendEntryRequest ¶
type CreateAPIKeyRequest ¶
type CreateAPIKeyRequest struct {
Name string `json:"name"`
}
type CreateCommentRequest ¶
type CreateMoteRequest ¶
type Identity ¶
type Identity struct {
UserID string
Email string
Slug string
WorkspaceID string // resolved workspace (default personal or from API key)
Method string // "jwt" or "api_key"
APIKeyID string // set only when Method == "api_key"
}
Identity holds the resolved caller identity for a request.
type SignInRequest ¶
type SignUpRequest ¶
type SignUpResponse ¶
type UpdateCommentRequest ¶
type UpdateCommentRequest struct {
Content string `json:"content"`
}
type UpdateEntryRequest ¶
type UpdateEntryRequest struct {
Content string `json:"content"`
}
type UpdateMoteTitleRequest ¶
type UpdateMoteTitleRequest struct {
Title string `json:"title"`
}
type UpdatePermissionRequest ¶
type UpdatePermissionRequest struct {
Mode string `json:"mode"`
}