Documentation ¶
Index ¶
- func DefaultHeaderMatcher() runtime.ServeMuxOption
- func HeaderMatcher(keys []string) runtime.ServeMuxOption
- func ListenAndServe(services ...Service) error
- func ListenAndServeContext(ctx context.Context, services ...Service) error
- type Authenticator
- type Config
- type EndpointService
- type Option
- func AddressFromEnv() Option
- func HealthChecks(checks ...health.CheckFunc) Option
- func JWTAuth(secret string) Option
- func Logger(logger log.Logger) Option
- func MetricsPaths(ready, live, metrics string) Option
- func Options(serverOpts ...grpc.ServerOption) Option
- func ServeMuxOptions(muxOpts ...runtime.ServeMuxOption) Option
- func StreamInterceptors(interceptors ...grpc.StreamServerInterceptor) Option
- func TLS(key, cert string) Option
- func Timeout(read, write time.Duration) Option
- func UnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) Option
- type Server
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultHeaderMatcher ¶
func DefaultHeaderMatcher() runtime.ServeMuxOption
DefaultHeaderMatcher return a ServerMuxOption that forward header keys request-id, api-key to GRPC Context.
func HeaderMatcher ¶
func HeaderMatcher(keys []string) runtime.ServeMuxOption
HeaderMatcher return a serveMuxOption for matcher header for passing a set of non IANA headers to GRPC context without a need to prefix them with Grpc-Metadata.
func ListenAndServe ¶
ListenAndServe create a new server base on environment configuration and serve the services with background context. See server.ListenAndServe for detail document.
Types ¶
type Authenticator ¶
Authenticator defines the interface to perform the actual authentication of the request. Implementations should fetch the required data from the context.Context object. GRPC specific data like `metadata` and `peer` is available on the context. Should return a new `context.Context` that is a child of `ctx` or `codes.Unauthenticated` when auth is lacking or `codes.PermissionDenied` when lacking permissions.
type Config ¶
type Config struct { Name string `envconfig:"NAME" default:"micro"` Address string `envconfig:"ADDRESS" default:":8000"` TLSCertFile string `envconfig:"TLS_CERT_FILE"` TLSKeyFile string `envconfig:"TLS_KEY_FILE"` // Paths LivenessPath string `envconfig:"LIVENESS_PATH" default:"/internal/liveness"` ReadinessPath string `envconfig:"READINESS_PATH" default:"/internal/readiness"` MetricsPath string `envconfig:"METRICS_PATH" default:"/internal/metrics"` // HTTP ReadTimeout time.Duration `envconfig:"READ_TIMEOUT" default:"30s"` WriteTimeout time.Duration `envconfig:"WRITE_TIMEOUT" default:"30s"` JWTSecret string `envconfig:"JWT_SECRET"` ContextLogger bool `envconfig:"CONTEXT_LOGGER" default:"true"` }
Config is a common configuration of a default server. Mostly used by lazy guys via NewFromEnv().
type EndpointService ¶
type EndpointService interface {
RegisterWithEndpoint(ctx context.Context, mux *runtime.ServeMux, addr string, opts []grpc.DialOption)
}
EndpointService implement an endpoint registration interface for service to attach their endpoint to GRPC gateway
type Option ¶
type Option func(*Server)
Option is a configuration option.
func AddressFromEnv ¶ added in v0.0.2
func AddressFromEnv() Option
AddressFromEnv is an option to get address from environment configuration. It looks for PORT and then ADDRESS variables. This option is mostly used for cloud environment like Heroku where the port is randomly set.
func HealthChecks ¶
HealthChecks is an option allow set health check function.
func MetricsPaths ¶
MetricsPaths is an option allow override readiness, liveness and metrics path.
func Options ¶
func Options(serverOpts ...grpc.ServerOption) Option
Options is an option allow add additional grpc.ServerOption.
func ServeMuxOptions ¶
func ServeMuxOptions(muxOpts ...runtime.ServeMuxOption) Option
ServeMuxOptions is an option allow add additional ServeMuxOption.
func StreamInterceptors ¶
func StreamInterceptors(interceptors ...grpc.StreamServerInterceptor) Option
StreamInterceptors is an option allows add additional stream interceptors to the server.
func UnaryInterceptors ¶
func UnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) Option
UnaryInterceptors is an option allows add additional unary interceptors to the server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds the configuration options for the server instance.
func NewFromEnv ¶
func NewFromEnv() *Server
NewFromEnv load configurations from environment and create a new server. Additional options can be added to the sever via Server.WithOptions(...). See Config for environment names.
func (*Server) ListenAndServe ¶
ListenAndServe call ListenAndServeContext with background context.
func (*Server) ListenAndServeContext ¶
ListenAndServeContext opens a tcp listener used by a grpc.Server and a HTTP server, and registers each Service with the grpc.Server. If the Service implements EndpointService its endpoints will be registered to the HTTP Server running on the same port. The server starts with default metrics and health endpoints. If the context is canceled or times out, the GRPC server will attempt a graceful shutdown.
func (*Server) WithOptions ¶
WithOptions allows add more options to the server after created.