Documentation ¶
Overview ¶
Package kit provides experimental packages to put together server and pubsub daemons with the following features:
* Standardized configuration and logging * Health check endpoints with configurable strategies * Configuration for managing pprof endpoints and log levels * Basic interfaces to define expectations and vocabulary * Structured logging containing basic request information * Useful metrics for endpoints * Graceful shutdowns
This is an experimental reference for creating Microservices in Go.
The rationale behind this package:
* A more opinionated server with fewer choices. * go-kit is used for serving HTTP/JSON & gRPC is used for serving HTTP2/RPC * Monitoring and metrics are handled by a sidecar (ie. Cloud Endpoints) * Logs always go to stdout/stderr * Using Go's 1.8 graceful HTTP shutdown * Services using this package are meant for deploy to GCP with GKE and Cloud Endpoints.
If you experience any issues please create an [issue](https://github.com/insighted4/insighted-go/issues).
## Examples
Several reference implementations utilizing `server` and `pubsub` are available in the [`examples`](examples/) subdirectory.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { // MaxHeaderBytes can be used to override the default of 1<<20. MaxHeaderBytes int `json:"max_header_bytes"` // ReadTimeout can be used to override the default http server timeout of 20s. // The string should be formatted like a time.Duration string. ReadTimeout time.Duration `json:"read_timeout"` // WriteTimeout can be used to override the default http server timeout of 20s. // The string should be formatted like a time.Duration string. WriteTimeout time.Duration `json:"write_timeout"` // IdleTimeout can be used to override the default http server timeout of 120s. // The string should be formatted like a time.Duration string. IdleTimeout time.Duration `json:"idle_timeout"` // ShutdownTimeout can be used to override the default http server shutdown timeout // of 5m. ShutdownTimeout time.Duration `json:"shutdown_timeout"` // HTTPPort is the port the server implementation will serve HTTP over. // The default is 8080 HTTPPort int `json:"http_port"` // RPCPort is the port the server implementation will serve RPC over. // The default is 8081. RPCPort int `json:"rpc_port"` // Enable pprof Profiling. Off by default. EnablePProf bool `json:"enable_pprof"` // LoggerHandler level (eg.: panic, fatal, error, warn, info, debug) LoggerLevel string `json:"logger_level"` // LoggerHandler format (ex.: text, json) LoggerFormat string `json:"logger_format"` }
Config holds info required to configure a server.Server.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a generic server configuration.
type HTTPEndpoint ¶
type HTTPEndpoint struct { Middleware gin.HandlerFunc Methods map[string]gin.HandlerFunc }
HTTPEndpoint encapsulates everything required to build an endpoint.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server encapsulates all logic for registering and running a server.
type Service ¶
type Service interface { // Config is the global configuration Config() Config // HTTPEndpoints default to using a JSON. HTTPHandler() http.Handler // RPCMiddleware is for any service-wide gRPC specific middleware // for easy integration with 3rd party grpc.UnaryServerInterceptors like // http://godoc.org/cloud.google.com/go/trace#Client.GRPCServerInterceptor // // If you want to apply multiple RPC middlewares, // we recommend using: // http://godoc.org/github.com/grpc-ecosystem/go-grpc-middleware#ChainUnaryServer RPCMiddleware() grpc.UnaryServerInterceptor // RPCServiceDesc allows services to declare an alternate gRPC // representation of themselves to be hosted on the RPC_PORT (8081 by default). RPCServiceDesc() *grpc.ServiceDesc // RPCOptions are for service-wide gRPC server options. // // The underlying kit server already uses the one available grpc.UnaryInterceptor // grpc.ServerOption so attempting to pass your own in this method will cause a panic // at startup. We recommend using RPCMiddleware() to fill this need. RPCOptions() []grpc.ServerOption }
Service is the interface of mixed HTTP/gRPC that can be registered and hosted by a server. Services provide hooks for service-wide options and middlewares and can be used as a means of dependency injection.
type Shutdowner ¶
type Shutdowner interface {
Shutdown()
}
Shutdowner allows your service to shutdown gracefully when http server stops. This may used when service has any background task which needs to be completed gracefully.