api

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitAdminRouter

func InitAdminRouter(apiHelper Helper)

func InitAdminUI added in v0.2.7

func InitAdminUI(apiHelper Helper)

func InitHealthRoutes added in v0.3.0

func InitHealthRoutes(apiHelper Helper)

InitHealthRoutes registers the health check endpoints

func InitJQRoute added in v0.8.0

func InitJQRoute(apiHelper Helper)

InitJQRoute registers the standalone jq evaluation endpoint. It is called only when jq evaluation is enabled, so the route 404s otherwise.

func InitLoginRoute added in v0.2.11

func InitLoginRoute(apiHelper Helper, loginMode string, authURL string, jwtSecret string, tokenExpiry int64)

func InitSourcesRouter

func InitSourcesRouter(apiHelper Helper)

func InitTestRouter

func InitTestRouter(api Helper)

func LiveHandler added in v0.8.2

func LiveHandler(c context.Context, w http.ResponseWriter, r heligo.Request) (int, error)

LiveHandler handles the /live endpoint: the process is up. It deliberately keeps answering 200 while the server drains — a graceful shutdown must not look like a hung process — and it never touches the database, so a database outage cannot get the process killed.

func ReadRequest added in v0.2.6

func ReadRequest(c context.Context, w http.ResponseWriter, r heligo.Request) (records []database.Record, status int, err error)

ReadRequest reads the input data from a request and manage the preconditions. It will emit BadRequest (400), RequestEntityTooLarge (413) or UnsupportedMediaType (415) status when appropriate. Supports JSON, CSV and x-www-form-urlencoded input data.

func ReadyHandler added in v0.8.2

func ReadyHandler(apiHelper Helper) heligo.Handler

ReadyHandler returns the handler for the /ready endpoint: route traffic to this instance. It flips to 503 as soon as a shutdown begins, so load balancers deregister the instance while it is still serving, and also when the database layer cannot serve a request — an instance whose pool hands out no connection answers nothing, and saying "ready" would keep traffic on it.

func SetResponseHeaders added in v0.2.5

func SetResponseHeaders(ctx context.Context, w http.ResponseWriter, r heligo.Request, count int64) int

SetResponseHeaders sets the response headers (for now Content-Range and Content-Location). It returns a status != 0 if some contraints are not satisfied and we need to include an error status in the response (eg 416 for RequestedRangeNotSatisfiable)

func SetVerboseErrors added in v0.6.0

func SetVerboseErrors(v bool)

SetVerboseErrors controls whether full database error details are returned to clients.

func StripPrefix added in v0.2.7

func StripPrefix(r *http.Request, prefix string) *http.Request

StripPrefix returns a new request with the URL path stripped from a prefix. It returns nil if the URL path has nbot been stripped. Taken from the handler version in the standard lib: http.StripPrefix.

func TableCreateHandler

func TableCreateHandler(c context.Context, w http.ResponseWriter, r heligo.Request) (int, error)

func TableDeleteHandler

func TableDeleteHandler(c context.Context, w http.ResponseWriter, r heligo.Request) (int, error)

func TableGetHandler

func TableGetHandler(c context.Context, w http.ResponseWriter, r heligo.Request) (int, error)

func TableListHandler

func TableListHandler(c context.Context, w http.ResponseWriter, r heligo.Request) (int, error)

func TableUpdateHandler

func TableUpdateHandler(c context.Context, w http.ResponseWriter, r heligo.Request) (int, error)

func WriteBadRequest

func WriteBadRequest(w http.ResponseWriter, err error) (int, error)

WriteBadRequest writes a BadRequest or StatusRequestEntityTooLarge status

func WriteContent added in v0.2.5

func WriteContent(ctx context.Context, w http.ResponseWriter, status int, content []byte) (int, error)

WriteContent writes the response and its content type

func WriteError

func WriteError(w http.ResponseWriter, err error) (int, error)

WriteError is the more general error function, combining the previous two.

func WriteServerError

func WriteServerError(w http.ResponseWriter, err error) (int, error)

WriteServerError write a status related to a database error

Types

type AccessTokenResponse added in v0.2.11

type AccessTokenResponse struct {
	Token                string             `json:"access_token"`
	TokenType            string             `json:"token_type"` // Bearer
	ExpiresIn            int                `json:"expires_in"`
	ExpiresAt            int64              `json:"expires_at"`
	RefreshToken         string             `json:"refresh_token"`
	User                 *User              `json:"user"`
	ProviderAccessToken  string             `json:"provider_token,omitempty"`
	ProviderRefreshToken string             `json:"provider_refresh_token,omitempty"`
	WeakPassword         *WeakPasswordError `json:"weak_password,omitempty"`
}

type Credentials added in v0.2.11

type Credentials struct {
	Email    string `json:"email"`
	Phone    string `json:"phone"`
	Password string `json:"password"`
}

type Helper added in v0.2.3

type Helper interface {
	GetDBE() *database.DbEngine
	GetDatabase(context.Context, string) (*database.Database, error)
	GetMainDatabase(context.Context) (*database.Database, error)

	GetRouter() *heligo.Router
	MiddlewareStd() heligo.Middleware
	MiddlewareDBE() heligo.Middleware
	MiddlewareWithDbName(string) heligo.Middleware

	BaseAdminURL() string
	BaseAPIURL() string
	HasShortAPIURL() bool
	IsDraining() bool

	SessionStatistics() authn.SessionStatistics
}

type SmoothError added in v0.2.4

type SmoothError struct {
	Subsystem string `json:"subsystem"`
	Message   string `json:"message"`
	Code      string `json:"code"`
	Hint      string `json:"hint"`
	Details   any    `json:"details"`
	Position  int32  `json:"position"`
}

SmoothError is the generic struct for error reporting

type User added in v0.2.11

type User struct {
	Aud   string `json:"aud"`
	Role  string `json:"role"`
	Email string `json:"email"`
}

type WeakPasswordError added in v0.2.11

type WeakPasswordError struct {
	Message string   `json:"message,omitempty"`
	Reasons []string `json:"reasons,omitempty"`
}

func (*WeakPasswordError) Error added in v0.2.11

func (e *WeakPasswordError) Error() string

Jump to

Keyboard shortcuts

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