Documentation
¶
Index ¶
- Constants
- func AddCorsFlags(flags *pflag.FlagSet, name string)
- func AddGrpcClientFlags(flags *pflag.FlagSet, name, addr string)
- func AddListenerFlags(flags *pflag.FlagSet, name, addr string)
- type CertPoolBuilder
- func (b *CertPoolBuilder) AddExtension(value string) *CertPoolBuilder
- func (b *CertPoolBuilder) AddExtensions(values ...string) *CertPoolBuilder
- func (b *CertPoolBuilder) AddFile(value string) *CertPoolBuilder
- func (b *CertPoolBuilder) AddFiles(values ...string) *CertPoolBuilder
- func (b *CertPoolBuilder) AddKubernetesFiles(value bool) *CertPoolBuilder
- func (b *CertPoolBuilder) AddSystemFiles(value bool) *CertPoolBuilder
- func (b *CertPoolBuilder) Build() (result *x509.CertPool, err error)
- func (b *CertPoolBuilder) SetLogger(value *slog.Logger) *CertPoolBuilder
- func (b *CertPoolBuilder) SetRoot(value string) *CertPoolBuilder
- type CorsMiddlewareBuilder
- func (b *CorsMiddlewareBuilder) AddAllowedOrigins(values ...string) *CorsMiddlewareBuilder
- func (b *CorsMiddlewareBuilder) Build() (result func(http.Handler) http.Handler, err error)
- func (b *CorsMiddlewareBuilder) SetFlags(flags *pflag.FlagSet, name string) *CorsMiddlewareBuilder
- func (b *CorsMiddlewareBuilder) SetLogger(value *slog.Logger) *CorsMiddlewareBuilder
- type GrpcClientBuilder
- func (b *GrpcClientBuilder) AddStreamInterceptor(interceptor grpc.StreamClientInterceptor) *GrpcClientBuilder
- func (b *GrpcClientBuilder) AddStreamInterceptors(interceptors ...grpc.StreamClientInterceptor) *GrpcClientBuilder
- func (b *GrpcClientBuilder) AddUnaryInterceptor(interceptor grpc.UnaryClientInterceptor) *GrpcClientBuilder
- func (b *GrpcClientBuilder) AddUnaryInterceptors(interceptors ...grpc.UnaryClientInterceptor) *GrpcClientBuilder
- func (b *GrpcClientBuilder) Build() (result *grpc.ClientConn, err error)
- func (b *GrpcClientBuilder) SetAddress(value string) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetCaPool(value *x509.CertPool) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetFlags(flags *pflag.FlagSet, name string) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetHost(value string) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetInsecure(value bool) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetKeepAlive(value time.Duration) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetLogger(value *slog.Logger) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetMetricsRegisterer(value prometheus.Registerer) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetMetricsSubsystem(value string) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetNetwork(value string) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetPlaintext(value bool) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetTokenSource(value auth.TokenSource) *GrpcClientBuilder
- func (b *GrpcClientBuilder) SetUserAgent(value string) *GrpcClientBuilder
- type ListenerBuilder
- func (b *ListenerBuilder) AddTLSProtocol(value string) *ListenerBuilder
- func (b *ListenerBuilder) Build() (result net.Listener, err error)
- func (b *ListenerBuilder) SetAddress(value string) *ListenerBuilder
- func (b *ListenerBuilder) SetFlags(flags *pflag.FlagSet, name string) *ListenerBuilder
- func (b *ListenerBuilder) SetLogger(value *slog.Logger) *ListenerBuilder
- func (b *ListenerBuilder) SetNetwork(value string) *ListenerBuilder
- func (b *ListenerBuilder) SetTLSCrt(value string) *ListenerBuilder
- func (b *ListenerBuilder) SetTLSKey(value string) *ListenerBuilder
Constants ¶
const ( GrpcListenerName = "gRPC" HttpListenerName = "HTTP" MetricsListenerName = "Metrics" )
Common listener names:
const ( DefaultGrpcAddress = "localhost:8000" DefaultHttpAddress = "localhost:8001" DefaultMetricsAddress = "localhost:8002" )
Default listener addresses:
const (
GrpcClientName = "gRPC"
)
Common client names:
Variables ¶
This section is empty.
Functions ¶
func AddCorsFlags ¶
AddCorsFlags adds to the given flag set the flags needed to configure the CORS middleware. It receives the name of the listerner where the CORS support will be enabled. For example, to configure an API listener:
network.AddCorsFlags(flags, "API")
The name will be converted to lower case to generate a prefix for the flags, and will be used unchanged as a prefix for the help text. The above example will result in the following flags:
--api-cors-allowed-origins strings API CORS allowed origins. (default "*")
func AddGrpcClientFlags ¶
AddGrpcClientFlags adds to the given flag set the flags needed to configure a network client. It receives the name of the client and the default server address. For example, to configure an API client:
network.AddGrpcClientFlags(flags, "API", "localhost:8000")
The name will be converted to lower case to generate a prefix for the flags, and will be used unchanged as a prefix for the help text. The above example will result in the following flags:
--api-server-network string API server network. (default "tcp") --api-server-address string API server address. (default "localhost:8000") --api-server-plaintext API disable TLS. --api-server-insecure API disable TLS certificate validation. --api-keep-alive API keep alive interval.
func AddListenerFlags ¶
AddListenerFlags adds to the given flag set the flags needed to configure a network listener. It receives the name of the listerner and the default address. For example, to configure an API listener:
network.AddListenerFlags(flags, "API", "localhost:8000")
The name will be converted to lower case to generate a prefix for the flags, and will be used unchanged as a prefix for the help text. The above example will result in the following flags:
--api-listener-address string API listen address. (default "localhost:8000") --api-listener-network string API listen network. (default "tcp") --api-listener-tls-crt string API TLS certificate in PEM format. --api-listener-tls-key string API TLS key in PEM format.
Types ¶
type CertPoolBuilder ¶
type CertPoolBuilder struct {
// contains filtered or unexported fields
}
CertPoolBuilder contains the data and logic needed to create a certificate pool. Don't create instances of this object directly, use the NewCertPoolBuilder function instead.
func NewCertPool ¶
func NewCertPool() *CertPoolBuilder
NewCertPool creates a builder that can then used to configure and create a certificate pool.
func (*CertPoolBuilder) AddExtension ¶
func (b *CertPoolBuilder) AddExtension(value string) *CertPoolBuilder
AddExtension adds a file name extension that is allowed when loading files from directories. The default is to only load files with '.pem', '.crt' and '.cer' extesions.
func (*CertPoolBuilder) AddExtensions ¶
func (b *CertPoolBuilder) AddExtensions(values ...string) *CertPoolBuilder
AddExtensions adds file name extensions that are allowed when loading files from directories. The default is to only load files with '.pem', '.crt' and '.cer' extesions.
func (*CertPoolBuilder) AddFile ¶
func (b *CertPoolBuilder) AddFile(value string) *CertPoolBuilder
AddFile adds a file containing CA certificates to be loaded into the pool. The parameter can also be a directory, in which case all certificate files within that directory will be loaded. When a directory is specified, the loading process is recursive, meaning that all subdirectories will also be processed and their certificate files will be included in the pool.
Only files with recognized certificate extensions will be processed when loading from directories. The default extensions are .pem, .crt, and .cer, though additional extensions can be configured using AddExtension or AddExtensions methods.
func (*CertPoolBuilder) AddFiles ¶
func (b *CertPoolBuilder) AddFiles(values ...string) *CertPoolBuilder
AddFiles adds multiple files containing CA certificates to be loaded into the pool. Each parameter can be either a file or a directory. When directories are specified, all certificate files within those directories and their subdirectories will be loaded recursively.
The same file extension filtering applies as with AddFile, where only files with recognized certificate extensions are processed when loading from directories.
func (*CertPoolBuilder) AddKubernetesFiles ¶
func (b *CertPoolBuilder) AddKubernetesFiles(value bool) *CertPoolBuilder
AddKubernetesFiles adds the Kubernetes CA files to the pool. The default is to add them.
func (*CertPoolBuilder) AddSystemFiles ¶
func (b *CertPoolBuilder) AddSystemFiles(value bool) *CertPoolBuilder
AddSystemFiles adds the system files to the pool. The default is to add them.
func (*CertPoolBuilder) Build ¶
func (b *CertPoolBuilder) Build() (result *x509.CertPool, err error)
Build uses the data stored in the builder to create a new certificate pool.
func (*CertPoolBuilder) SetLogger ¶
func (b *CertPoolBuilder) SetLogger(value *slog.Logger) *CertPoolBuilder
SetLogger sets the logger that the loader will use to send messages to the log. This is mandatory.
func (*CertPoolBuilder) SetRoot ¶
func (b *CertPoolBuilder) SetRoot(value string) *CertPoolBuilder
SetRoot sets a custom root directory for resolving file paths. This method is primarily intended for unit tests where you need to simulate the presence of files (like Kubernetes certificates or custom CA files) in a controlled environment. When a root is set, all file paths (both absolute and relative) will be resolved relative to this root directory. This affects both Kubernetes certificate files and any files added via AddFile or AddFiles.
For regular use, there is typically no need to call this method as the default behavior of using paths as-is from the filesystem is appropriate for production environments.
type CorsMiddlewareBuilder ¶
type CorsMiddlewareBuilder struct {
// contains filtered or unexported fields
}
CorsMiddlewareBuilder contains the data and logic needed to create A CORS middleware. Don't create instances of this object directly, use the NewCorsMiddleware function instead.
func NewCorsMiddleware ¶
func NewCorsMiddleware() *CorsMiddlewareBuilder
NewCorsMiddleware creates a builder that can then be used to configure and create a CORS middleware.
func (*CorsMiddlewareBuilder) AddAllowedOrigins ¶
func (b *CorsMiddlewareBuilder) AddAllowedOrigins(values ...string) *CorsMiddlewareBuilder
AddAllowedOrigins adds a list of allowed origins to the CORS middleware. This is optional, and the default value is '*'.
func (*CorsMiddlewareBuilder) Build ¶
Build uses the data stored in the builder to create a new CORS middleware.
func (*CorsMiddlewareBuilder) SetFlags ¶
func (b *CorsMiddlewareBuilder) SetFlags(flags *pflag.FlagSet, name string) *CorsMiddlewareBuilder
SetFlags sets the command line flags that should be used to configure the middleware.
The name is used to select the options when there are multiple instances. For example, if it is 'API' then it will only take into accounts the flags starting with '--api'.
This is optional.
func (*CorsMiddlewareBuilder) SetLogger ¶
func (b *CorsMiddlewareBuilder) SetLogger(value *slog.Logger) *CorsMiddlewareBuilder
SetLogger sets the logger that the middleware will use to send messages to the log. This is mandatory.
type GrpcClientBuilder ¶
type GrpcClientBuilder struct {
// contains filtered or unexported fields
}
GrpcClientBuilder contains the data and logic needed to create a gRPC client. Don't create instances of this object directly, use the NewGrpcClient function instead.
func NewGrpcClient ¶
func NewGrpcClient() *GrpcClientBuilder
NewGrpcClient creates a builder that can then used to configure and create a gRPC client.
func (*GrpcClientBuilder) AddStreamInterceptor ¶
func (b *GrpcClientBuilder) AddStreamInterceptor(interceptor grpc.StreamClientInterceptor) *GrpcClientBuilder
AddStreamInterceptor adds a stream interceptor to the client.
func (*GrpcClientBuilder) AddStreamInterceptors ¶
func (b *GrpcClientBuilder) AddStreamInterceptors(interceptors ...grpc.StreamClientInterceptor) *GrpcClientBuilder
AddStreamInterceptors adds multiple stream interceptors to the client.
func (*GrpcClientBuilder) AddUnaryInterceptor ¶
func (b *GrpcClientBuilder) AddUnaryInterceptor(interceptor grpc.UnaryClientInterceptor) *GrpcClientBuilder
AddUnaryInterceptor adds a unary interceptor to the client.
func (*GrpcClientBuilder) AddUnaryInterceptors ¶
func (b *GrpcClientBuilder) AddUnaryInterceptors(interceptors ...grpc.UnaryClientInterceptor) *GrpcClientBuilder
AddUnaryInterceptors adds multiple unary interceptors to the client.
func (*GrpcClientBuilder) Build ¶
func (b *GrpcClientBuilder) Build() (result *grpc.ClientConn, err error)
Build uses the data stored in the builder to create a new network client.
func (*GrpcClientBuilder) SetAddress ¶
func (b *GrpcClientBuilder) SetAddress(value string) *GrpcClientBuilder
SetAddress sets the server address.
func (*GrpcClientBuilder) SetCaPool ¶
func (b *GrpcClientBuilder) SetCaPool(value *x509.CertPool) *GrpcClientBuilder
SetCaPool sets the certificate pool that contains the certificates of the certificate authorities that are trusted when connecting using TLS. This is optional, and the default is to use trust the certificate authorities trusted by the operating system.
func (*GrpcClientBuilder) SetFlags ¶
func (b *GrpcClientBuilder) SetFlags(flags *pflag.FlagSet, name string) *GrpcClientBuilder
SetFlags sets the command line flags that should be used to configure the client.
The name is used to select the options when there are multiple clients. For example, if it is 'API' then it will only take into accounts the flags starting with '--api'.
This is optional.
func (*GrpcClientBuilder) SetHost ¶
func (b *GrpcClientBuilder) SetHost(value string) *GrpcClientBuilder
SetHost sets the host name that the client will use for the TLS SNI extension and the HTTP Host header. This is optional, if not specified the host name from the address will be used.
func (*GrpcClientBuilder) SetInsecure ¶
func (b *GrpcClientBuilder) SetInsecure(value bool) *GrpcClientBuilder
SetInsecure when set to true configures the client for use TLS but to not verify the certificate presented by the server. This shouldn't be used in production environments. The default is false.
func (*GrpcClientBuilder) SetKeepAlive ¶
func (b *GrpcClientBuilder) SetKeepAlive(value time.Duration) *GrpcClientBuilder
SetKeepAlive sets the keep alive interval. This is optional, by default no keep alive is used.
func (*GrpcClientBuilder) SetLogger ¶
func (b *GrpcClientBuilder) SetLogger(value *slog.Logger) *GrpcClientBuilder
SetLogger sets the logger that the client will use to send messages to the log. This is mandatory.
func (*GrpcClientBuilder) SetMetricsRegisterer ¶
func (b *GrpcClientBuilder) SetMetricsRegisterer(value prometheus.Registerer) *GrpcClientBuilder
SetMetricsRegiserer sets the metrics registry that will be used for metrics. This is optional, if not specified then the default metrics registry will be used.
func (*GrpcClientBuilder) SetMetricsSubsystem ¶
func (b *GrpcClientBuilder) SetMetricsSubsystem(value string) *GrpcClientBuilder
SetMetricsSubsystem sets the subsystem that will be used for metrics. This is optional, if not specified then no metrics will be collected.
func (*GrpcClientBuilder) SetNetwork ¶
func (b *GrpcClientBuilder) SetNetwork(value string) *GrpcClientBuilder
SetNetwork sets the server network.
func (*GrpcClientBuilder) SetPlaintext ¶
func (b *GrpcClientBuilder) SetPlaintext(value bool) *GrpcClientBuilder
SetPlaintext when set to true configures the client for a server that doesn't use TLS. The default is false.
func (*GrpcClientBuilder) SetTokenSource ¶
func (b *GrpcClientBuilder) SetTokenSource(value auth.TokenSource) *GrpcClientBuilder
SetTokenSource sets the token source that the client will use to authenticate to the server. This is optional, by default no authentication credentials are sent.
func (*GrpcClientBuilder) SetUserAgent ¶
func (b *GrpcClientBuilder) SetUserAgent(value string) *GrpcClientBuilder
SetUserAgent sets the 'User-Agent' header that will be sent with every request. This is optional, by default the gRPC library will use its own user agent string.
type ListenerBuilder ¶
type ListenerBuilder struct {
// contains filtered or unexported fields
}
ListenerBuilder contains the data and logic needed to create a network listener. Don't create instances of this object directly, use the NewListener function instead.
func NewListener ¶
func NewListener() *ListenerBuilder
NewListener creates a builder that can then used to configure and create a network listener.
func (*ListenerBuilder) AddTLSProtocol ¶
func (b *ListenerBuilder) AddTLSProtocol(value string) *ListenerBuilder
AddTLSProtocol adds a protocol that will be supported during the TLS negotiation.
func (*ListenerBuilder) Build ¶
func (b *ListenerBuilder) Build() (result net.Listener, err error)
Build uses the data stored in the builder to create a new network listener.
func (*ListenerBuilder) SetAddress ¶
func (b *ListenerBuilder) SetAddress(value string) *ListenerBuilder
SetAddress sets the listen address. This is mandatory.
func (*ListenerBuilder) SetFlags ¶
func (b *ListenerBuilder) SetFlags(flags *pflag.FlagSet, name string) *ListenerBuilder
SetFlags sets the command line flags that should be used to configure the listener.
The name is used to select the options when there are multiple listeners. For example, if it is 'API' then it will only take into accounts the flags starting with '--api'.
This is optional.
func (*ListenerBuilder) SetLogger ¶
func (b *ListenerBuilder) SetLogger(value *slog.Logger) *ListenerBuilder
SetLogger sets the logger that the listener will use to send messages to the log. This is mandatory.
func (*ListenerBuilder) SetNetwork ¶
func (b *ListenerBuilder) SetNetwork(value string) *ListenerBuilder
SetNetwork sets the network. This is optional and the default is TCP.
func (*ListenerBuilder) SetTLSCrt ¶
func (b *ListenerBuilder) SetTLSCrt(value string) *ListenerBuilder
SetTLSCrt sets the file that contains the certificate file, in PEM format.
func (*ListenerBuilder) SetTLSKey ¶
func (b *ListenerBuilder) SetTLSKey(value string) *ListenerBuilder
SetTLSKey sets the file that contains the key file, in PEM format.