server

package
v0.0.0-...-d691e2b Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBuildHandlerChain

func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) http.Handler

DefaultBuildHandlerChain xxx

func RunServer

func RunServer(server *http.Server, ln net.Listener, shutDownTimeout time.Duration, stopCh <-chan struct{}) error

RunServer listens on the given port if listener is not given, then spawns a go-routine continuously serving until the stopCh is closed. This function does not block.

func SetupSignalHandler

func SetupSignalHandler() <-chan struct{}

SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned which is closed on one of these signals. If a second signal is caught, the program is terminated with exit code 1.

func WrapRestFilterFunction

func WrapRestFilterFunction(h func(c *Context, chain *restful.FilterChain)) restful.FilterFunction

func WrapRestRouteFunc

func WrapRestRouteFunc(h func(*Context)) restful.RouteFunction

Types

type BuildHandlerChainFunc

type BuildHandlerChainFunc func(apiHandler http.Handler, c *Config) http.Handler

BuildHandlerChainFunc is a type for functions that build handler chain

type CompletedConfig

type CompletedConfig struct {
	*Config
}

CompletedConfig xxx

func (CompletedConfig) New

func (c CompletedConfig) New(name string) (*GenericServer, error)

New creates a new server which logically combines the handling chain with the passed server. name is used to differentiate for logging. The handler chain in particular can be difficult as it starts delgating.

type Config

type Config struct {
	// SecureServingInfo is required to serve https
	SecureServingInfo *SecureServingInfo

	EnableProfiling bool
	// Requires generic profiling enabled
	EnableContentionProfiling bool
	EnableMetrics             bool
	SummaryOverheadMs         int

	// Version will enable the /version endpoint if non-nil
	Version *version.Version

	// ExternalAddress is the host name to use for external (public internet) facing URLs (e.g. Swagger)
	// Will default to a value based on secure serving info and available ipv4 IPs.
	ExternalAddress string

	// HandlerChainWaitGroup allows you to wait for all chain handlers exit after the server shutdown.
	HandlerChainWaitGroup *waitgroup.SafeWaitGroup

	// The default set of healthz checks. There might be more added via AddHealthzChecks dynamically.
	HealthzChecks []healthz.HealthzChecker

	// BuildHandlerChainFunc allows you to build custom handler chains by decorating the apiHandler.
	BuildHandlerChainFunc func(apiHandler http.Handler, c *Config) http.Handler

	// If specified, all requests except those which match the LongRunningFunc predicate will timeout
	// after this duration.
	RequestTimeout time.Duration

	// MaxRequestsInFlight is the maximum number of parallel non-long-running requests. Every further
	// request has to wait. Applies only to non-mutating requests.
	MaxRequestsInFlight int
}

Config is a structure used to configure a GenericAPIServer. Its members are sorted roughly in order of importance for composers.

func NewConfig

func NewConfig() *Config

NewConfig returns a Config struct with the default values

func (*Config) Complete

func (c *Config) Complete() CompletedConfig

Complete fills in any fields not set that are required to have valid data and can be derived from other fields. If you're going to `ApplyOptions`, do that first. It's mutating the receiver.

type Context

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

Context represents the context of the current HTTP request. It holds request and response objects, path, path parameters, data and registered handler.

func BuildContext

func BuildContext(request *restful.Request, response *restful.Response) *Context

BuildContext xxx

func (*Context) HTTPRequest

func (c *Context) HTTPRequest() *http.Request

func (*Context) Logger

func (c *Context) Logger() *logs.Logger

func (*Context) Request

func (c *Context) Request() *restful.Request

func (*Context) RequestID

func (c *Context) RequestID() string

func (*Context) Response

func (c *Context) Response() *restful.Response

func (*Context) WithErrorLog

func (c *Context) WithErrorLog(e error) innerErr.FinalError

func (*Context) WithWarnLog

func (c *Context) WithWarnLog(e error) innerErr.FinalError

type GenericServer

type GenericServer struct {
	// ShutdownTimeout is the timeout used for server shutdown. This specifies the timeout before server
	// gracefully shutdown returns.
	ShutdownTimeout time.Duration

	SecureServingInfo *SecureServingInfo

	// ExternalAddress is the address (hostname or IP and port) that should be used in
	// external (public internet) URLs for this GenericAPIServer.
	ExternalAddress string

	// Handler holds the handlers being used by this API server
	Handler *ServerHandler

	// HandlerChainWaitGroup allows you to wait for all chain handlers finish after the server shutdown.
	HandlerChainWaitGroup *utilwaitgroup.SafeWaitGroup
	// contains filtered or unexported fields
}

GenericServer contains state for a faas api server.

