handlers

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const APIVersion = "1.0"
View Source
const MaxJSONBodySize = 2 * 1024 * 1024

MaxJSONBodySize is the maximum allowed size for JSON request bodies (2MB)

Variables

This section is empty.

Functions

func Created

func Created(w http.ResponseWriter, r *http.Request, data interface{})

Created sends a 201 response with the created resource

func DecodeJSON added in v1.1.3

func DecodeJSON(r *http.Request, v interface{}) error

DecodeJSON safely decodes JSON from request body with size limit

func Error

func Error(w http.ResponseWriter, r *http.Request, status int, code, message string)

Error sends an error response

func Forbidden

func Forbidden(w http.ResponseWriter, r *http.Request)

Forbidden sends a 403 response

func InternalError

func InternalError(w http.ResponseWriter, r *http.Request)

InternalError sends a 500 response

func JSON

func JSON(w http.ResponseWriter, status int, data interface{})

JSON sends a JSON response

func NoContent

func NoContent(w http.ResponseWriter)

NoContent sends a 204 response

func NotFound

func NotFound(w http.ResponseWriter, r *http.Request, message string)

NotFound sends a 404 response

func OK

func OK(w http.ResponseWriter, r *http.Request, data interface{})

OK sends a 200 response

func Success added in v1.2.0

func Success(w http.ResponseWriter, r *http.Request, status int, data interface{})

Success sends a standardized success response with metadata

func SuccessList added in v1.2.0

func SuccessList(w http.ResponseWriter, r *http.Request, data interface{}, page, limit, total int)

SuccessList sends a standardized list response with pagination

func Unauthorized

func Unauthorized(w http.ResponseWriter, r *http.Request)

Unauthorized sends a 401 response

func ValidationErrors

func ValidationErrors(w http.ResponseWriter, r *http.Request, errors validation.ValidationErrors)

ValidationErrors sends a validation error response

Types

type APIResponse added in v1.2.0

type APIResponse struct {
	Data  interface{}  `json:"data"`
	Meta  *Meta        `json:"meta,omitempty"`
	Error *ErrorDetail `json:"error,omitempty"`
}

APIResponse is the standard response envelope

type AuthHandler

type AuthHandler struct {
	// contains filtered or unexported fields
}

AuthHandler handles authentication-related HTTP requests

func NewAuthHandler

func NewAuthHandler(authService *auth.Service) *AuthHandler

NewAuthHandler creates a new auth handler

func (*AuthHandler) Check

func (h *AuthHandler) Check(w http.ResponseWriter, r *http.Request)

Check handles GET /api/v1/auth/check

func (*AuthHandler) Login

func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request)

Login handles POST /api/v1/auth/login

func (*AuthHandler) Logout

func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request)

Logout handles POST /api/v1/auth/logout

func (*AuthHandler) WithDemoMode added in v1.3.3

func (h *AuthHandler) WithDemoMode(enabled bool) *AuthHandler

WithDemoMode sets the demo mode flag

type BackupHandler

type BackupHandler struct {
	// contains filtered or unexported fields
}

BackupHandler handles backup-related HTTP requests

func NewBackupHandler

func NewBackupHandler(backupSvc *services.BackupService, s3SyncSvc *services.S3SyncService) *BackupHandler

NewBackupHandler creates a new backup handler

func (*BackupHandler) Export

func (h *BackupHandler) Export(w http.ResponseWriter, r *http.Request)

Export handles GET /api/v1/backup/export Query params: format (json|zip), password (optional)

func (*BackupHandler) Import

func (h *BackupHandler) Import(w http.ResponseWriter, r *http.Request)

Import handles POST /api/v1/backup/import Form data: file (multipart), strategy (replace|merge|skip), password (optional)

func (*BackupHandler) S3Delete

func (h *BackupHandler) S3Delete(w http.ResponseWriter, r *http.Request)

S3Delete handles DELETE /api/v1/backup/s3/{key}

func (*BackupHandler) S3List

func (h *BackupHandler) S3List(w http.ResponseWriter, r *http.Request)

S3List handles GET /api/v1/backup/s3/list

func (*BackupHandler) S3Restore

func (h *BackupHandler) S3Restore(w http.ResponseWriter, r *http.Request)

S3Restore handles POST /api/v1/backup/s3/restore Body: { "key": "backups/snipo-backup-xxx.json", "strategy": "replace|merge|skip", "password": "optional" }

func (*BackupHandler) S3Status

func (h *BackupHandler) S3Status(w http.ResponseWriter, r *http.Request)

S3Status handles GET /api/v1/backup/s3/status

func (*BackupHandler) S3Sync

func (h *BackupHandler) S3Sync(w http.ResponseWriter, r *http.Request)

