Documentation
¶
Overview ¶
Package grpcserver provides API to grpc server with graceful shutdown.
Typical usage:
grpcserver.New( httpserver.WithName("my-server"), httpserver.WithAddress("127.0.0.1:8080"), httpserver.WithRegisterFn(func(s *grpc.Server) { // Register your service here }), ).Run(ctx)
Index ¶
Constants ¶
const ( // DefAddress is the default server's address that will be listened to. DefAddress = "127.0.0.1:50051" // DefName is the default server's name. DefName = "grpc-server" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config structure with server configuration. Shouldn't be created manually.
type ConfigService ¶
ConfigService interface used to obtain configuration from somewhere into some specific structure.
type Option ¶
Option function that is fed to New and MustNew. Obtain them using 'With' functions down below.
func WithAddress ¶
WithAddress option applies provided address that will be listened to. Default: "127.0.0.1:50051".
func WithConfig ¶
func WithConfig(service ConfigService, key string) Option
WithConfig option retrieves configuration from provided configuration service.
Example JSON configuration with all possible fields (if some are not present, defaults will be used):
{ "name": "server-name", "address": "127.0.0.1:50051" }
func WithLogger ¶
WithLogger option applies provided logger. Default: standard logger with name equal to server's one.
func WithRegisterFn ¶
func WithRegisterFn(registerFn RegisterFn) Option
WithRegisterFn option applies provided register function.
type RegisterFn ¶
RegisterFn callback function that is called before listening in order to register any user-defined grpc service.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server structure that provides grpc server functionality. Don't create manually, use the functions down below instead.