net

package
v7.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)

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

func GRPCCallOK(err error) bool

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

func GRPCCallSuccessful(err error) bool

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

func GetLocalIPAddressString() (string, error)

GetLocalIPAddressString returns the local IP address used by Ignition Store IP() method.

func ListenAndServeGRPC

func ListenAndServeGRPC(server *grpc.Server) *bufconn.Listener

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

func WriteHTTP

func WriteHTTP(ctx context.Context, w http.ResponseWriter, m encoders.WriterEncoder, response any, status int) error

WriteHTTP writes the status and the body of an HTTP response. It writes the content of response in w using the given encoders.Marshaller.

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

func NewClient

func NewClient(caller Caller, serializer encoders.Marshaller) Client

NewClient initializes a new Client using the given Caller and encoders.Marshaller.

func (*Client) Call

func (c *Client) Call(ctx context.Context, endpoint string, in, out interface{}) error

Call calls the given endpoint with the given input as payload. If there's a response back from the endpoint, it will be stored in the output variable.

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

type Middleware func(handler http.Handler) http.Handler

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

type Option func(*Server) *Server

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

func HTTP(handler http.Handler, port uint) Option

HTTP initializes a new HTTP server to serve endpoints defined in handler on a certain port.

func ListenerTCP

func ListenerTCP(port uint) Option

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 NewServer

func NewServer(opts ...Option) *Server

NewServer initializes a new server.

func (*Server) Close

func (s *Server) Close()

Close gracefully closes all the underlying servers (HTTP & gRPC).

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() <-chan error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL