gogo

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

README

micro License Apache 2 Go Report Card GoDoc

GoGo micro is a set of utilities and libraries that makes it easier to write and manage microservices.

Getting started

  • Service Discovery
  • NATS
  • Health Check Scrpit
  • Examples

Service Discovery

Service discovery is used to resolve service names to NATS addresses (subject). We use Consul as our service discovery system. Install Consul

NATS

NATS is a messaging system used as internal communication of our distributed services.

Installation
# Go client
go get github.com/nats-io/nats.go

# Server
go get github.com/nats-io/gnatsd

Health Check Script

One of the primary roles of the Consul agent is management of system-level and application-level health checks. There are several different kinds of checks, see Checks Definition. The checks used in micro is Script + Interval.

Examples

Refer to nzgogo/examples directory for more details. The repo contains examples such as greeter that teach you how to write a service using micro.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewService

func NewService(n string, v string) *service

func URLToServiceName

func URLToServiceName(host string, path string) string

URLToServiceName builds the service name for a internal transport use from an URL

func URLToServiceVersion

func URLToServiceVersion(path string) string

URLToServiceVersion builds the service version for a internal transport use from an URL

Types

type HandlerWrapper

type HandlerWrapper func(router.Handler) router.Handler

HandlerWrapper wraps the HandlerFunc and returns the equivalent

type HttpHandlerFunc

type HttpHandlerFunc func(http.ResponseWriter, *http.Request)

HttpHandlerFunc represents a single method of a http handler. It's used primarily for the wrappers.

func HttpWrapperChain

func HttpWrapperChain(f HttpHandlerFunc, m ...HttpHandlerWrapper) HttpHandlerFunc

HttpWrapperChain builds the wrapper chain recursively, functions are first class

type HttpHandlerWrapper

type HttpHandlerWrapper func(HttpHandlerFunc) HttpHandlerFunc

HttpHandlerWrapper wraps the HttpHandlerFunc and returns the equivalent

type HttpResponseWrapper

type HttpResponseWrapper func(HttpResponseWriter) HttpResponseWriter

type HttpResponseWriter

type HttpResponseWriter func(http.ResponseWriter, *codec.Message)

type Option

type Option func(*Options)

func Context

func Context(c context.Context) Option

func Registry

func Registry(r registry.Registry) Option

func Router

func Router(r router.Router) Option

func Selector

func Selector(s selector.Selector) Option

func Transport

func Transport(t transport.Transport) Option

func WrapHandler

func WrapHandler(w ...HandlerWrapper) Option

WrapHandler adds a service handler Wrapper to a list of options passed into the server

func WrapRepsWriter

func WrapRepsWriter(w ...HttpResponseWrapper) Option

WrapHandler adds a service handler Wrapper to a list of options passed into the server

type Options

type Options struct {
	Transport transport.Transport
	Registry  registry.Registry
	Router    router.Router
	Context   context.Context
	Selector  selector.Selector

	//wrappers
	HdlrWrappers     []HandlerWrapper
	HttpRespWrappers []HttpResponseWrapper
}

Options of a service

type Service

type Service interface {
	Name() string
	Version() string
	ID() string
	Options() Options
	Config() map[string]string
	ServerHandler(*nats.Msg)
	ApiHandler(*nats.Msg)
	Init(...Option) error
	Run() error
	Stop() error
	Respond(*codec.Message, string) error
	Pub(string, string, *codec.Message) error
	Req(string, string, *codec.Message, transport.ResponseHandler) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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