net

package
v1.0.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: Apache-2.0 Imports: 24 Imported by: 2

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

Functions

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 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 GetLocalIPAddressString

func GetLocalIPAddressString() (string, error)

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

func NewRouter

func NewRouter() chi.Router

NewRouter initializes a new HTTP router using chi. It also loads middlewares used on every incoming HTTP request.

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 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), opts []grpc.ServerOption) 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 options are passed as a function in order to inject custom middlewares to the gRPC server. DefaultServerOptionsGRPC contains a set of basic middlewares to use in any application, but we encourage you to create or extend your own opts function.

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 Ignition Robotics 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