gateway

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 79 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConfigNotFound is returned when the configuration is not found.
	ErrConfigNotFound = errors.New("config not found")
	// ErrAlreadyExists is returned when a resource already exists.
	ErrAlreadyExists = errors.New("already exists")
	// ErrNoLiveUpstream is returned when no live upstreams are available.
	ErrNoLiveUpstream = errors.New("no live upstreams while connecting to upstream")
)

Functions

func NewStdlibServer added in v0.9.0

func NewStdlibServer(
	h *server.Hertz,
	options *config.ServerOptions,
	tlsConfig *tls.Config,
	tracers []tracer.Tracer,
) *http.Server

NewStdlibServer creates a new http.Server that wraps a Hertz instance for HTTP/2 support. Pass the same tracers that are registered with the Hertz server so that accesslog and metrics are triggered correctly for HTTP/2 (gRPC) requests.

func Run

func Run(mainOptions config.Options) (err error)

Run starts the bifrost server with the given options.

mainOptions is the configuration for the bifrost server. err is the error that occurred during the startup process.

func SetBifrost

func SetBifrost(bifrost *Bifrost)

SetBifrost sets the current instance of Bifrost. It stores the given Bifrost instance in the defaultBifrost atomic value. This function is used to set the Bifrost instance after it has been created. It is typically called by the top-level application code to initialize the Bifrost instance.

Types

type AbortMiddleware added in v0.6.0

type AbortMiddleware struct{}

AbortMiddleware is a middleware that aborts the request.

func (*AbortMiddleware) ServeHTTP added in v0.6.0

func (m *AbortMiddleware) ServeHTTP(_ context.Context, c *app.RequestContext)

type Bifrost

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

Bifrost is the main gateway engine.

func GetBifrost

func GetBifrost() *Bifrost

GetBifrost retrieves the current instance of Bifrost. It returns a pointer to the Bifrost instance stored in the defaultBifrost atomic value.

func NewBifrost

func NewBifrost(mainOptions config.Options, mode BifrostMode) (bifrost *Bifrost, err error)

NewBifrost creates a new instance of Bifrost.

It takes in two parameters: mainOptions of type config.Options and isReload of type bool. The mainOptions parameter contains the main configuration options for the Bifrost instance. The isReload parameter indicates whether the function is being called during a reload operation. The function returns a pointer to Bifrost and an error.

func (*Bifrost) Close added in v0.9.0

func (b *Bifrost) Close() error

Close releases resources used by Bifrost.

func (*Bifrost) IsActive

func (b *Bifrost) IsActive() bool

IsActive returns whether the Bifrost is active or not. It returns true if the Bifrost is active, false otherwise.

func (*Bifrost) Run

func (b *Bifrost) Run()

Run starts all HTTP servers in the Bifrost instance. The last server is started in the current goroutine, and the function will block until the last server stops. The other servers are started in separate goroutines.

func (*Bifrost) Service

func (b *Bifrost) Service(serviceID string) (*Service, bool)

Service retrieves a service by its ID from the Bifrost instance. It returns a pointer to the Service and a boolean indicating whether the service was found. If the serviceID does not exist, the returned Service pointer will be nil and the boolean will be false.

func (*Bifrost) SetActive

func (b *Bifrost) SetActive(status BifrostStatus)

SetActive sets whether the Bifrost is active or not.

func (*Bifrost) Shutdown

func (b *Bifrost) Shutdown(ctx context.Context) error

Shutdown shuts down all HTTP servers in the Bifrost instance gracefully. It blocks until all servers finish their shutdown process. The function returns an error if any server fails to shut down.

func (*Bifrost) ShutdownNow

func (b *Bifrost) ShutdownNow(ctx context.Context) error

ShutdownNow shuts down all servers immediately.

func (*Bifrost) ZeroDownTime

func (b *Bifrost) ZeroDownTime() *infra.ZeroDownTime

ZeroDownTime returns the zero-downtime runtime manager.

type BifrostMode added in v0.10.0

type BifrostMode int

BifrostMode defines whether Bifrost is starting normally or reloading.

const (
	// ModeNormal represents a normal startup.
	ModeNormal BifrostMode = iota
	// ModeReload represents a reload operation.
	ModeReload
)

type BifrostStatus added in v0.10.0

type BifrostStatus int

BifrostStatus defines whether the Bifrost is active or not.

const (
	// StatusInactive represents an inactive state.
	StatusInactive BifrostStatus = iota
	// StatusActive represents an active state.
	StatusActive
)

type DynamicService

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

DynamicService handles requests for services determined dynamically at runtime.

func (*DynamicService) ServeHTTP

func (s *DynamicService) ServeHTTP(ctx context.Context, c *app.RequestContext)

type Engine

type Engine struct {
	ID string
	// contains filtered or unexported fields
}

