gobin

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WebhookEventUpdate string = "update"
	WebhookEventDelete string = "delete"
)

Variables

View Source
var (
	ErrInvalidMultipartPartName   = errors.New("invalid multipart part name")
	ErrInvalidDocumentFileName    = errors.New("invalid document file name")
	ErrInvalidDocumentFileContent = errors.New("invalid document file content")
	ErrDuplicateDocumentFileNames = errors.New("duplicate document file names")
)
View Source
var (
	ErrNoPermissions     = errors.New("no permissions provided")
	ErrUnknownPermission = func(p string) error {
		return fmt.Errorf("unknown permission: %s", p)
	}
	ErrPermissionDenied = func(p string) error {
		return fmt.Errorf("permission denied: %s", p)
	}
)
View Source
var (
	ErrDocumentNotFound       = errors.New("document not found")
	ErrDocumentFileNotFound   = errors.New("document file not found")
	ErrInvalidDocumentVersion = errors.New("document version is invalid")
	ErrPreviewsDisabled       = errors.New("document previews disabled")
	ErrRateLimit              = errors.New("rate limit exceeded")
	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 AllStringPermissions = []string{"write", "delete", "share", "webhook"}
View Source
var VersionTimeFormat = "2006-01-02 15:04:05"

Functions

func FormatBuildVersion

func FormatBuildVersion(version string, commit string, buildTime time.Time) string

func GetWebhookSecret

func GetWebhookSecret(r *http.Request) string

func SetClaims

func SetClaims(r *http.Request, claims Claims) *http.Request

Types

type Claims

type Claims struct {
	jwt.Claims
	Permissions Permissions `json:"pms"`
}

func EmptyClaims

func EmptyClaims(documentID string) Claims

func GetClaims

func GetClaims(r *http.Request) Claims

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         database.Config  `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"`
}

func (Config) String

func (c Config) String() string

type DeleteResponse

type DeleteResponse struct {
	Versions int `json:"versions"`
}

type DocumentResponse

type DocumentResponse struct {
	Key          string         `json:"key"`
	Version      int64          `json:"version"`
	VersionLabel string         `json:"version_label,omitempty"`
	VersionTime  string         `json:"version_time,omitempty"`
	Files        []ResponseFile `json:"files"`
	Token        string         `json:"token,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	Message   string `json:"message"`
	Status    int    `json:"status"`
	Path      string `json:"path"`
	RequestID string `json:"request_id"`
}

type LogConfig

type LogConfig struct {
	Level     slog.Level `cfg:"level"`
	Format    string     `cfg:"format"`
	AddSource bool       `cfg:"add_source"`
	NoColor   bool       `cfg:"no_color"`
}

func (LogConfig) String

func (c LogConfig) String() string

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 Permissions

type Permissions int
const (
	PermissionWrite Permissions = 1 << iota
	PermissionDelete
	PermissionShare
	PermissionWebhook
)

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 RequestFile

type RequestFile struct {
	Name     string
	Content  string
	Language string
}

type ResponseFile

type ResponseFile struct {
	Name      string `json:"name"`
	Content   string `json:"content,omitempty"`
	Formatted string `json:"formatted,omitempty"`
	Language  string `json:"language"`
}

type Server

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

func NewServer

func NewServer(version string, debug bool, cfg Config, db *database.DB, signer jose.Signer, tracer trace.Tracer, meter metric.Meter, assets http.FileSystem, htmlFormatter *html.Formatter, standaloneHTMLFormatter *html.Formatter) *Server

func (*Server) Close

func (s *Server) Close()

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) GetDocumentFile

func (s *Server) GetDocumentFile(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) GetRawDocumentFile

func (s *Server) GetRawDocumentFile(w http.ResponseWriter, r *http.Request)

func (*Server) GetVersion

func (s *Server) GetVersion(w http.ResponseWriter, _ *http.Request)

func (*Server) JWTMiddleware

func (s *Server) JWTMiddleware(next http.Handler) http.Handler

func (*Server) NewToken

func (s *Server) NewToken(documentID string, permissions Permissions) (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)

func (*Server) RateLimit

func (s *Server) RateLimit(next http.Handler) http.Handler

func (*Server) Routes

func (s *Server) Routes() http.Handler

func (*Server) Start

func (s *Server) Start()

func (*Server) ThemeCSS

func (s *Server) ThemeCSS(w http.ResponseWriter, r *http.Request)

type ShareRequest

type ShareRequest struct {
	Permissions []string `json:"permissions"`
}

type ShareResponse

type ShareResponse struct {
	Token string `json:"token"`
}

type TraceConfig

type TraceConfig struct {
	Endpoint string `cfg:"endpoint"`
	Insecure bool   `cfg:"insecure"`
}

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 WebhookCreateRequest struct {
	URL    string   `json:"url"`
	Secret string   `json:"secret"`
	Events []string `json:"events"`
}

type WebhookDocument

type WebhookDocument struct {
	Key     string                `json:"key"`
	Version int64                 `json:"version"`
	Files   []WebhookDocumentFile `json:"files"`
}

type WebhookDocumentFile

type WebhookDocumentFile struct {
	Name     string `json:"name"`
	Content  string `json:"content"`
	Language string `json:"language"`
}

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 WebhookResponse struct {
	ID          string   `json:"id"`
	DocumentKey string   `json:"document_key"`
	URL         string   `json:"url"`
	Secret      string   `json:"secret"`
	Events      []string `json:"events"`
}

type WebhookUpdateRequest

type WebhookUpdateRequest struct {
	URL    string   `json:"url"`
	Secret string   `json:"secret"`
	Events []string `json:"events"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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