server

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server provides HTTP routes and webhook handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPServer added in v0.30.0

func NewHTTPServer(addr string, s *Server) *http.Server

NewHTTPServer returns the HTTP server of s on addr. When its shutdown starts, s's waits end at once (Server.EndWaits), so that shutdown does not wait for their long polls.

func ServeInBackground added in v0.30.0

func ServeInBackground(ctx context.Context, name string, srv *http.Server, exit func(code int))

ServeInBackground runs srv.ListenAndServe in the background, logging it as name, and calls exit(1) from that goroutine when it fails for any reason but shutdown. The process passes os.Exit.

func ShutdownServers added in v0.30.0

func ShutdownServers(ctx context.Context, servers ...*http.Server) error

ShutdownServers shuts every non-nil server down concurrently, within ctx, and returns their joined errors.

func StartMetricsServer added in v0.30.0

func StartMetricsServer(
	ctx context.Context, addr string, handler http.Handler, exit func(code int),
) *http.Server

StartMetricsServer serves GET /metrics from handler on addr in the background (ServeInBackground, with exit) and returns its server.

Types

type Option

type Option func(*Server)

Option configures a Server built by NewServer.

func WithMetrics

func WithMetrics(m Recorder) Option

WithMetrics records webhook deliveries in m. A nil m leaves the default, which records nothing.

func WithPreviewTTL added in v0.26.0

func WithPreviewTTL(ttl time.Duration) Option

WithPreviewTTL sets the TTL of the in-server sweep, which a preview's expiresAt adds to its updatedAt; 0, the default, omits expiresAt.

func WithReadToken added in v0.26.0

func WithReadToken(token string) Option

WithReadToken enables the GET /v1 routes with the Bearer token, besides the deploy token. An empty token leaves them to the deploy token alone.

func WithStatusToken added in v0.30.0

func WithStatusToken(token string) Option

WithStatusToken enables POST /webhooks/status, authenticated by the Bearer token; an empty token leaves the route unregistered.

type Recorder added in v0.30.0

type Recorder interface {
	WebhookDelivery(event, status string)
}

Recorder records the webhook deliveries the server answers. *metrics.Metrics implements it.

type Server

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

func NewServer

func NewServer(
	a *app.App,
	f forge.Forge,
	webhooks forge.WebhookParser,
	deployToken string,
	opts ...Option,
) *Server

NewServer returns the server of the webhooks webhooks parses, over the application services a (non-nil) and the forge f, configured by opts. The deploy API is served only when deployToken is set, and the read API when deployToken or the read token is.

func (*Server) EndWaits added in v0.26.0

func (s *Server) EndWaits()

EndWaits ends every blocked wait, which answers its current state at once, and every later one after its first evaluation. It is registered with http.Server.RegisterOnShutdown, so shutdown does not wait for long polls.

func (*Server) Handler

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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