rest

package
v0.0.0-...-1185af5 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package rest provides a wrapper around of mux service (rest grpc) implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerPathFunc

type HandlerPathFunc func(mux *runtime.ServeMux) error

HandlerPathFunc allows users to configure custom path handlers for mux service.

type HandlerPathOption

type HandlerPathOption struct {
	// Method is the http method used in the route/path.
	Method string
	// PathPattern the http route path.
	PathPattern string
	// Handler is what to do when the request fulfill the method and path pattern.
	Handler func(w http.ResponseWriter, r *http.Request, _ map[string]string)
}

HandlerPathOption allows users to configure custom path handlers. The struct is used along with HandlerPathFunc when configuring custom path handlers for the mux service.

type InitRESTServiceConfig

type InitRESTServiceConfig struct {
	Listener         net.Listener
	Service          ServiceServer
	UInterceptor     []grpc.UnaryServerInterceptor
	Handlers         []HandlerPathOption
	Options          []Option
	ResponseModifier func(context.Context, http.ResponseWriter, proto.Message) error
}

InitRESTServiceConfig REST server init configuration.

type Option

type Option func(mux *Server)

Option sets up a server mux.

func WithAddrAssigned

func WithAddrAssigned() Option

WithAddrAssigned sets service to ask for listener assigned address. Mainly used when the port to the listener is assigned dynamically.

func WithAddress

func WithAddress(addr string) Option

WithAddress sets server address.

func WithHandlerPathOption

func WithHandlerPathOption(opts ...HandlerPathFunc) Option

WithHandlerPathOption sets the options for custom path handlers to the mux server.

func WithListener

func WithListener(l net.Listener, shouldCloseListener bool) Option

WithListener sets the listener. Server does not need to start a new one.

func WithPort

func WithPort(port int) Option

WithPort sets server address port.

func WithServerMuxOption

func WithServerMuxOption(opts ...runtime.ServeMuxOption) Option

WithServerMuxOption sets the options for the mux server.

func WithService

func WithService(s ServiceServer) Option

WithService registers a service.

type Server

type Server struct {
	AddrAssigned chan string
	// contains filtered or unexported fields
}

Server is a wrapper around runtime.Server.

func InitRESTService

func InitRESTService(
	ctx context.Context,
	cfg InitRESTServiceConfig,
) (*Server, error)

InitRESTService initialize an instance of REST service based on the GRPC service.

func NewServer

func NewServer(ctx context.Context, opts ...Option) (*Server, error)

NewServer initiates a new wrapped mux server.

func (*Server) Addr

func (s *Server) Addr() string

Addr service address.

func (*Server) Listener

func (s *Server) Listener() net.Listener

Listener returns the listener.

func (*Server) Name

func (s *Server) Name() string

Name Service name.

func (*Server) Start

func (s *Server) Start() error

Start begins listening and serving.

func (*Server) WithShutdownSignal

func (s *Server) WithShutdownSignal(shutdown <-chan struct{}, done chan<- struct{}) servicing.Service

WithShutdownSignal adds channels to wait for shutdown and to report shutdown finished.

type ServiceHandlerServerFunc

type ServiceHandlerServerFunc func(mux *runtime.ServeMux) error

ServiceHandlerServerFunc is the function to register the http handlers for service to "mux".

type ServiceServer

type ServiceServer interface {
	RegisterHandlerService(mux *runtime.ServeMux) error
	WithUnaryServerInterceptor(i grpc.UnaryServerInterceptor) ServiceServer
}

ServiceServer is an interface for a server that provides services.

Jump to

Keyboard shortcuts

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