Documentation ¶
Index ¶
- type Foundation
- func (f *Foundation) RegisterHTTPHandler(path string, fn http.HandlerFunc, methods ...string)
- func (f *Foundation) RegisterLiveness(fn func() (string, error))
- func (f *Foundation) RegisterReadiness(fn func() (string, error))
- func (f *Foundation) RegisterService(fn RegisterServiceFunc)
- func (f *Foundation) RegisterServiceHandler(fn RegisterServiceHandlerFunc, muxOpts ...runtime.ServeMuxOption)
- func (f *Foundation) Serve() error
- type FoundationOptions
- type Option
- func EnableCors() Option
- func WithCorsOptions(opts cors.Options) Option
- func WithGrpcAddr(addr string) Option
- func WithGrpcServerOptions(opts ...grpc.ServerOption) Option
- func WithHTTPAddr(addr string) Option
- func WithHTTPReadTimeout(timeout time.Duration) Option
- func WithHTTPWriteTimeout(timeout time.Duration) Option
- func WithLogger(logger *log.Logger) Option
- type RegisterServiceFunc
- type RegisterServiceHandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Foundation ¶
type Foundation struct {
// contains filtered or unexported fields
}
Foundation provides a convenient way to build new services.
Foundation aims to provide a set of common boilerplate code for creating a production ready GRPC server and HTTP mux router (with grpc-gateway capabilities) and custom HTTP endpoints.
func NewFoundation ¶
func NewFoundation(name string, options ...Option) (*Foundation, error)
NewFoundation creates a new foundation service. A list of configurable option can be passed as option and as env Variable eg:
// Setting up grpc server via option kit.NewFoundation("myservice", kit.WithGrpcAddr("localhost:8089")) // Setting up grpc server via Env FOUNDATION_GRPC_ADDRESS=localhost:8089 kit.NewFoundation("myservice")
Order of priority for option is as follows:
1- Default configuration 2- Env variable 3- Options
func (*Foundation) RegisterHTTPHandler ¶
func (f *Foundation) RegisterHTTPHandler(path string, fn http.HandlerFunc, methods ...string)
RegisterHTTPHandler registers a custom HTTP handler.
func (*Foundation) RegisterLiveness ¶
func (f *Foundation) RegisterLiveness(fn func() (string, error))
RegisterLiveness register a liveness function for /healthz
Many applications running for long periods of time eventually transition to broken states, and cannot recover except by being restarted. Kubernetes provides liveness probes to detect and remedy such situations.
func (*Foundation) RegisterReadiness ¶
func (f *Foundation) RegisterReadiness(fn func() (string, error))
RegisterReadiness register a readiness function for /readyz
Sometimes, applications are temporarily unable to serve traffic. For example, an application might need to load a large amount of data or a large number of configuration files during startup. In such instances, we don’t want to kill the application, but we don’t want to send it requests either.
func (*Foundation) RegisterService ¶
func (f *Foundation) RegisterService(fn RegisterServiceFunc)
RegisterService registers a grpc service handler.
func (*Foundation) RegisterServiceHandler ¶
func (f *Foundation) RegisterServiceHandler(fn RegisterServiceHandlerFunc, muxOpts ...runtime.ServeMuxOption)
RegisterServiceHandler registers a grpc-gateway service handler.
func (*Foundation) Serve ¶
func (f *Foundation) Serve() error
Serve configure and start serving request for the foundation service.
type FoundationOptions ¶
type FoundationOptions struct {
// contains filtered or unexported fields
}
FoundationOptions provides a set of configurable options for Foundation.
type Option ¶
type Option func(*FoundationOptions)
Option defines a Foundation option.
func WithCorsOptions ¶
WithCorsOptions defines http server cors options.
func WithGrpcAddr ¶
WithGrpcAddr defines a GRPC server host and port.
func WithGrpcServerOptions ¶
func WithGrpcServerOptions(opts ...grpc.ServerOption) Option
WithGrpcServerOptions defines GRPC server options.
func WithHTTPAddr ¶
WithHTTPAddr defines a HTTP server host and port.
func WithHTTPReadTimeout ¶
WithHTTPReadTimeout defines read timeout for the HTTP server.
func WithHTTPWriteTimeout ¶
WithHTTPWriteTimeout defines write timeout for the HTTP server.
func WithLogger ¶
type RegisterServiceFunc ¶
RegisterServiceFunc represents a function for registering a grpc service handler.
type RegisterServiceHandlerFunc ¶
type RegisterServiceHandlerFunc func(gw *runtime.ServeMux, conn *grpc.ClientConn)
RegisterServiceHandlerFunc represents a function for registering a grpc gateway service handler.
Directories ¶
Path | Synopsis |
---|---|
Package cache contains interfaces for caching data.
|
Package cache contains interfaces for caching data. |
Package config provides a simple logic that will read configuration from configmaps, io.Reader or envvar.
|
Package config provides a simple logic that will read configuration from configmaps, io.Reader or envvar. |
Package errors provides simple error handling primitives.
|
Package errors provides simple error handling primitives. |
Package grpc provides function for managing gRPC system calls (client and server).
|
Package grpc provides function for managing gRPC system calls (client and server). |
Package id is a globally unique id generator suited for web scale.
|
Package id is a globally unique id generator suited for web scale. |
Package log provides function for managing structured logs.
|
Package log provides function for managing structured logs. |
Package pagination provides functions for managing next page token pagination as well as a batcher that will dynamically batch size a list query.
|
Package pagination provides functions for managing next page token pagination as well as a batcher that will dynamically batch size a list query. |
Package pubsub contains interfaces for publishing data to queues and subscribing and consuming data from those queues.
|
Package pubsub contains interfaces for publishing data to queues and subscribing and consuming data from those queues. |
Package sql provides function for managing connection to various database.
|
Package sql provides function for managing connection to various database. |
Package telemetry provides functions for managing instrumented code and measure data about that code's performance and operation.
|
Package telemetry provides functions for managing instrumented code and measure data about that code's performance and operation. |