Documentation ¶
Index ¶
- Constants
- Variables
- func FormatBuildVersion(version string, commit string, buildTime time.Time) string
- func GetWebhookSecret(r *http.Request) string
- type Claims
- type Config
- type DB
- func (d *DB) Close() error
- func (d *DB) CreateDocument(ctx context.Context, content string, language string) (Document, error)
- func (d *DB) CreateWebhook(ctx context.Context, documentID string, url string, secret string, ...) (*Webhook, error)
- func (d *DB) DeleteDocument(ctx context.Context, documentID string) (Document, error)
- func (d *DB) DeleteDocumentByVersion(ctx context.Context, documentID string, version int64) (Document, error)
- func (d *DB) DeleteExpiredDocuments(ctx context.Context, expireAfter time.Duration) error
- func (d *DB) DeleteWebhook(ctx context.Context, documentID string, webhookID string, secret string) error
- func (d *DB) GetAndDeleteWebhooksByDocumentID(ctx context.Context, documentID string) ([]Webhook, error)
- func (d *DB) GetDocument(ctx context.Context, documentID string) (Document, error)
- func (d *DB) GetDocumentVersion(ctx context.Context, documentID string, version int64) (Document, error)
- func (d *DB) GetDocumentVersions(ctx context.Context, documentID string, withContent bool) ([]Document, error)
- func (d *DB) GetVersionCount(ctx context.Context, documentID string) (int, error)
- func (d *DB) GetWebhook(ctx context.Context, documentID string, webhookID string, secret string) (*Webhook, error)
- func (d *DB) GetWebhooksByDocumentID(ctx context.Context, documentID string) ([]Webhook, error)
- func (d *DB) UpdateDocument(ctx context.Context, documentID string, content string, language string) (Document, error)
- func (d *DB) UpdateWebhook(ctx context.Context, documentID string, webhookID string, secret string, ...) (*Webhook, error)
- type DatabaseConfig
- type DeleteResponse
- type Document
- type DocumentResponse
- type ErrorResponse
- type LogConfig
- type MetricsConfig
- type OtelConfig
- type Permission
- type PreviewConfig
- type RateLimitConfig
- type Server
- func (s *Server) Close()
- func (s *Server) DeleteDocument(w http.ResponseWriter, r *http.Request)
- func (s *Server) DeleteDocumentWebhook(w http.ResponseWriter, r *http.Request)
- func (s *Server) DocumentVersions(w http.ResponseWriter, r *http.Request)
- func (s *Server) ExecuteWebhooks(ctx context.Context, event string, document WebhookDocument)
- func (s *Server) GetDocument(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetDocumentPreview(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetDocumentWebhook(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetPrettyDocument(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetRawDocument(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetVersion(w http.ResponseWriter, _ *http.Request)
- func (s *Server) JWTMiddleware(next http.Handler) http.Handler
- func (s *Server) NewToken(documentID string, permissions []Permission) (string, error)
- func (s *Server) PatchDocument(w http.ResponseWriter, r *http.Request)
- func (s *Server) PatchDocumentWebhook(w http.ResponseWriter, r *http.Request)
- func (s *Server) PostDocument(w http.ResponseWriter, r *http.Request)
- func (s *Server) PostDocumentShare(w http.ResponseWriter, r *http.Request)
- func (s *Server) PostDocumentWebhook(w http.ResponseWriter, r *http.Request)
- func (s *Server) RateLimit(next http.Handler) http.Handler
- func (s *Server) Routes() http.Handler
- func (s *Server) Start()
- func (s *Server) StyleCSS(w http.ResponseWriter, r *http.Request)
- type ShareRequest
- type ShareResponse
- type TraceConfig
- type Webhook
- type WebhookConfig
- type WebhookCreateRequest
- type WebhookDocument
- type WebhookEventRequest
- type WebhookResponse
- type WebhookUpdate
- type WebhookUpdateRequest
Constants ¶
View Source
const ( WebhookEventUpdate string = "update" WebhookEventDelete string = "delete" )
Variables ¶
View Source
var ( ErrNoPermissions = errors.New("no permissions provided") ErrUnknownPermission = func(p Permission) error { return fmt.Errorf("unknown permission: %s", p) } ErrPermissionDenied = func(p Permission) error { return fmt.Errorf("permission denied: %s", p) } )
View Source
var ( ErrDocumentNotFound = errors.New("document not found") ErrRateLimit = errors.New("rate limit exceeded") ErrEmptyBody = errors.New("empty request body") ErrContentTooLarge = func(maxLength int) error { return fmt.Errorf("content too large, must be less than %d chars", maxLength) } )
View Source
var ( ErrWebhookNotFound = errors.New("webhook not found") ErrMissingWebhookSecret = errors.New("missing webhook secret") ErrMissingWebhookURL = errors.New("missing webhook url") ErrMissingWebhookEvents = errors.New("missing webhook events") ErrMissingURLOrSecretOrEvents = errors.New("missing url, secret or events") )
View Source
var AllPermissions = []Permission{ PermissionWrite, PermissionDelete, PermissionShare, PermissionWebhook, }
View Source
var VersionTimeFormat = "2006-01-02 15:04:05"
Functions ¶
func FormatBuildVersion ¶
func GetWebhookSecret ¶
Types ¶
type Claims ¶
type Claims struct { jwt.Claims Permissions []Permission `json:"permissions"` }
type Config ¶
type Config struct { Log LogConfig `cfg:"log"` Debug bool `cfg:"debug"` DevMode bool `cfg:"dev_mode"` ListenAddr string `cfg:"listen_addr"` HTTPTimeout time.Duration `cfg:"http_timeout"` Database DatabaseConfig `cfg:"database"` MaxDocumentSize int `cfg:"max_document_size"` MaxHighlightSize int `cfg:"max_highlight_size"` RateLimit *RateLimitConfig `cfg:"rate_limit"` JWTSecret string `cfg:"jwt_secret"` Preview *PreviewConfig `cfg:"preview"` Otel *OtelConfig `cfg:"otel"` Webhook *WebhookConfig `cfg:"webhook"` CustomStyles string `cfg:"custom_styles"` DefaultStyle string `cfg:"default_style"` }
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) CreateDocument ¶
func (*DB) CreateWebhook ¶
func (*DB) DeleteDocument ¶
func (*DB) DeleteDocumentByVersion ¶
func (*DB) DeleteExpiredDocuments ¶
func (*DB) DeleteWebhook ¶
func (*DB) GetAndDeleteWebhooksByDocumentID ¶
func (*DB) GetDocument ¶
func (*DB) GetDocumentVersion ¶
func (*DB) GetDocumentVersions ¶
func (*DB) GetVersionCount ¶
func (*DB) GetWebhook ¶
func (*DB) GetWebhooksByDocumentID ¶
func (*DB) UpdateDocument ¶
type DatabaseConfig ¶
type DatabaseConfig struct { Type string `cfg:"type"` Debug bool `cfg:"debug"` ExpireAfter time.Duration `cfg:"expire_after"` CleanupInterval time.Duration `cfg:"cleanup_interval"` // SQLite Path string `cfg:"path"` // PostgreSQL Host string `cfg:"host"` Port int `cfg:"port"` Username string `cfg:"username"` Password string `cfg:"password"` Database string `cfg:"database"` SSLMode string `cfg:"ssl_mode"` }
func (DatabaseConfig) PostgresDataSourceName ¶
func (c DatabaseConfig) PostgresDataSourceName() string
func (DatabaseConfig) String ¶
func (c DatabaseConfig) String() string
type DeleteResponse ¶
type DeleteResponse struct {
Versions int `json:"versions"`
}
type DocumentResponse ¶
type DocumentResponse struct { Key string `json:"key,omitempty"` Version int64 `json:"version"` VersionLabel string `json:"version_label,omitempty"` VersionTime string `json:"version_time,omitempty"` Data string `json:"data,omitempty"` Formatted string `json:"formatted,omitempty"` CSS string `json:"css,omitempty"` ThemeCSS string `json:"theme_css,omitempty"` Language string `json:"language"` Token string `json:"token,omitempty"` }
type ErrorResponse ¶
type LogConfig ¶
type MetricsConfig ¶
type MetricsConfig struct {
ListenAddr string `cfg:"listen_addr"`
}
func (MetricsConfig) String ¶
func (c MetricsConfig) String() string
type OtelConfig ¶
type OtelConfig struct { InstanceID string `cfg:"instance_id"` Trace *TraceConfig `cfg:"trace"` Metrics *MetricsConfig `cfg:"metrics"` }
func (OtelConfig) String ¶
func (c OtelConfig) String() string
type Permission ¶
type Permission string
const ( PermissionWrite Permission = "write" PermissionDelete Permission = "delete" PermissionWebhook Permission = "webhook" )
func (Permission) IsValid ¶
func (p Permission) IsValid() bool
type PreviewConfig ¶
type PreviewConfig struct { InkscapePath string `cfg:"inkscape_path"` MaxLines int `cfg:"max_lines"` DPI int `cfg:"dpi"` CacheSize int `cfg:"cache_size"` CacheTTL time.Duration `cfg:"cache_ttl"` }
func (PreviewConfig) String ¶
func (c PreviewConfig) String() string
type RateLimitConfig ¶
type RateLimitConfig struct { Requests int `cfg:"requests"` Duration time.Duration `cfg:"duration"` Whitelist []string `cfg:"whitelist"` Blacklist []string `cfg:"blacklist"` }
func (RateLimitConfig) String ¶
func (c RateLimitConfig) String() string
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) DeleteDocument ¶
func (s *Server) DeleteDocument(w http.ResponseWriter, r *http.Request)
func (*Server) DeleteDocumentWebhook ¶
func (s *Server) DeleteDocumentWebhook(w http.ResponseWriter, r *http.Request)
func (*Server) DocumentVersions ¶
func (s *Server) DocumentVersions(w http.ResponseWriter, r *http.Request)
func (*Server) ExecuteWebhooks ¶
func (s *Server) ExecuteWebhooks(ctx context.Context, event string, document WebhookDocument)
func (*Server) GetDocument ¶
func (s *Server) GetDocument(w http.ResponseWriter, r *http.Request)
func (*Server) GetDocumentPreview ¶
func (s *Server) GetDocumentPreview(w http.ResponseWriter, r *http.Request)
func (*Server) GetDocumentWebhook ¶
func (s *Server) GetDocumentWebhook(w http.ResponseWriter, r *http.Request)
func (*Server) GetPrettyDocument ¶
func (s *Server) GetPrettyDocument(w http.ResponseWriter, r *http.Request)
func (*Server) GetRawDocument ¶
func (s *Server) GetRawDocument(w http.ResponseWriter, r *http.Request)
func (*Server) GetVersion ¶
func (s *Server) GetVersion(w http.ResponseWriter, _ *http.Request)
func (*Server) NewToken ¶
func (s *Server) NewToken(documentID string, permissions []Permission) (string, error)
func (*Server) PatchDocument ¶
func (s *Server) PatchDocument(w http.ResponseWriter, r *http.Request)
func (*Server) PatchDocumentWebhook ¶
func (s *Server) PatchDocumentWebhook(w http.ResponseWriter, r *http.Request)
func (*Server) PostDocument ¶
func (s *Server) PostDocument(w http.ResponseWriter, r *http.Request)
func (*Server) PostDocumentShare ¶
func (s *Server) PostDocumentShare(w http.ResponseWriter, r *http.Request)
func (*Server) PostDocumentWebhook ¶
func (s *Server) PostDocumentWebhook(w http.ResponseWriter, r *http.Request)
type ShareRequest ¶
type ShareRequest struct {
}type ShareResponse ¶
type ShareResponse struct {
}type TraceConfig ¶
func (TraceConfig) String ¶
func (c TraceConfig) String() string
type WebhookConfig ¶
type WebhookConfig struct { Timeout time.Duration `cfg:"timeout"` MaxTries int `cfg:"max_tries"` Backoff time.Duration `cfg:"backoff"` BackoffFactor float64 `cfg:"backoff_factor"` MaxBackoff time.Duration `cfg:"max_backoff"` }
func (WebhookConfig) String ¶
func (c WebhookConfig) String() string
type WebhookCreateRequest ¶
type WebhookDocument ¶
type WebhookEventRequest ¶
type WebhookEventRequest struct { WebhookID string `json:"webhook_id"` Event string `json:"event"` CreatedAt time.Time `json:"created_at"` Document WebhookDocument `json:"document"` }
type WebhookResponse ¶
type WebhookUpdate ¶
type WebhookUpdateRequest ¶
Click to show internal directories.
Click to hide internal directories.