Documentation ¶
Index ¶
- Variables
- func ConnectToGRPCServer(listener *bufconn.Listener) (*grpc.ClientConn, error)
- func DefaultServerOptionsGRPC() []grpc.ServerOption
- func DefaultStreamInterceptorsGRPC() []grpc.StreamServerInterceptor
- func DefaultUnaryInterceptorsGRPC() []grpc.UnaryServerInterceptor
- func GRPCCallOK(err error) bool
- func GRPCCallSuccessful(err error) bool
- func GenerateStreamServerInterceptorsChainWithBase(interceptors ...grpc.StreamServerInterceptor) grpc.ServerOption
- func GenerateUnaryServerInterceptorsChainWithBase(interceptors ...grpc.UnaryServerInterceptor) grpc.ServerOption
- func GetLocalIPAddressString() (string, error)
- func ListenAndServeGRPC(server *grpc.Server) *bufconn.Listener
- func NewRouter(middlewares ...Middleware) chi.Router
- func NewServerOptionsGRPC(streams []grpc.StreamServerInterceptor, unaries []grpc.UnaryServerInterceptor) []grpc.ServerOption
- func WriteHTTP(ctx context.Context, w http.ResponseWriter, m encoders.WriterEncoder, ...) error
- type Caller
- type Client
- type EndpointHTTP
- type Middleware
- type Option
- type RoutesGetter
- type Server
- type ServiceRegistrator
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilValuesIO is returned when either the input or the output are nil. ErrNilValuesIO = errors.New("nil input or output values") // ErrOutputMustBePointer is returned if the output is not a pointer. ErrOutputMustBePointer = errors.New("output must be a pointer") )
var DefaultMiddlewares = []Middleware{ middleware.RequestID, middleware.RealIP, middleware.Logger, middleware.Recoverer, render.SetContentType(render.ContentTypeJSON), }
DefaultMiddlewares groups a set of middlewares used across different services.
Functions ¶
func ConnectToGRPCServer ¶
func ConnectToGRPCServer(listener *bufconn.Listener) (*grpc.ClientConn, error)
ConnectToGRPCServer connects to a gRPC server and returns the established connection. The returned connection should be used to instance a service client.
func DefaultServerOptionsGRPC ¶
func DefaultServerOptionsGRPC() []grpc.ServerOption
DefaultServerOptionsGRPC is a predefined set of gRPC server options that can be used by any Server when calling the GRPC function. We encourage you to create or extend your own opts function taking this one as a starting point.
func DefaultStreamInterceptorsGRPC ¶
func DefaultStreamInterceptorsGRPC() []grpc.StreamServerInterceptor
DefaultStreamInterceptorsGRPC defines the base streams interceptors we usually use for our gRPC servers.
func DefaultUnaryInterceptorsGRPC ¶
func DefaultUnaryInterceptorsGRPC() []grpc.UnaryServerInterceptor
DefaultUnaryInterceptorsGRPC defines the base streams interceptors we usually use for our gRPC servers.
func GRPCCallOK ¶
GRPCCallOK processes a gRPC response error to verify that a gRPC call returned an OK status. The actual contents of the error are ignored. Only the call status error is checked.
func GRPCCallSuccessful ¶
GRPCCallSuccessful processes a gRPC response error to verify that a gRPC call returned an OK or Unknown status. The actual contents of the error are ignored. Only the call status error is checked.
gRPC method implementations that return anything other than a *Status value as their error value (e.g. an error generated with errors.New()) will have the value wrapped inside a *Status value and its error code set to Unknown.
This function considers calls with statuses with unknown errors successful. In addition, if the error value is not of type *Status, then the call is considered successful.
func GenerateStreamServerInterceptorsChainWithBase ¶
func GenerateStreamServerInterceptorsChainWithBase(interceptors ...grpc.StreamServerInterceptor) grpc.ServerOption
GenerateStreamServerInterceptorsChainWithBase appends the given interceptors to the base interceptors defined in DefaultStreamInterceptorsGRPC.
func GenerateUnaryServerInterceptorsChainWithBase ¶
func GenerateUnaryServerInterceptorsChainWithBase(interceptors ...grpc.UnaryServerInterceptor) grpc.ServerOption
GenerateUnaryServerInterceptorsChainWithBase appends the given interceptors to the base interceptors defined in DefaultUnaryInterceptorsGRPC.
func GetLocalIPAddressString ¶
GetLocalIPAddressString returns the local IP address used by Ignition Store IP() method.
func ListenAndServeGRPC ¶
ListenAndServeGRPC receives a configured gRPC server and starts listening. This function does not block. You should have called the appropriate gRPC server configuration function before calling this. After calling this function, you should call `server.Stop()` when done with the server.
func NewRouter ¶
func NewRouter(middlewares ...Middleware) chi.Router
NewRouter initializes a new HTTP router using chi. It also loads middlewares used on every incoming HTTP request.
func NewServerOptionsGRPC ¶
func NewServerOptionsGRPC(streams []grpc.StreamServerInterceptor, unaries []grpc.UnaryServerInterceptor) []grpc.ServerOption
NewServerOptionsGRPC initializes a new set of ServerOption with the given streams and unaries interceptors. Calling this function already uses
Types ¶
type Caller ¶
type Caller interface { // Call establishes a communication with the given endpoint, sending the input bytes as payload. // If there is any response, it will be returned as a slice of bytes. // Implementations should expect to receive the target service endpoint name through the `endpoint` parameter. Call(ctx context.Context, endpoint string, in []byte) ([]byte, error) }
Caller calls external service endpoints.
func NewCallerHTTP ¶
func NewCallerHTTP(baseURL *url.URL, endpoints map[string]EndpointHTTP, timeout time.Duration) Caller
NewCallerHTTP initializes a new HTTP Caller.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a generic wrapper for creating API clients with different encodings and transport layers
type EndpointHTTP ¶
type EndpointHTTP struct { // Method is the HTTP verb supported by this endpoint. Method string // Path is the relative path where this endpoint is located. // Example: /example/test Path string }
EndpointHTTP represents an HTTP endpoint.
type Middleware ¶
Middleware is function that gets executed before each HTTP handler. It's useful for adding request-specific logic to every request like logging and setting request id.
type Option ¶
Option contains logic that can be passed to a server in its initializer to modify it.
func GRPC ¶
func GRPC(register func(s grpc.ServiceRegistrar), streams []grpc.StreamServerInterceptor, unaries []grpc.UnaryServerInterceptor) Option
GRPC initializes and adds a new gRPC server to the Server. Multiple gRPC servers use the same ListenerTCP. ListenerTCP is required if this Option is passed. A set of gRPC interceptors for streams and unaries are passed as arguments in order to inject custom middlewares to the gRPC server. When calling this function, a set of default interceptors are already added to the gRPC server. Please check the NewServerOptionsGRPC implementation.
func HTTP ¶
HTTP initializes a new HTTP server to serve endpoints defined in handler on a certain port.
func ListenerTCP ¶
ListenerTCP initializes a new Listener for server. This Option is required for GRPC servers when registered in Server.
type RoutesGetter ¶
type RoutesGetter interface { // Routes returns a set of routes in a http.Handler form. Routes() http.Handler }
RoutesGetter holds a method to get routes.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a web server to listen to incoming requests. It supports different types of transport mechanisms used through Gazebo projects. It currently supports HTTP and gRPC servers.
func (*Server) Close ¶
func (s *Server) Close()
Close gracefully closes all the underlying servers (HTTP & gRPC).
func (*Server) ListenAndServe ¶
ListenAndServe starts listening for incoming requests for the different HTTP and gRPC servers. Returns a channel that will receive an error from any of the current underlying transport mechanisms. Each underlying server will be launched in a different go routine.
type ServiceRegistrator ¶
type ServiceRegistrator interface { // Register registers the current service into the given server. Register(s grpc.ServiceRegistrar) }
ServiceRegistrator registers a gRPC service in a gRPC server.