webserver

package
v0.0.49-panic Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_webserver_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type CompletedConfig

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

func (CompletedConfig) New

func (c CompletedConfig) New(name string) (*WebServer, 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 {
	GetViper func() *viper.Viper // If set, overrides params below
	Proto    Web

	GatewayOptions []grpc.GatewayOption
	GinMiddlewares []gin.HandlerFunc

	CORS *cors.Config

	TlsConfig *tls.Config

	ServiceRegistryBackend *consul.ServiceRegister
	ServiceResolverBackend *consul.ServiceResolver

	// BindAddress is the host name to use for bind (local internet) facing URLs (e.g. Loopback)
	// Will default to a value based on secure serving info and available ipv4 IPs.
	BindAddress string
	// 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
	// ShutdownDelayDuration allows to block shutdown for some time, e.g. until endpoints pointing to this API server
	// have converged on all node. During this time, the API server keeps serving, /healthz will return 200,
	// but /readyz will return failure.
	ShutdownDelayDuration time.Duration
}

func NewConfig

func NewConfig() *Config

NewConfig returns a Config struct with the default values

func NewViperConfig added in v0.0.17

func NewViperConfig(getViper func() *viper.Viper) *Config

NewViperConfig returns a Config struct with the global viper instance key representing a sub tree of this instance. NewViperConfig is case-insensitive for a key.

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 PostStartHookFunc

type PostStartHookFunc func(ctx context.Context) 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 PostStartHookProvider

type PostStartHookProvider interface {
	PostStartHook() (string, PostStartHookFunc, error)
}

PostStartHookProvider is an interface in addition to provide a post start hook for the api server

type PreShutdownHookFunc

type PreShutdownHookFunc func() error

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

type Web added in v0.0.17

type Web struct {
	BindAddr             *Web_Net  `protobuf:"bytes,1,opt,name=bind_addr,json=bindAddr,proto3" json:"bind_addr,omitempty"`                                        // for listen
	AdvertiseAddr        *Web_Net  `protobuf:"bytes,2,opt,name=advertise_addr,json=advertiseAddr,proto3" json:"advertise_addr,omitempty"`                         // for expose
	Tls                  *Web_TLS  `protobuf:"bytes,3,opt,name=tls,proto3" json:"tls,omitempty"`                                                                  // for tls such as https
	Cors                 *Web_CORS `protobuf:"bytes,4,opt,name=cors,proto3" json:"cors,omitempty"`                                                                // for cors
	MaxConcurrencyUnary  int64     `protobuf:"varint,5,opt,name=max_concurrency_unary,json=maxConcurrencyUnary,proto3" json:"max_concurrency_unary,omitempty"`    // for concurrent parallel requests of unary server, The default is 0 (no limit is given)
	MaxConcurrencyStream int64     `protobuf:"varint,6,opt,name=max_concurrency_stream,json=maxConcurrencyStream,proto3" json:"max_concurrency_stream,omitempty"` // for concurrent parallel requests of stream server, The default is 0 (no limit is given)
	// for debug
	ForceDisableTls bool                 `protobuf:"varint,7,opt,name=force_disable_tls,json=forceDisableTls,proto3" json:"force_disable_tls,omitempty"` // disable tls
	LocalIpResolver *Web_LocalIpResolver `protobuf:"bytes,8,opt,name=local_ip_resolver,json=localIpResolver,proto3" json:"local_ip_resolver,omitempty"`  // for resolve local ip to expose, used if advertise_addr is empty
	NoGrpcProxy     bool                 `protobuf:"varint,9,opt,name=no_grpc_proxy,json=noGrpcProxy,proto3" json:"no_grpc_proxy,omitempty"`             // disable http proxy for grpc client to connect grpc server
	// contains filtered or unexported fields
}

func (*Web) Descriptor deprecated added in v0.0.17

func (*Web) Descriptor() ([]byte, []int)

Deprecated: Use Web.ProtoReflect.Descriptor instead.

func (*Web) GetAdvertiseAddr added in v0.0.17

func (x *Web) GetAdvertiseAddr() *Web_Net

func (*Web) GetBackendAdvertiseHostPort added in v0.0.17

func (web *Web) GetBackendAdvertiseHostPort() string

GetBackendAdvertiseHostPort returns a address to expose with domain, if not set, use host instead.

func (*Web) GetBackendBindHostPort added in v0.0.17

func (web *Web) GetBackendBindHostPort() string

GetBackendBindHostPort returns a address to listen.

func (*Web) GetBackendServeHostPort added in v0.0.17

func (web *Web) GetBackendServeHostPort(advertise bool) string

GetBackendServeHostPort returns a address to expose without domain, if not set, use resolver to resolve a ip

func (*Web) GetBindAddr added in v0.0.17

func (x *Web) GetBindAddr() *Web_Net

func (*Web) GetCors added in v0.0.17

func (x *Web) GetCors() *Web_CORS

func (*Web) GetForceDisableTls added in v0.0.17

func (x *Web) GetForceDisableTls() bool

func (*Web) GetLocalIpResolver added in v0.0.17

func (x *Web) GetLocalIpResolver() *Web_LocalIpResolver

func (*Web) GetMaxConcurrencyStream added in v0.0.35

func (x *Web) GetMaxConcurrencyStream() int64

func (*Web) GetMaxConcurrencyUnary added in v0.0.35

func (x *Web) GetMaxConcurrencyUnary() int64

func (*Web) GetNoGrpcProxy added in v0.0.33

func (x *Web) GetNoGrpcProxy() bool

func (*Web) GetTls added in v0.0.17

func (x *Web) GetTls() *Web_TLS

func (*Web) HTTPScheme added in v0.0.17

func (web *Web) HTTPScheme() string

func (*Web) ProtoMessage added in v0.0.17

func (*Web) ProtoMessage()

func (*Web) ProtoReflect added in v0.0.17

func (x *Web) ProtoReflect() protoreflect.Message

func (*Web) Reset added in v0.0.17

func (x *Web) Reset()

func (*Web) ResolveBackendLocalUrl added in v0.0.17

func (web *Web) ResolveBackendLocalUrl(relativePaths ...string) string

func (*Web) ResolveLocalIp added in v0.0.19

func (web *Web) ResolveLocalIp() string

func (*Web) String added in v0.0.17

func (x *Web) String() string

type WebHandler

type WebHandler interface {
	SetRoutes(ginRouter gin.IRouter, grpcRouter *grpc.Gateway)
}

type WebServer

type WebServer struct {
	Name string

	// ShutdownDelayDuration allows to block shutdown for some time, e.g. until endpoints pointing to this API server
	// have converged on all node. During this time, the API server keeps serving, /healthz will return 200,
	// but /readyz will return failure.
	ShutdownDelayDuration time.Duration
	// contains filtered or unexported fields
}

func (*WebServer) AddBootSequenceHealthChecks

func (s *WebServer) AddBootSequenceHealthChecks(checks ...healthz.HealthCheck) error

AddBootSequenceHealthChecks adds health checks to the old healthz endpoint (for backwards compatibility reasons) as well as livez and readyz. The livez grace period is defined by the value of the command-line flag --livez-grace-period; before the grace period elapses, the livez health checks will default to healthy. One may want to set a grace period in order to prevent the kubelet from restarting the kube-apiserver due to long-ish boot sequences. Readyz health checks, on the other hand, have no grace period, since readyz should fail until boot fully completes.

func (*WebServer) AddHealthChecks

func (s *WebServer) AddHealthChecks(checks ...healthz.HealthCheck) error

AddHealthChecks adds HealthCheck(s) to health endpoints (healthz, livez, readyz) but configures the liveness grace period to be zero, which means we expect this health check to immediately indicate that the apiserver is unhealthy.

func (*WebServer) AddPostStartHook

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

AddPostStartHook allows you to add a PostStartHook.

func (*WebServer) AddPostStartHookOrDie

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

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

func (*WebServer) AddPreShutdownHook

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

AddPreShutdownHook allows you to add a PreShutdownHook.

func (*WebServer) AddPreShutdownHookOrDie

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

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

func (*WebServer) InstallWebHandlers added in v0.0.17

func (s *WebServer) InstallWebHandlers(handlers ...WebHandler)

func (*WebServer) PrepareRun

func (s *WebServer) PrepareRun() (preparedWebServer, error)

PrepareRun does post API installation setup steps. It calls recursively the same function of the delegates.

func (*WebServer) RunPostStartHooks

func (s *WebServer) RunPostStartHooks(ctx context.Context)

RunPostStartHooks runs the PostStartHooks for the server

func (*WebServer) RunPreShutdownHooks

func (s *WebServer) RunPreShutdownHooks() error

RunPreShutdownHooks runs the PreShutdownHooks for the server

type Web_CORS added in v0.0.17

type Web_CORS struct {
	Enable bool `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"`
	// returns Access-Control-Allow-Origin: * if false
	UseConditional bool `protobuf:"varint,2,opt,name=use_conditional,json=useConditional,proto3" json:"use_conditional,omitempty"`
	// allowed_origins is a list of origins a cross-domain request can be executed from.
	// If the special "*" value is present in the list, all origins will be allowed.
	// An origin may contain a wildcard (*) to replace 0 or more characters
	// (i.e.: http://*.domain.com). Usage of wildcards implies a small performance penalty.
	// Only one wildcard can be used per origin.
	// Default value is ["*"]
	// return Access-Control-Allow-Origin
	AllowedOrigins []string `protobuf:"bytes,3,rep,name=allowed_origins,json=allowedOrigins,proto3" json:"allowed_origins,omitempty"`
	// allowed_methods is a list of methods the client is allowed to use with
	// cross-domain requests. Default value is simple methods (HEAD, GET and POST).
	AllowedMethods []string `protobuf:"bytes,4,rep,name=allowed_methods,json=allowedMethods,proto3" json:"allowed_methods,omitempty"`
	// allowed_headers is list of non simple headers the client is allowed to use with
	// cross-domain requests.
	// If the special "*" value is present in the list, all headers will be allowed.
	// Default value is [] but "Origin" is always appended to the list.
	AllowedHeaders []string `protobuf:"bytes,5,rep,name=allowed_headers,json=allowedHeaders,proto3" json:"allowed_headers,omitempty"`
	// exposed_headers indicates which headers are safe to expose to the API of a CORS
	// API specification
	// return Access-Control-Expose-Headers
	ExposedHeaders []string `protobuf:"bytes,6,rep,name=exposed_headers,json=exposedHeaders,proto3" json:"exposed_headers,omitempty"`
	// allow_credentials indicates whether the request can include user credentials like
	// cookies, HTTP authentication or client side SSL certificates.
	// return Access-Control-Allow-Credentials
	AllowCredentials bool `protobuf:"varint,7,opt,name=allow_credentials,json=allowCredentials,proto3" json:"allow_credentials,omitempty"`
	// options_passthrough instructs preflight to let other potential next handlers to
	// process the OPTIONS method. Turn this on if your application handles OPTIONS.
	OptionsPassthrough bool `protobuf:"varint,8,opt,name=options_passthrough,json=optionsPassthrough,proto3" json:"options_passthrough,omitempty"`
	// max_age indicates how long the results of a preflight request
	// can be cached
	MaxAge *durationpb.Duration `protobuf:"bytes,9,opt,name=max_age,json=maxAge,proto3" json:"max_age,omitempty"`
	// debug flag adds additional output to debug server side CORS issues
	Debug bool `protobuf:"varint,10,opt,name=debug,proto3" json:"debug,omitempty"`
	// contains filtered or unexported fields
}

func (*Web_CORS) Descriptor deprecated added in v0.0.17

func (*Web_CORS) Descriptor() ([]byte, []int)

Deprecated: Use Web_CORS.ProtoReflect.Descriptor instead.

func (*Web_CORS) GetAllowCredentials added in v0.0.17

func (x *Web_CORS) GetAllowCredentials() bool

func (*Web_CORS) GetAllowedHeaders added in v0.0.17

func (x *Web_CORS) GetAllowedHeaders() []string

func (*Web_CORS) GetAllowedMethods added in v0.0.17

func (x *Web_CORS) GetAllowedMethods() []string

func (*Web_CORS) GetAllowedOrigins added in v0.0.17

func (x *Web_CORS) GetAllowedOrigins() []string

func (*Web_CORS) GetDebug added in v0.0.17

func (x *Web_CORS) GetDebug() bool

func (*Web_CORS) GetEnable added in v0.0.17

func (x *Web_CORS) GetEnable() bool

func (*Web_CORS) GetExposedHeaders added in v0.0.17

func (x *Web_CORS) GetExposedHeaders() []string

func (*Web_CORS) GetMaxAge added in v0.0.17

func (x *Web_CORS) GetMaxAge() *durationpb.Duration

func (*Web_CORS) GetOptionsPassthrough added in v0.0.17

func (x *Web_CORS) GetOptionsPassthrough() bool

func (*Web_CORS) GetUseConditional added in v0.0.17

func (x *Web_CORS) GetUseConditional() bool

func (*Web_CORS) ProtoMessage added in v0.0.17

func (*Web_CORS) ProtoMessage()

func (*Web_CORS) ProtoReflect added in v0.0.17

func (x *Web_CORS) ProtoReflect() protoreflect.Message

func (*Web_CORS) Reset added in v0.0.17

func (x *Web_CORS) Reset()

func (*Web_CORS) String added in v0.0.17

func (x *Web_CORS) String() string

type Web_LocalIpResolver added in v0.0.17

type Web_LocalIpResolver struct {
	Networks  []string             `protobuf:"bytes,1,rep,name=networks,proto3" json:"networks,omitempty"`
	Addresses []string             `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"`
	Timeout   *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"`
	// contains filtered or unexported fields
}

func (*Web_LocalIpResolver) Descriptor deprecated added in v0.0.17

func (*Web_LocalIpResolver) Descriptor() ([]byte, []int)

Deprecated: Use Web_LocalIpResolver.ProtoReflect.Descriptor instead.

func (*Web_LocalIpResolver) GetAddresses added in v0.0.17

func (x *Web_LocalIpResolver) GetAddresses() []string

func (*Web_LocalIpResolver) GetNetworks added in v0.0.17

func (x *Web_LocalIpResolver) GetNetworks() []string

func (*Web_LocalIpResolver) GetTimeout added in v0.0.17

func (x *Web_LocalIpResolver) GetTimeout() *durationpb.Duration

func (*Web_LocalIpResolver) ProtoMessage added in v0.0.17

func (*Web_LocalIpResolver) ProtoMessage()

func (*Web_LocalIpResolver) ProtoReflect added in v0.0.17

func (x *Web_LocalIpResolver) ProtoReflect() protoreflect.Message

func (*Web_LocalIpResolver) Reset added in v0.0.17

func (x *Web_LocalIpResolver) Reset()

func (*Web_LocalIpResolver) String added in v0.0.17

func (x *Web_LocalIpResolver) String() string

type Web_Net added in v0.0.17

type Web_Net struct {
	Host    string   `protobuf:"bytes,1,opt,name=host,proto3" json:"host,omitempty"`
	Domains []string `protobuf:"bytes,2,rep,name=domains,proto3" json:"domains,omitempty"` // service name to register to consul for dns
	Port    int32    `protobuf:"varint,3,opt,name=port,proto3" json:"port,omitempty"`
	// contains filtered or unexported fields
}

func (*Web_Net) Descriptor deprecated added in v0.0.17

func (*Web_Net) Descriptor() ([]byte, []int)

Deprecated: Use Web_Net.ProtoReflect.Descriptor instead.

func (*Web_Net) GetDomains added in v0.0.19

func (x *Web_Net) GetDomains() []string

func (*Web_Net) GetHost added in v0.0.17

func (x *Web_Net) GetHost() string

func (*Web_Net) GetPort added in v0.0.17

func (x *Web_Net) GetPort() int32

func (*Web_Net) ProtoMessage added in v0.0.17

func (*Web_Net) ProtoMessage()

func (*Web_Net) ProtoReflect added in v0.0.17

func (x *Web_Net) ProtoReflect() protoreflect.Message

func (*Web_Net) Reset added in v0.0.17

func (x *Web_Net) Reset()

func (*Web_Net) String added in v0.0.17

func (x *Web_Net) String() string

type Web_TLS added in v0.0.17

type Web_TLS struct {
	Enable        bool             `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"`
	KeyPairBase64 *Web_TLS_KeyPair `protobuf:"bytes,2,opt,name=key_pair_base64,json=keyPairBase64,proto3" json:"key_pair_base64,omitempty"` // key pair in base64 format encoded from pem
	KeyPairPath   *Web_TLS_KeyPair `protobuf:"bytes,3,opt,name=key_pair_path,json=keyPairPath,proto3" json:"key_pair_path,omitempty"`       // key pair stored in file from pem
	// service_name is used to verify the hostname on the returned
	// certificates unless InsecureSkipVerify is given. It is also included
	// in the client's handshake to support virtual hosting unless it is
	// an IP address.
	ServiceName      string   `protobuf:"bytes,4,opt,name=service_name,json=serviceName,proto3" json:"service_name,omitempty"`
	AllowedTlsCidrs  []string `protobuf:"bytes,5,rep,name=allowed_tls_cidrs,json=allowedTlsCidrs,proto3" json:"allowed_tls_cidrs,omitempty"` //"127.0.0.1/24"
	WhitelistedPaths []string `protobuf:"bytes,6,rep,name=whitelisted_paths,json=whitelistedPaths,proto3" json:"whitelisted_paths,omitempty"`
	// contains filtered or unexported fields
}

func (*Web_TLS) Descriptor deprecated added in v0.0.17

func (*Web_TLS) Descriptor() ([]byte, []int)

Deprecated: Use Web_TLS.ProtoReflect.Descriptor instead.

func (*Web_TLS) GetAllowedTlsCidrs added in v0.0.17

func (x *Web_TLS) GetAllowedTlsCidrs() []string

func (*Web_TLS) GetEnable added in v0.0.17

func (x *Web_TLS) GetEnable() bool

func (*Web_TLS) GetKeyPairBase64 added in v0.0.17

func (x *Web_TLS) GetKeyPairBase64() *Web_TLS_KeyPair

func (*Web_TLS) GetKeyPairPath added in v0.0.17

func (x *Web_TLS) GetKeyPairPath() *Web_TLS_KeyPair

func (*Web_TLS) GetServiceName added in v0.0.17

func (x *Web_TLS) GetServiceName() string

func (*Web_TLS) GetWhitelistedPaths added in v0.0.17

func (x *Web_TLS) GetWhitelistedPaths() []string

func (*Web_TLS) ProtoMessage added in v0.0.17

func (*Web_TLS) ProtoMessage()

func (*Web_TLS) ProtoReflect added in v0.0.17

func (x *Web_TLS) ProtoReflect() protoreflect.Message

func (*Web_TLS) Reset added in v0.0.17

func (x *Web_TLS) Reset()

func (*Web_TLS) String added in v0.0.17

func (x *Web_TLS) String() string

type Web_TLS_KeyPair added in v0.0.17

type Web_TLS_KeyPair struct {
	Cert string `protobuf:"bytes,1,opt,name=cert,proto3" json:"cert,omitempty"` // public key
	Key  string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`   // private key
	// contains filtered or unexported fields
}

a public/private key pair

func (*Web_TLS_KeyPair) Descriptor deprecated added in v0.0.17

func (*Web_TLS_KeyPair) Descriptor() ([]byte, []int)

Deprecated: Use Web_TLS_KeyPair.ProtoReflect.Descriptor instead.

func (*Web_TLS_KeyPair) GetCert added in v0.0.17

func (x *Web_TLS_KeyPair) GetCert() string

func (*Web_TLS_KeyPair) GetKey added in v0.0.17

func (x *Web_TLS_KeyPair) GetKey() string

func (*Web_TLS_KeyPair) ProtoMessage added in v0.0.17

func (*Web_TLS_KeyPair) ProtoMessage()

func (*Web_TLS_KeyPair) ProtoReflect added in v0.0.17

func (x *Web_TLS_KeyPair) ProtoReflect() protoreflect.Message

func (*Web_TLS_KeyPair) Reset added in v0.0.17

func (x *Web_TLS_KeyPair) Reset()

func (*Web_TLS_KeyPair) String added in v0.0.17

func (x *Web_TLS_KeyPair) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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