Documentation
¶
Overview ¶
Package api provides the HTTP API server for msgvault.
Index ¶
- func CORSMiddleware(cfg CORSConfig) func(http.Handler) http.Handler
- func RateLimitMiddleware(limiter *RateLimiter) func(http.Handler) http.Handler
- type APIAttachment
- type APIMessage
- type AccountInfo
- type AccountStatus
- type AttachmentInfo
- type CORSConfig
- type ErrorResponse
- type MessageDetail
- type MessageStore
- type MessageSummary
- type RateLimiter
- type SchedulerStatusResponse
- type SearchResult
- type Server
- type StatsResponse
- type StoreStats
- type SyncScheduler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORSMiddleware ¶
func CORSMiddleware(cfg CORSConfig) func(http.Handler) http.Handler
CORSMiddleware returns a middleware that handles CORS headers.
func RateLimitMiddleware ¶
func RateLimitMiddleware(limiter *RateLimiter) func(http.Handler) http.Handler
RateLimitMiddleware returns a middleware that rate limits requests by IP.
Types ¶
type APIAttachment ¶
type APIAttachment = store.APIAttachment
APIAttachment is an alias for store.APIAttachment.
type APIMessage ¶
type APIMessage = store.APIMessage
APIMessage is an alias for store.APIMessage — single source of truth for the message DTO shared between the store and API layers.
type AccountInfo ¶
type AccountInfo struct {
Email string `json:"email"`
DisplayName string `json:"display_name,omitempty"`
LastSyncAt string `json:"last_sync_at,omitempty"`
NextSyncAt string `json:"next_sync_at,omitempty"`
Schedule string `json:"schedule,omitempty"`
Enabled bool `json:"enabled"`
}
AccountInfo represents an account in list responses.
type AccountStatus ¶
type AccountStatus = scheduler.AccountStatus
AccountStatus is an alias for scheduler.AccountStatus — single source of truth.
type AttachmentInfo ¶
type AttachmentInfo struct {
Filename string `json:"filename"`
MimeType string `json:"mime_type"`
Size int64 `json:"size_bytes"`
}
AttachmentInfo represents attachment metadata in API responses.
type CORSConfig ¶
type CORSConfig struct {
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
AllowCredentials bool
MaxAge int // Preflight cache duration in seconds
}
CORSConfig holds CORS configuration.
func DefaultCORSConfig ¶
func DefaultCORSConfig() CORSConfig
DefaultCORSConfig returns a permissive CORS configuration for local development.
type ErrorResponse ¶
ErrorResponse represents an API error.
type MessageDetail ¶
type MessageDetail struct {
MessageSummary
Body string `json:"body"`
Attachments []AttachmentInfo `json:"attachments"`
}
MessageDetail represents a full message response.
type MessageStore ¶
type MessageStore interface {
GetStats() (*StoreStats, error)
ListMessages(offset, limit int) ([]APIMessage, int64, error)
GetMessage(id int64) (*APIMessage, error)
SearchMessages(query string, offset, limit int) ([]APIMessage, int64, error)
}
MessageStore defines the store operations the API needs.
type MessageSummary ¶
type MessageSummary struct {
ID int64 `json:"id"`
Subject string `json:"subject"`
From string `json:"from"`
To []string `json:"to"`
SentAt string `json:"sent_at"`
Snippet string `json:"snippet"`
Labels []string `json:"labels"`
HasAttach bool `json:"has_attachments"`
SizeBytes int64 `json:"size_bytes"`
}
MessageSummary represents a message in list responses.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides per-IP rate limiting with TTL-based eviction.
func NewRateLimiter ¶
func NewRateLimiter(rps float64, burst int) *RateLimiter
NewRateLimiter creates a new rate limiter. rps is requests per second, burst is the maximum burst size.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(key string) bool
Allow checks if a request from the given key should be allowed.
func (*RateLimiter) Close ¶
func (rl *RateLimiter) Close()
Close stops the background eviction goroutine. Safe to call multiple times concurrently.
type SchedulerStatusResponse ¶
type SchedulerStatusResponse struct {
Running bool `json:"running"`
Accounts []AccountStatus `json:"accounts"`
}
SchedulerStatusResponse represents scheduler status.
type SearchResult ¶
type SearchResult struct {
Query string `json:"query"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
Messages []MessageSummary `json:"messages"`
}
SearchResult represents search results.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the HTTP API server.
func NewServer ¶
func NewServer(cfg *config.Config, store MessageStore, sched SyncScheduler, logger *slog.Logger) *Server
NewServer creates a new API server.
type StatsResponse ¶
type StatsResponse struct {
TotalMessages int64 `json:"total_messages"`
TotalThreads int64 `json:"total_threads"`
TotalAccounts int64 `json:"total_accounts"`
TotalLabels int64 `json:"total_labels"`
TotalAttach int64 `json:"total_attachments"`
DatabaseSize int64 `json:"database_size_bytes"`
}
StatsResponse represents the archive statistics.
type StoreStats ¶
StoreStats is an alias for store.Stats — single source of truth.
type SyncScheduler ¶
type SyncScheduler interface {
IsScheduled(email string) bool
TriggerSync(email string) error
Status() []AccountStatus
IsRunning() bool
}
SyncScheduler defines the scheduler operations the API needs.