Engine handles request processing and middleware execution.

func (*Engine) OnShutdown

func (e *Engine) OnShutdown()

OnShutdown is called when the engine is shutting down.

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(ctx context.Context, c *app.RequestContext)

func (*Engine) Use

func (e *Engine) Use(middlewares ...app.HandlerFunc)

Use adds middlewares to the engine.

type FirstRouteMiddleware added in v0.2.0

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

FirstRouteMiddleware is a middleware that sets the initial route information.

func (*FirstRouteMiddleware) ServeHTTP added in v0.2.0

type HTTPServer

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

HTTPServer represents an HTTP server instance in the gateway.

func (*HTTPServer) Bind

func (s *HTTPServer) Bind() string

Bind returns the address the server is bound to.

func (*HTTPServer) Engine

func (s *HTTPServer) Engine() *Engine

Engine returns the current request processing engine.

func (*HTTPServer) Run

func (s *HTTPServer) Run()

Run starts the HTTP server and blocks until it stops.

func (*HTTPServer) SetEngine

func (s *HTTPServer) SetEngine(engine *Engine)

SetEngine updates the request processing engine for the server.

func (*HTTPServer) Shutdown

func (s *HTTPServer) Shutdown(ctx context.Context) error

Shutdown stops the HTTP server gracefully.

type HertzBridge added in v0.9.0

type HertzBridge struct {
	Hertz *server.Hertz
	// contains filtered or unexported fields
}

HertzBridge implements http.Handler by bridging to a Hertz instance. When tracers are registered it also drives the Hertz tracer pipeline so that accesslog and Prometheus metrics work correctly for HTTP/2 (gRPC) requests.

func (*HertzBridge) ServeHTTP added in v0.9.0

func (b *HertzBridge) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ListenerMode added in v0.10.0

type ListenerMode int

ListenerMode defines whether the server should listen on a network port.

const (
	// ListenerEnabled indicates the server should listen on the configured address.
	ListenerEnabled ListenerMode = iota
	// ListenerDisabled indicates the server should not open a listener.
	ListenerDisabled
)

type ResolverDiscovery added in v0.4.0

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

ResolverDiscovery implements service discovery using the internal resolver.

func NewResolverDiscovery added in v0.4.0

func NewResolverDiscovery(upstream *Upstream) *ResolverDiscovery

NewResolverDiscovery creates a new ResolverDiscovery instance.

func (*ResolverDiscovery) Close added in v0.9.0

func (d *ResolverDiscovery) Close() error

Close releases resources used by ResolverDiscovery.

func (*ResolverDiscovery) GetInstances added in v0.4.0

GetInstances resolves upstream targets using DNS and returns a list of instances.

func (*ResolverDiscovery) Watch added in v0.4.0

Watch is not supported by ResolverDiscovery and returns an error.

type Routes

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

Routes manages the routing logic, including exact, prefix, and regex matching.

func (*Routes) Add

func (r *Routes) Add(routeOpts config.RouteOptions, middlewares ...app.HandlerFunc) error

Add adds a new route.

func (*Routes) ServeHTTP

func (r *Routes) ServeHTTP(c context.Context, ctx *app.RequestContext)

ServeHTTP implements the http.Handler interface.

type Service

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

Service represents a backend service that can have multiple upstreams and middlewares.

func (*Service) Close added in v0.9.0

func (s *Service) Close() error

Close releases resources used by the service and its upstreams.

func (*Service) Middlewares

func (s *Service) Middlewares() []app.HandlerFunc

Middlewares returns the list of middlewares associated with this service.

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(ctx context.Context, c *app.RequestContext)

func (*Service) Upstream added in v0.7.0

func (s *Service) Upstream() *Upstream

Upstream returns the primary upstream associated with this service.

type ShutdownMode added in v0.10.0

type ShutdownMode int

ShutdownMode defines whether to shutdown gracefully or immediately.

const (
	// ShutdownGraceful represents a graceful shutdown.
	ShutdownGraceful ShutdownMode = iota
	// ShutdownImmediate represents an immediate shutdown.
	ShutdownImmediate
)

type TracingMiddleware added in v0.2.0

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

TracingMiddleware handles OpenTelemetry tracing for requests.

func (*TracingMiddleware) ServeHTTP added in v0.2.0

func (m *TracingMiddleware) ServeHTTP(ctx context.Context, c *app.RequestContext)

type Upstream

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

Upstream represents a collection of backend targets and a load balancer.

func (*Upstream) Balancer added in v0.6.0

func (u *Upstream) Balancer() balancer.Balancer

Balancer returns the current load balancer for the upstream.

func (*Upstream) Close added in v0.9.0

func (u *Upstream) Close() error

Close stops watching for updates and closes all associated proxies and discovery resources.

Jump to

Keyboard shortcuts

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