Documentation
¶
Index ¶
- Variables
- func DefaultHTTPHandler(mux *runtime.ServeMux) http.Handler
- type AnnotatorFunc
- type HTTPHandlerFunc
- type Logger
- type LoggerFunc
- type Option
- func Annotator(annotator AnnotatorFunc) Option
- func ErrorHandler(errorHandler runtime.ErrorHandlerFunc) Option
- func GRPCDialOption(dialOption grpc.DialOption) Option
- func GRPCServerOption(serverOption grpc.ServerOption) Option
- func HTTPHandler(httpHandler HTTPHandlerFunc) Option
- func InterruptSignal(signal os.Signal) Option
- func MuxOption(muxOption runtime.ServeMuxOption) Option
- func PreShutdownDelay(timeout time.Duration) Option
- func Redoc(redoc *RedocOpts) Option
- func RouteOpt(route Route) Option
- func ShutdownFunc(f func()) Option
- func ShutdownTimeout(timeout time.Duration) Option
- func StaticDir(staticDir string) Option
- func StreamInterceptor(streamInterceptor grpc.StreamServerInterceptor) Option
- func UnaryInterceptor(unaryInterceptor grpc.UnaryServerInterceptor) Option
- func WithHTTPServer(server *http.Server) Option
- func WithLogger(logger Logger) Option
- type RedocOpts
- type ReverseProxyFunc
- type Route
- type Service
- func (s *Service) AddRoutes(routes ...Route)
- func (s *Service) Getpid() int
- func (s *Service) HasRoute(route Route) bool
- func (s *Service) ServeFile(w http.ResponseWriter, r *http.Request, pathParams map[string]string)
- func (s *Service) Start(httpPort uint, grpcPort uint, reverseProxyFunc ReverseProxyFunc) error
- func (s *Service) Stop()
Constants ¶
This section is empty.
Variables ¶
var InterruptSignals = []os.Signal{ syscall.SIGSTOP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, }
InterruptSignals are the default interrupt signals to catch
Functions ¶
Types ¶
type AnnotatorFunc ¶
AnnotatorFunc is the annotator function is for injecting meta data from http request into gRPC context
type HTTPHandlerFunc ¶
HTTPHandlerFunc is the http middleware handler function
type LoggerFunc ¶
type LoggerFunc func(string, ...interface{})
LoggerFunc is a bridge between Logger and any third party logger
func (LoggerFunc) Printf ¶
func (f LoggerFunc) Printf(msg string, args ...interface{})
Printf implements Logger interface
type Option ¶
type Option func(s *Service)
Option is service functional option
See this post about the "functional options" pattern: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
func Annotator ¶
func Annotator(annotator AnnotatorFunc) Option
Annotator returns an Option to append an annotator
func ErrorHandler ¶
func ErrorHandler(errorHandler runtime.ErrorHandlerFunc) Option
ErrorHandler returns an Option to set the errorHandler
func GRPCDialOption ¶
func GRPCDialOption(dialOption grpc.DialOption) Option
GRPCDialOption returns an Option to append a gRPC dial option
func GRPCServerOption ¶
func GRPCServerOption(serverOption grpc.ServerOption) Option
GRPCServerOption returns an Option to append a gRPC server option
func HTTPHandler ¶
func HTTPHandler(httpHandler HTTPHandlerFunc) Option
HTTPHandler returns an Option to set the httpHandler
func InterruptSignal ¶
InterruptSignal returns an Option to append a interrupt signal
func MuxOption ¶
func MuxOption(muxOption runtime.ServeMuxOption) Option
MuxOption returns an Option to append a mux option
func PreShutdownDelay ¶
PreShutdownDelay returns an Option to set the time waiting for running goroutines to finish their jobs before the shutdown starts
func ShutdownFunc ¶
func ShutdownFunc(f func()) Option
ShutdownFunc returns an Option to register a function which will be called when server shutdown
func ShutdownTimeout ¶
ShutdownTimeout returns an Option to set the timeout before the server shutdown abruptly
func StreamInterceptor ¶
func StreamInterceptor(streamInterceptor grpc.StreamServerInterceptor) Option
StreamInterceptor returns an Option to append an streamInterceptor
func UnaryInterceptor ¶
func UnaryInterceptor(unaryInterceptor grpc.UnaryServerInterceptor) Option
UnaryInterceptor returns an Option to append an unaryInterceptor
func WithHTTPServer ¶
WithHTTPServer returns an Option to set the http server, note that the Addr and Handler will be reset in startGRPCGateway(), so you are not able to specify them
type RedocOpts ¶
type RedocOpts struct { // Route is the route in http server, should include / at the beginning, default is /docs. // Currently it can not be root route "/", see https://github.com/grpc-ecosystem/grpc-gateway/issues/1909 Route string // SpecURLs are the urls to find the spec for, format: name -> url SpecURLs map[string]string // RedocURL is the js that generates the redoc site, defaults to: https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js RedocURL string // Title is the page title, default to: API documentation Title string // Up is whether to boot up the redoc endpoints Up bool }
RedocOpts is configures for redoc
func (*RedocOpts) EnsureDefaults ¶ added in v2.1.3
func (redoc *RedocOpts) EnsureDefaults()
EnsureDefaults sets default redoc options
type ReverseProxyFunc ¶
type ReverseProxyFunc func(ctx context.Context, mux *runtime.ServeMux, grpcHostAndPort string, opts []grpc.DialOption) error
ReverseProxyFunc is the callback that the caller should implement to steps to reverse-proxy the HTTP/1 requests to gRPC
type Route ¶
type Route struct { Method string Path string Handler runtime.HandlerFunc }
Route represents the route for mux
type Service ¶
type Service struct { GRPCServer *grpc.Server HTTPServer *http.Server // contains filtered or unexported fields }
Service represents the microservice