S3Sync handles POST /api/v1/backup/s3/sync Body: { "format": "json|zip", "password": "optional" }

type ConfigInput added in v1.3.3

type ConfigInput struct {
	Enabled                    bool   `json:"enabled"`
	GithubToken                string `json:"github_token"`
	AutoSyncEnabled            bool   `json:"auto_sync_enabled"`
	SyncIntervalMinutes        int    `json:"sync_interval_minutes"`
	ConflictResolutionStrategy string `json:"conflict_resolution_strategy"`
}

ConfigInput represents the input for configuring gist sync

type ConfigResponse added in v1.3.3

type ConfigResponse struct {
	Enabled                    bool   `json:"enabled"`
	GithubUsername             string `json:"github_username"`
	HasToken                   bool   `json:"has_token"`
	AutoSyncEnabled            bool   `json:"auto_sync_enabled"`
	SyncIntervalMinutes        int    `json:"sync_interval_minutes"`
	ConflictResolutionStrategy string `json:"conflict_resolution_strategy"`
	LastFullSyncAt             string `json:"last_full_sync_at,omitempty"`
}

ConfigResponse represents the gist sync configuration response (token masked)

type ErrorDetail

type ErrorDetail struct {
	Code      string                       `json:"code"`
	Message   string                       `json:"message"`
	Details   []validation.ValidationError `json:"details,omitempty"`
	RequestID string                       `json:"request_id,omitempty"`
	Timestamp time.Time                    `json:"timestamp,omitempty"`
}

ErrorDetail contains error details

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents an API error response

type FeatureFlags added in v1.2.0

type FeatureFlags struct {
	PublicSnippets bool `json:"public_snippets"`
	S3Sync         bool `json:"s3_sync"`
	APITokens      bool `json:"api_tokens"`
	BackupRestore  bool `json:"backup_restore"`
}

FeatureFlags represents enabled features

type FolderHandler

type FolderHandler struct {
	// contains filtered or unexported fields
}

FolderHandler handles folder-related HTTP requests

func NewFolderHandler

func NewFolderHandler(repo *repository.FolderRepository) *FolderHandler

NewFolderHandler creates a new folder handler

func (*FolderHandler) Create