func (*GenericServer) AddHealthzChecks

func (s *GenericServer) AddHealthzChecks(checks ...healthz.HealthzChecker) error

AddHealthzChecks allows you to add a HealthzCheck.

func (*GenericServer) AddPostStartHook

func (s *GenericServer) AddPostStartHook(name string, hook PostStartHookFunc) error

AddPostStartHook allows you to add a PostStartHook.

func (*GenericServer) AddPostStartHookOrDie

func (s *GenericServer) AddPostStartHookOrDie(name string, hook PostStartHookFunc)

AddPostStartHookOrDie allows you to add a PostStartHook, but dies on failure

func (*GenericServer) AddPreShutdownHook

func (s *GenericServer) AddPreShutdownHook(name string, hook PreShutdownHookFunc) error

AddPreShutdownHook allows you to add a PreShutdownHook.

func (*GenericServer) AddPreShutdownHookOrDie

func (s *GenericServer) AddPreShutdownHookOrDie(name string, hook PreShutdownHookFunc)

AddPreShutdownHookOrDie allows you to add a PostStartHook, but dies on failure

func (*GenericServer) PrepareRun

func (s *GenericServer) PrepareRun() preparedGenericServer

PrepareRun does post API installation setup steps.

func (*GenericServer) RunPostStartHooks

func (s *GenericServer) RunPostStartHooks(stopCh <-chan struct{})

RunPostStartHooks runs the PostStartHooks for the server

func (*GenericServer) RunPreShutdownHooks

func (s *GenericServer) RunPreShutdownHooks() error

RunPreShutdownHooks runs the PreShutdownHooks for the server

type HandlerChainBuilderFn

type HandlerChainBuilderFn func(apiHandler http.Handler) http.Handler

HandlerChainBuilderFn is used to wrap the GoRestfulContainer handler using the provided handler chain. It is normally used to apply filtering like authentication and authorization

type PostStartHookContext

type PostStartHookContext struct {
	// LoopbackClientConfig is a config for a privileged loopback connection to the API server
	// LoopbackClientConfig *restclient.Config
	// StopCh is the channel that will be closed when the server stops
	StopCh <-chan struct{}
}

PostStartHookContext provides information about this API server to a PostStartHookFunc

type PostStartHookFunc

type PostStartHookFunc func(context PostStartHookContext) error

PostStartHookFunc is a function that is called after the server has started. It must properly handle cases like:

  1. asynchronous start in multiple API server processes
  2. conflicts between the different processes all trying to perform the same action
  3. partially complete work (API server crashes while running your hook)
  4. API server access **BEFORE** your hook has completed

Think of it like a mini-controller that is super privileged and gets to run in-process If you use this feature, tag @deads2k on github who has promised to review code for anyone's PostStartHook until it becomes easier to use.

type PreShutdownHookFunc

type PreShutdownHookFunc func() error

PreShutdownHookFunc is a function that can be added to the shutdown logic.

type RecommendedConfig

type RecommendedConfig struct {
	Config
}

func NewRecommendedConfig

func NewRecommendedConfig() *RecommendedConfig

NewRecommendedConfig returns a RecommendedConfig struct with the default values

type SecureServingInfo

type SecureServingInfo struct {
	// Listener is the secure server network listener.
	Listener net.Listener
}

SecureServingInfo xxx

type ServerHandler

type ServerHandler struct {
	// FullHandlerChain is the one that is eventually served with.  It should include the full filter
	// chain and then call the Director.
	FullHandlerChain http.Handler

	// The registered APIs.  InstallAPIs uses this.  Other servers probably shouldn't access this directly.
	GoRestfulContainer *restful.Container

	// NonGoRestfulMux is the final HTTP handler in the chain.
	// It comes after all filters and the API handling
	// This is where other servers can attach handler to various parts of the chain.
	NonGoRestfulMux *mux.PathRecorderMux

	// Director is here so that we can properly handle fall through and proxy cases.
	Director http.Handler
}

ServerHandler holds the different http.Handlers used by the API server. This includes the full handler chain, the director (which chooses between gorestful and nonGoRestful, the gorestful handler (used for the API) which falls through to the nonGoRestful handler on unregistered paths, and the nonGoRestful handler (which can contain a fallthrough of its own) FullHandlerChain -> Director -> {GoRestfulContainer,NonGoRestfulMux} based on inspection of registered web services

func NewServerHandler

func NewServerHandler(name string, handlerChainBuilder HandlerChainBuilderFn, notFoundHandler http.Handler) *ServerHandler

NewServerHandler xxx

func (*ServerHandler) ServeHTTP

func (s *ServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP makes it an http.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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