Documentation
¶
Index ¶
- Constants
- Variables
- func AcceptsMarkdown(r *http.Request) bool
- func DocToMarkdown(cfg *config.Config, name string, content []byte) []byte
- func FileToMarkdown(cfg *config.Config, file *snips.File, content []byte) []byte
- func HealthHandler(w http.ResponseWriter, _ *http.Request)
- func Pattern(r *http.Request) string
- func ProfileHandler(w http.ResponseWriter, r *http.Request)
- func ShouldSendRaw(r *http.Request) bool
- func UserID(ctx context.Context) (string, bool)
- func WithAuthentication(database *db.DB, next http.HandlerFunc) http.HandlerFunc
- func WithLocalhostOnly(next http.HandlerFunc) http.HandlerFunc
- func WithLogger(next http.Handler) http.Handler
- func WithMetrics(next http.Handler) http.Handler
- func WithMiddleware(handler http.Handler, middlewares ...Middleware) http.Handler
- func WithRecover(next http.Handler) http.Handler
- func WithRequestID(next http.Handler) http.Handler
- type API
- func (a *API) CreateFile(w http.ResponseWriter, r *http.Request)
- func (a *API) DeleteFile(w http.ResponseWriter, r *http.Request)
- func (a *API) GetFile(w http.ResponseWriter, r *http.Request)
- func (a *API) GetFileContent(w http.ResponseWriter, r *http.Request)
- func (a *API) GetRevision(w http.ResponseWriter, r *http.Request)
- func (a *API) ListFiles(w http.ResponseWriter, r *http.Request)
- func (a *API) ListRevisions(w http.ResponseWriter, r *http.Request)
- func (a *API) Meta(w http.ResponseWriter, r *http.Request)
- func (a *API) OpenAPI(w http.ResponseWriter, r *http.Request)
- func (a *API) Register(mux *http.ServeMux)
- func (a *API) SignFile(w http.ResponseWriter, r *http.Request)
- func (a *API) UpdateFile(w http.ResponseWriter, r *http.Request)
- func (a *API) UpdateFileContent(w http.ResponseWriter, r *http.Request)
- func (a *API) User(w http.ResponseWriter, r *http.Request)
- type Assets
- type ContextKey
- type Middleware
- type Service
- type StaticAssets
- func (a *StaticAssets) AssetPath(name string) string
- func (a *StaticAssets) CSS() []byte
- func (a *StaticAssets) Doc(filename string) ([]byte, error)
- func (a *StaticAssets) JS() []byte
- func (a *StaticAssets) README() []byte
- func (a *StaticAssets) Serve(w http.ResponseWriter, r *http.Request)
- func (a *StaticAssets) StaticFile(name string) ([]byte, bool)
- func (a *StaticAssets) Template(name string) *template.Template
- type UI
- func (ui *UI) Doc(w http.ResponseWriter, r *http.Request)
- func (ui *UI) DocOGImage(w http.ResponseWriter, r *http.Request)
- func (ui *UI) File(w http.ResponseWriter, r *http.Request)
- func (ui *UI) Landing(w http.ResponseWriter, r *http.Request)
- func (ui *UI) OGImage(w http.ResponseWriter, r *http.Request)
- func (ui *UI) Register(mux *http.ServeMux)
- func (ui *UI) RevisionDiff(w http.ResponseWriter, r *http.Request)
- func (ui *UI) Revisions(w http.ResponseWriter, r *http.Request)
Constants ¶
const ( APIDefaultPageSize = 50 APIMaxPageSize = 100 )
const (
APIMaxSignTTLSeconds int64 = (1<<63 - 1) / int64(time.Second)
)
Variables ¶
var DefaultMiddleware = []Middleware{ WithRecover, WithMetrics, WithLogger, WithRequestID, }
Functions ¶
func AcceptsMarkdown ¶ added in v0.9.0
func DocToMarkdown ¶ added in v0.9.0
func FileToMarkdown ¶ added in v0.9.0
func HealthHandler ¶
func HealthHandler(w http.ResponseWriter, _ *http.Request)
func ProfileHandler ¶
func ProfileHandler(w http.ResponseWriter, r *http.Request)
func ShouldSendRaw ¶
func UserID ¶ added in v0.13.0
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 ¶
WithLogger adds a request scoped logger to the request context.
func WithMetrics ¶
WithMetrics will record metrics for the request.
func WithMiddleware ¶
func WithMiddleware(handler http.Handler, middlewares ...Middleware) http.Handler
func WithRecover ¶
WithRecover will recover from any panics and log them.
Types ¶
type API ¶ added in v0.13.0
type API struct {
// contains filtered or unexported fields
}
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) 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) 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)
type ContextKey ¶
type ContextKey string
const ( RequestIDContextKey ContextKey = "request_id" UserIDContextKey ContextKey = "user_id" RequestIDHeader = "X-Request-ID" )
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) 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)
type UI ¶ added in v0.13.0
type UI struct {
// contains filtered or unexported fields
}
func (*UI) DocOGImage ¶ added in v0.13.0
func (ui *UI) DocOGImage(w http.ResponseWriter, r *http.Request)
func (*UI) RevisionDiff ¶ added in v0.13.0
func (ui *UI) RevisionDiff(w http.ResponseWriter, r *http.Request)