router

package
v0.0.0-...-9bffff5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RouteTypePrefix = "prefix"
	RouteTypeExact  = "exact"
)
View Source
const (
	SegmentsModePreserve = "preserve"
	SegmentsModeIgnore   = "ignore"
)
View Source
const (
	HandlerTypeBackend  = "backend"
	HandlerTypeRedirect = "redirect"
	HandlerTypeGone     = "gone"
)

Variables

This section is empty.

Functions

func ExportRoutes

func ExportRoutes(filePath string, logger zerolog.Logger) error

ExportRoutes queries the database and writes routes to the specified file in JSONL format

func NewAPIHandler

func NewAPIHandler(rout *Router) (api http.Handler, err error)

func RegisterMetrics

func RegisterMetrics(r prometheus.Registerer)

RegisterMetrics registers Prometheus metrics from the router module and the modules that it directly depends on. To use the default (global) registry, pass prometheus.DefaultRegisterer.

func VersionInfo

func VersionInfo() (v string)

VersionInfo returns human-readable version information in a format suitable for concatenation with other messages.

Types

type Options

type Options struct {
	BackendConnTimeout        time.Duration
	BackendHeaderTimeout      time.Duration
	Logger                    zerolog.Logger
	RouteReloadInterval       time.Duration
	EnableContentStoreUpdates bool
}

Additional configurable options

type PgxIface

type PgxIface interface {
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
}

type Route

type Route struct {
	IncomingPath *string
	RouteType    *string
	BackendID    *string
	RedirectTo   *string
	SegmentsMode *string
	SchemaName   *string
	Details      *string
}

IncomingPath is the URL path of the route (e.g. /foo) RouteType is the type of matching the route should do (exact/prefix) BackendID is the backend application (e.g. frontend, publisher etc...) RedirectTo is the redirect location for a redirect route SegmentsMode indicates whether the URL path for a redirect route should be preserved (preserve/ignore) SchemaName indicates the type of route (backend, redirect, gone) Details contains additional information about the route

type Router

type Router struct {
	ReloadChan chan bool

	Logger zerolog.Logger
	// contains filtered or unexported fields
}

Router is a wrapper around an HTTP multiplexer (trie.Mux) which retrieves its routes from a postgres database (content-store)

func NewRouter

func NewRouter(o Options) (rt *Router, err error)

Creates an instance of Router struct which: 1. Loads routes from file or content-store database 2. Sets up a channel that will be used to send reload requests 3. If enabled starts goroutine to listen for content-store updates 4. Starts goroutine to listen for reload requests

func (*Router) PeriodicRouteUpdates

func (rt *Router) PeriodicRouteUpdates()

Periodically send boolean messages (true) to Router's channel that signals it to reload routes from content-store's database.

func (*Router) ServeHTTP

func (rt *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP delegates responsibility for serving requests to the proxy mux instance for this router.

Jump to

Keyboard shortcuts

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