web

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIDefaultPageSize = 50
	APIMaxPageSize     = 100
)
View Source
const (
	APIMaxSignTTLSeconds int64 = (1<<63 - 1) / int64(time.Second)
)

Variables

Functions

func AcceptsMarkdown added in v0.9.0

func AcceptsMarkdown(r *http.Request) bool

func DocToMarkdown added in v0.9.0

func DocToMarkdown(cfg *config.Config, name string, content []byte) []byte

func FileToMarkdown added in v0.9.0

func FileToMarkdown(cfg *config.Config, file *snips.File, content []byte) []byte

func HealthHandler

func HealthHandler(w http.ResponseWriter, _ *http.Request)

func Pattern

func Pattern(r *http.Request) string

func ProfileHandler

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

func ShouldSendRaw

func ShouldSendRaw(r *http.Request) bool

func UserID added in v0.13.0

func UserID(ctx context.Context) (string, bool)

UserID extracts the authenticated API user's ID from the request context, placed there by WithAuthentication, reporting whether the request was authenticated.

func WithAuthentication added in v0.13.0

func WithAuthentication(database *db.DB, next http.HandlerFunc) http.HandlerFunc

WithAuthentication authenticates a request with a bearer token.

func WithLocalhostOnly added in v0.13.0

func WithLocalhostOnly(next http.HandlerFunc) http.HandlerFunc

WithLocalhostOnly rejects requests that do not originate from a loopback address.

func WithLogger

func WithLogger(next http.Handler) http.Handler

WithLogger adds a request scoped logger to the request context.

func WithMetrics

func WithMetrics(next http.Handler) http.Handler

WithMetrics will record metrics for the request.

func WithMiddleware

func WithMiddleware(handler http.Handler, middlewares ...Middleware) http.Handler

func WithRecover

func WithRecover(next http.Handler) http.Handler

WithRecover will recover from any panics and log them.

func WithRequestID

func WithRequestID(next http.Handler) http.Handler

WithRequestID adds a unique request ID to the request context, and echoes it as a response header so clients can reference it when reporting issues.

Types

type API added in v0.13.0

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

func NewAPI added in v0.13.0

func NewAPI(cfg *config.Config, database *db.DB) *API

func (*API) CreateFile added in v0.13.0

func (a *API) CreateFile(w http.ResponseWriter, r *http.Request)

func (*API) DeleteFile added in v0.13.0

func (a *API) DeleteFile(w http.ResponseWriter, r *http.Request)

func (*API) GetFile added in v0.13.0

func (a *API) GetFile(w http.ResponseWriter, r *http.Request)

func (*API) GetFileContent added in v0.13.0

func (a *API) GetFileContent(w http.ResponseWriter, r *http.Request)

func (*API) GetRevision added in v0.13.0

func (a *API) GetRevision(w http.ResponseWriter, r *http.Request)

func (*API) ListFiles added in v0.13.0

func (a *API) ListFiles(w http.ResponseWriter, r *http.Request)

func (*API) ListRevisions added in v0.13.0

func (a *API) ListRevisions(w http.ResponseWriter, r *http.Request)

func (*API) Meta added in v0.13.0

func (a *API) Meta(w http.ResponseWriter, r *http.Request)

func (*API) OpenAPI added in v0.13.0

func (a *API) OpenAPI(w http.ResponseWriter, r *http.Request)

OpenAPI serves the specification as json or yaml, based on the extension.

func (*API) Register added in v0.13.0

func (a *API) Register(mux *http.ServeMux)

func (*API) SignFile added in v0.13.0

func (a *API) SignFile(w http.ResponseWriter, r *http.Request)

func (*API) UpdateFile added in v0.13.0

func (a *API) UpdateFile(w http.ResponseWriter, r *http.Request)

func (*API) UpdateFileContent added in v0.13.0

func (a *API) UpdateFileContent(w http.ResponseWriter, r *http.Request)

func (*API) User added in v0.13.0

func (a *API) User(w http.ResponseWriter, r *http.Request)

type Assets

type Assets interface {
	Doc(filename string) ([]byte, error)
	StaticFile(name string) ([]byte, bool)
	Template(name string) *template.Template
	Serve(w http.ResponseWriter, r *http.Request)
}

type ContextKey

type ContextKey string
const (
	RequestIDContextKey ContextKey = "request_id"
	UserIDContextKey    ContextKey = "user_id"

	RequestIDHeader = "X-Request-ID"
)

type Middleware

type Middleware func(next http.Handler) http.Handler

type Service

type Service struct {
	*http.Server
}

func New

func New(cfg *config.Config, database *db.DB, assets Assets) (*Service, error)

type StaticAssets

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

func NewAssets

func NewAssets(webFS fs.FS, docsFS fs.FS, readme []byte, extendHeadFile string) (*StaticAssets, error)

NewAssets holds the templates, static content and minifies accordingly.

func (*StaticAssets) AssetPath added in v0.8.0

func (a *StaticAssets) AssetPath(name string) string

AssetPath returns the hashed asset path for a given logical name (e.g. "index.css" → "/assets/index.a1b2c3d4.css").

func (*StaticAssets) CSS

func (a *StaticAssets) CSS() []byte

func (*StaticAssets) Doc

func (a *StaticAssets) Doc(filename string) ([]byte, error)

func (*StaticAssets) JS

func (a *StaticAssets) JS() []byte

func (*StaticAssets) README

func (a *StaticAssets) README() []byte

func (*StaticAssets) Serve

func (a *StaticAssets) Serve(w http.ResponseWriter, r *http.Request)

func (*StaticAssets) StaticFile added in v0.9.0

func (a *StaticAssets) StaticFile(name string) ([]byte, bool)

func (*StaticAssets) Template

func (a *StaticAssets) Template(name string) *template.Template

type UI added in v0.13.0

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

func NewUI added in v0.13.0

func NewUI(cfg *config.Config, database *db.DB, assets Assets) *UI

func (*UI) Doc added in v0.13.0

func (ui *UI) Doc(w http.ResponseWriter, r *http.Request)

func (*UI) DocOGImage added in v0.13.0

func (ui *UI) DocOGImage(w http.ResponseWriter, r *http.Request)

func (*UI) File added in v0.13.0

func (ui *UI) File(w http.ResponseWriter, r *http.Request)

func (*UI) Landing added in v0.13.0

func (ui *UI) Landing(w http.ResponseWriter, r *http.Request)

func (*UI) OGImage added in v0.13.0

func (ui *UI) OGImage(w http.ResponseWriter, r *http.Request)

func (*UI) Register added in v0.13.0

func (ui *UI) Register(mux *http.ServeMux)

func (*UI) RevisionDiff added in v0.13.0

func (ui *UI) RevisionDiff(w http.ResponseWriter, r *http.Request)

func (*UI) Revisions added in v0.13.0

func (ui *UI) Revisions(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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