func (h *FolderHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/folders

func (*FolderHandler) Delete

func (h *FolderHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/folders/{id}

func (*FolderHandler) Get

Get handles GET /api/v1/folders/{id}

func (*FolderHandler) List

func (h *FolderHandler) List(w http.ResponseWriter, r *http.Request)

List handles GET /api/v1/folders

func (*FolderHandler) Move

func (h *FolderHandler) Move(w http.ResponseWriter, r *http.Request)

Move handles PUT /api/v1/folders/{id}/move

func (*FolderHandler) Update

func (h *FolderHandler) Update(w http.ResponseWriter, r *http.Request)

Update handles PUT /api/v1/folders/{id}

type GistSyncHandler added in v1.3.3

type GistSyncHandler struct {
	// contains filtered or unexported fields
}

GistSyncHandler handles gist sync related endpoints

func NewGistSyncHandler added in v1.3.3

func NewGistSyncHandler(
	syncRepo *repository.GistSyncRepository,
	snippetRepo *repository.SnippetRepository,
	fileRepo *repository.SnippetFileRepository,
	encryptionSvc *services.EncryptionService,
) *GistSyncHandler

NewGistSyncHandler creates a new gist sync handler

func (*GistSyncHandler) ClearConfig added in v1.3.3

func (h *GistSyncHandler) ClearConfig(w http.ResponseWriter, r *http.Request)

ClearConfig clears the GitHub token and disables sync

func (*GistSyncHandler) DeleteMapping added in v1.3.3

func (h *GistSyncHandler) DeleteMapping(w http.ResponseWriter, r *http.Request)

DeleteMapping deletes a snippet-gist mapping

func (*GistSyncHandler) DisableSync added in v1.3.3

func (h *GistSyncHandler) DisableSync(w http.ResponseWriter, r *http.Request)

DisableSync disables sync for a snippet

func (*GistSyncHandler) EnableSync added in v1.3.3

func (h *GistSyncHandler) EnableSync(w http.ResponseWriter, r *http.Request)

EnableSync enables sync for a snippet

func (*GistSyncHandler) EnableSyncForAll added in v1.3.3

func (h *GistSyncHandler) EnableSyncForAll(w http.ResponseWriter, r *http.Request)

EnableSyncForAll enables sync for all snippets

func (*GistSyncHandler) GetConfig added in v1.3.3

func (h *GistSyncHandler) GetConfig(w http.ResponseWriter, r *http.Request)

GetConfig retrieves the gist sync configuration

func (*GistSyncHandler) GetLogs added in v1.3.3

func (h *GistSyncHandler) GetLogs(w http.ResponseWriter, r *http.Request)

GetLogs retrieves sync operation logs

func (*GistSyncHandler) ListConflicts added in v1.3.3

func (h *GistSyncHandler) ListConflicts(w http.ResponseWriter, r *http.Request)

ListConflicts lists all unresolved conflicts

func (*GistSyncHandler) ListMappings added in v1.3.3

func (h *GistSyncHandler) ListMappings(w http.ResponseWriter, r *http.Request)

ListMappings lists all snippet-gist mappings

func (*GistSyncHandler) ResolveConflict added in v1.3.3

func (h *GistSyncHandler) ResolveConflict(w http.ResponseWriter, r *http.Request)

ResolveConflict resolves a conflict

func (*GistSyncHandler) SyncAll added in v1.3.3

func (h *GistSyncHandler) SyncAll(w http.ResponseWriter, r *http.Request)

SyncAll syncs all enabled snippets

func (*GistSyncHandler) SyncSnippet added in v1.3.3

func (h *GistSyncHandler) SyncSnippet(w http.ResponseWriter, r *http.Request)

SyncSnippet syncs a specific snippet to gist

func (*GistSyncHandler) TestConnection added in v1.3.3

func (h *GistSyncHandler) TestConnection(w http.ResponseWriter, r *http.Request)

TestConnection tests the GitHub token validity

func (*GistSyncHandler) UpdateConfig added in v1.3.3

func (h *GistSyncHandler) UpdateConfig(w http.ResponseWriter, r *http.Request)

UpdateConfig updates the gist sync configuration

type HealthHandler

type HealthHandler struct {
	// contains filtered or unexported fields
}

HealthHandler handles health check requests

func NewHealthHandler

func NewHealthHandler(db *sql.DB, version, commit string, features *config.FeatureFlags) *HealthHandler

NewHealthHandler creates a new health handler

func (*HealthHandler) Health

func (h *HealthHandler) Health(w http.ResponseWriter, r *http.Request)

Health handles GET /health

func (*HealthHandler) Ping

func (h *HealthHandler) Ping(w http.ResponseWriter, r *http.Request)

Ping handles GET /ping - simple liveness check

type HealthResponse

type HealthResponse struct {
	Status    string            `json:"status"`
	Version   string            `json:"version"`
	Commit    string            `json:"commit,omitempty"`
	Uptime    string            `json:"uptime"`
	Checks    map[string]string `json:"checks"`
	Memory    MemoryStats       `json:"memory"`
	Features  *FeatureFlags     `json:"features,omitempty"`
	Timestamp string            `json:"timestamp"`
}

HealthResponse represents the health check response

type ListResponse added in v1.2.0

type ListResponse struct {
	Data       interface{} `json:"data"`
	Pagination *Pagination `json:"pagination,omitempty"`
	Meta       *Meta       `json:"meta,omitempty"`
}

ListResponse wraps list data with pagination

type LoginRequest

type LoginRequest struct {
	Password string `json:"password"`
}

LoginRequest represents a login request

type LoginResponse

type LoginResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
}

LoginResponse represents a login response

type MemoryStats

type MemoryStats struct {
	Alloc      uint64 `json:"alloc_mb"`
	TotalAlloc uint64 `json:"total_alloc_mb"`
	Sys        uint64 `json:"sys_mb"`
	NumGC      uint32 `json:"num_gc"`
}

MemoryStats represents memory statistics

type Meta added in v1.2.0

type Meta struct {
	RequestID string    `json:"request_id"`
	Timestamp time.Time `json:"timestamp"`
	Version   string    `json:"version"`
}

Meta contains response metadata

type MoveRequest

type MoveRequest struct {
	ParentID *int64 `json:"parent_id"`
}

MoveRequest represents a request to move a folder

type Pagination added in v1.2.0

type Pagination struct {
	Page       int              `json:"page"`
	Limit      int              `json:"limit"`
	Total      int              `json:"total"`
	TotalPages int              `json:"totalPages"`
	Links      *PaginationLinks `json:"links,omitempty"`
}

Pagination contains pagination metadata

type PaginationLinks struct {
	Self string  `json:"self"`
	Next *string `json:"next"`
	Prev *string `json:"prev"`
}

PaginationLinks contains navigation links for paginated responses

type SettingsHandler added in v1.2.0

type SettingsHandler struct {
	// contains filtered or unexported fields
}

SettingsHandler handles settings related endpoints

func NewSettingsHandler added in v1.2.0

func NewSettingsHandler(repo *repository.SettingsRepository) *SettingsHandler

NewSettingsHandler creates a new settings handler

func (*SettingsHandler) Get added in v1.2.0

Get retrieves application settings

func (*SettingsHandler) Update added in v1.2.0

func (h *SettingsHandler) Update(w http.ResponseWriter, r *http.Request)

Update updates application settings

type SnippetHandler

type SnippetHandler struct {
	// contains filtered or unexported fields
}

SnippetHandler handles snippet-related HTTP requests

func NewSnippetHandler

func NewSnippetHandler(service *services.SnippetService) *SnippetHandler

NewSnippetHandler creates a new snippet handler

func (*SnippetHandler) Create

func (h *SnippetHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/snippets

func (*SnippetHandler) Delete

func (h *SnippetHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/snippets/{id}

func (*SnippetHandler) Duplicate

func (h *SnippetHandler) Duplicate(w http.ResponseWriter, r *http.Request)

Duplicate handles POST /api/v1/snippets/{id}/duplicate

func (*SnippetHandler) Get

Get handles GET /api/v1/snippets/{id}

func (*SnippetHandler) GetHistory added in v1.2.0

func (h *SnippetHandler) GetHistory(w http.ResponseWriter, r *http.Request)

GetHistory handles GET /api/v1/snippets/{id}/history

func (*SnippetHandler) GetPublic

func (h *SnippetHandler) GetPublic(w http.ResponseWriter, r *http.Request)

GetPublic handles GET /api/v1/snippets/public/{id}

func (*SnippetHandler) GetPublicFile added in v1.2.3

func (h *SnippetHandler) GetPublicFile(w http.ResponseWriter, r *http.Request)

GetPublicFile handles GET /api/v1/snippets/public/{id}/files/{filename} Returns raw file content for downloading individual files from public snippets

func (*SnippetHandler) List

List handles GET /api/v1/snippets

func (*SnippetHandler) Restore added in v1.3.5

func (h *SnippetHandler) Restore(w http.ResponseWriter, r *http.Request)

Restore handles POST /api/v1/snippets/{id}/restore

func (*SnippetHandler) RestoreFromHistory added in v1.2.0

func (h *SnippetHandler) RestoreFromHistory(w http.ResponseWriter, r *http.Request)

RestoreFromHistory handles POST /api/v1/snippets/{id}/history/{history_id}/restore

func (*SnippetHandler) Search

func (h *SnippetHandler) Search(w http.ResponseWriter, r *http.Request)

Search handles GET /api/v1/snippets/search

func (*SnippetHandler) ToggleArchive added in v1.2.0

func (h *SnippetHandler) ToggleArchive(w http.ResponseWriter, r *http.Request)

ToggleArchive handles POST /api/v1/snippets/{id}/archive

func (*SnippetHandler) ToggleFavorite

func (h *SnippetHandler) ToggleFavorite(w http.ResponseWriter, r *http.Request)

ToggleFavorite handles POST /api/v1/snippets/{id}/favorite

func (*SnippetHandler) Update

func (h *SnippetHandler) Update(w http.ResponseWriter, r *http.Request)

Update handles PUT /api/v1/snippets/{id}

type TagHandler

type TagHandler struct {
	// contains filtered or unexported fields
}

TagHandler handles tag-related HTTP requests

func NewTagHandler

func NewTagHandler(repo *repository.TagRepository) *TagHandler

NewTagHandler creates a new tag handler

func (*TagHandler) Create

func (h *TagHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/tags

func (*TagHandler) Delete

func (h *TagHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/tags/{id}

func (*TagHandler) Get

func (h *TagHandler) Get(w http.ResponseWriter, r *http.Request)

Get handles GET /api/v1/tags/{id}

func (*TagHandler) List

func (h *TagHandler) List(w http.ResponseWriter, r *http.Request)

List handles GET /api/v1/tags

func (*TagHandler) Update

func (h *TagHandler) Update(w http.ResponseWriter, r *http.Request)

Update handles PUT /api/v1/tags/{id}

type TokenHandler

type TokenHandler struct {
	// contains filtered or unexported fields
}

TokenHandler handles API token-related HTTP requests

func NewTokenHandler

func NewTokenHandler(repo *repository.TokenRepository, settingsRepo *repository.SettingsRepository, authService *auth.Service) *TokenHandler

NewTokenHandler creates a new token handler

func (*TokenHandler) Create

func (h *TokenHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /api/v1/tokens

func (*TokenHandler) Delete

func (h *TokenHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/tokens/{id}

func (*TokenHandler) Get

Get handles GET /api/v1/tokens/{id}

func (*TokenHandler) List

func (h *TokenHandler) List(w http.ResponseWriter, r *http.Request)

List handles GET /api/v1/tokens

func (*TokenHandler) WithDemoMode added in v1.3.3

func (h *TokenHandler) WithDemoMode(enabled bool) *TokenHandler

WithDemoMode sets the demo mode flag

Jump to

Keyboard shortcuts

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