micro

package module
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 22 Imported by: 1

README

micro

GoDoc Build Status codecov Release

Microservice prototype with gRPC + Restful + Redoc + Prometheus.

Require GO version >= v1.11

Documentation

Index

Constants

This section is empty.

Variables

InterruptSignals are the default interrupt signals to catch

Functions

func AllPattern added in v1.1.0

func AllPattern() runtime.Pattern

AllPattern returns a pattern which matches any url

func DefaultHTTPHandler

func DefaultHTTPHandler(mux *runtime.ServeMux) http.Handler

DefaultHTTPHandler is the default http handler which does nothing

func PathPattern added in v1.1.0

func PathPattern(path string) runtime.Pattern

PathPattern returns a pattern which matches exactly with the path

Types

type AnnotatorFunc

type AnnotatorFunc func(context.Context, *http.Request) metadata.MD

AnnotatorFunc is the annotator function is for injecting meta data from http request into gRPC context

type HTTPHandlerFunc

type HTTPHandlerFunc func(*runtime.ServeMux) http.Handler

HTTPHandlerFunc is the http middleware handler function

type Logger added in v1.1.0

type Logger interface {
	Printf(string, ...interface{})
}

Logger is logger interface

type LoggerFunc added in v1.5.0

type LoggerFunc func(string, ...interface{})

LoggerFunc is a bridge between Logger and any third party logger

func (LoggerFunc) Printf added in v1.5.0

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.ProtoErrorHandlerFunc) Option

ErrorHandler returns an Option to set the errorHandler

func GRPCDialOption added in v1.4.1

func GRPCDialOption(dialOption grpc.DialOption) Option

GRPCDialOption returns an Option to append a gRPC dial option

func GRPCServerOption added in v1.4.0

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 added in v1.2.0

func InterruptSignal(signal os.Signal) Option

InterruptSignal returns an Option to append a interrupt signal

func MuxOption added in v1.5.0

func MuxOption(muxOption runtime.ServeMuxOption) Option

MuxOption returns an Option to append a mux option

func PreShutdownDelay added in v1.2.0

func PreShutdownDelay(timeout time.Duration) Option

PreShutdownDelay returns an Option to set the time waiting for running goroutines to finish their jobs before the shutdown starts

func Redoc

func Redoc(redoc *RedocOpts) Option

Redoc returns an Option to set the Redoc

func RouteOpt added in v1.1.0

func RouteOpt(route Route) Option

RouteOpt returns an Option to append a route

func ShutdownFunc added in v1.2.0

func ShutdownFunc(f func()) Option

ShutdownFunc returns an Option to register a function which will be called when server shutdown

func ShutdownTimeout added in v1.2.0

func ShutdownTimeout(timeout time.Duration) Option

ShutdownTimeout returns an Option to set the timeout before the server shutdown abruptly

func StaticDir

func StaticDir(staticDir string) Option

StaticDir returns an Option to set the staticDir

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 added in v1.4.0

func WithHTTPServer(server *http.Server) Option

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

func WithLogger added in v1.5.0

func WithLogger(logger Logger) Option

WithLogger uses the provided logger

type RedocOpts

type RedocOpts struct {
	// Route is the route in http server, DO NOT include / at the beginning
	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) AddSpec

func (redoc *RedocOpts) AddSpec(name, url string) *RedocOpts

AddSpec adds a spec url with name

func (*RedocOpts) Serve

func (redoc *RedocOpts) Serve(w http.ResponseWriter, r *http.Request, pathParams map[string]string)

Serve is the HandlerFunc for Redoc

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 added in v1.1.0

type Route struct {
	Method  string
	Pattern runtime.Pattern
	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

func NewService

func NewService(opts ...Option) *Service

NewService creates a new microservice

func (*Service) AddRoutes added in v1.5.1

func (s *Service) AddRoutes(routes ...Route)

AddRoutes adds additional routes

func (*Service) Getpid added in v1.2.0

func (s *Service) Getpid() int

Getpid gets the process id of server

func (*Service) Start

func (s *Service) Start(httpPort uint16, grpcPort uint16, reverseProxyFunc ReverseProxyFunc) error

Start starts the microservice with listening on the ports

func (*Service) Stop

func (s *Service) Stop()

Stop stops the microservice gracefully

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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