server

package
v0.0.0-...-f2259ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package server provides shared HTTP server utilities for mote-server.

Index

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

func CORSMiddleware(next http.Handler) http.Handler

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 NewRouter

func NewRouter(pool *pgxpool.Pool, jwtCfg auth.JWTConfig) http.Handler

func RequireIdentity

func RequireIdentity(next http.Handler) http.Handler

RequireIdentity is middleware that rejects requests without a resolved identity.

func ResolveIdentity

func ResolveIdentity(pool *pgxpool.Pool, jwtCfg auth.JWTConfig) func(http.Handler) http.Handler

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 SPAHandler

func SPAHandler(pool *pgxpool.Pool) http.Handler

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 SignInHandler(pool *pgxpool.Pool, jwtCfg auth.JWTConfig) http.HandlerFunc

func SignUpHandler

func SignUpHandler(pool *pgxpool.Pool, jwtCfg auth.JWTConfig) http.HandlerFunc

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 AppendEntryRequest struct {
	Content     string  `json:"content"`
	RuntimeHint *string `json:"runtime_hint,omitempty"`
	HostHint    *string `json:"host_hint,omitempty"`
	SessionHint *string `json:"session_hint,omitempty"`
	TaskHint    *string `json:"task_hint,omitempty"`
}

type CreateAPIKeyRequest

type CreateAPIKeyRequest struct {
	Name string `json:"name"`
}

type CreateCommentRequest

type CreateCommentRequest struct {
	EntryID     string  `json:"entry_id"`
	Content     string  `json:"content"`
	RuntimeHint *string `json:"runtime_hint,omitempty"`
	HostHint    *string `json:"host_hint,omitempty"`
	SessionHint *string `json:"session_hint,omitempty"`
	TaskHint    *string `json:"task_hint,omitempty"`
}

type CreateMoteRequest

type CreateMoteRequest struct {
	Title       string  `json:"title"`
	RuntimeHint *string `json:"runtime_hint,omitempty"`
	HostHint    *string `json:"host_hint,omitempty"`
	SessionHint *string `json:"session_hint,omitempty"`
	TaskHint    *string `json:"task_hint,omitempty"`
}

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.

func IdentityFromContext

func IdentityFromContext(ctx context.Context) (*Identity, bool)

IdentityFromContext retrieves the resolved identity from a request context.

type SignInRequest

type SignInRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type SignUpRequest

type SignUpRequest struct {
	Email       string `json:"email"`
	Password    string `json:"password"`
	DisplayName string `json:"display_name"`
}

type SignUpResponse

type SignUpResponse struct {
	User  *model.User `json:"user"`
	Token string      `json:"token"`
}

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL