Documentation ¶
Overview ¶
Package lile provides helper methods to quickly create RPC based services that have metrics, tracing and pub/sub support
Index ¶
- func AddStreamInterceptor(sint grpc.StreamServerInterceptor)
- func AddUnaryInterceptor(unint grpc.UnaryServerInterceptor)
- func BaseCommand(serviceName, shortDescription string) *cobra.Command
- func ContextClientInterceptor() grpc.UnaryClientInterceptor
- func Name(n string)
- func NewTestServer(s *grpc.Server) (string, func())
- func RegisterHealthProbe(name string, ready func(ctx context.Context) error, ...) (started func())
- func Run() error
- func ServeGRPC(started func()) error
- func Server(r func(s *grpc.Server))
- func Shutdown()
- func TestConn(addr string) *grpc.ClientConn
- func URLForService(name string) string
- type RegisterImplementation
- type Registry
- type ServerConfig
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddStreamInterceptor ¶
func AddStreamInterceptor(sint grpc.StreamServerInterceptor)
AddStreamInterceptor adds a stream interceptor to the RPC server
func AddUnaryInterceptor ¶
func AddUnaryInterceptor(unint grpc.UnaryServerInterceptor)
AddUnaryInterceptor adds a unary interceptor to the RPC server
func BaseCommand ¶
BaseCommand provides the basic flags vars for running a service
func ContextClientInterceptor ¶
func ContextClientInterceptor() grpc.UnaryClientInterceptor
ContextClientInterceptor passes around headers for tracing and linkerd
func NewTestServer ¶
NewTestServer is a helper function to create a gRPC server on a non-network socket and it returns the socket location and a func to call which starts the server
func RegisterHealthProbe ¶
func RegisterHealthProbe(name string, ready func(ctx context.Context) error, alive func(ctx context.Context) error) (started func())
RegisterHealthProbe adds new probes to the health endpoints. Multiples can be added and the name is used to give some meaning to what's currently being probed. The ready func is use when the application gets in a state where it can't handle request but can recover. The alive func is used to determine service health, if this returns an error then it's saying that the application is in a state where it will have to be restarted. The started func is to be called when the service is has done its initial initialisation, in Kubernetes the ready and alive funcs won't be called until started as been executed.
func Run ¶
func Run() error
Run is a blocking cmd to run the gRPC and metrics server. You should listen to os signals and call Shutdown() if you want a graceful shutdown or want to handle other goroutines
func ServeGRPC ¶
func ServeGRPC(started func()) error
ServeGRPC creates and runs a blocking gRPC server
func TestConn ¶
func TestConn(addr string) *grpc.ClientConn
TestConn is a connection that connects to a socket based connection
func URLForService ¶
URLForService returns a service URL via a registry or a simple DNS name if not available via the registry
Types ¶
type RegisterImplementation ¶
RegisterImplementation allows you to register your gRPC server
type Registry ¶
type Registry interface { // Register a service Register(s *Service) error // Deregister a service DeRegister(s *Service) error // Get a service by name Get(name string) (string, error) }
Registry is the interface to implement for external registry providers
type ServerConfig ¶
ServerConfig is a generic server configuration
func (*ServerConfig) Address ¶
func (c *ServerConfig) Address() string
Address Gets a logical addr for a ServerConfig
type Service ¶
type Service struct { ID string Name string // Interceptors UnaryInts []grpc.UnaryServerInterceptor StreamInts []grpc.StreamServerInterceptor // The RPC server implementation GRPCImplementation RegisterImplementation GRPCOptions []grpc.ServerOption // gRPC and Prometheus endpoints Config ServerConfig PrometheusConfig ServerConfig // Probe server for managing health endpoints and registering new probes ProbeServer probe.Server // Registry allows Lile to work with external registries like // consul, zookeeper or similar Registry Registry // Private utils. Exposed so they can be used if needed ServiceListener net.Listener GRPCServer *grpc.Server PrometheusServer *http.Server // contains filtered or unexported fields }
Service is a gRPC based server with extra features
func NewService ¶
NewService creates a new service with a given name