plugin

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

README

Plugins License GoDoc Travis CI Go Report Card

Go plugins is a place for community maintained plugins.

Overview

Micro tooling is built on a powerful pluggable architecture. Plugins can be swapped out with zero code changes. This repository contains plugins for all micro related tools. Read on for further info.

Check out the Micro on NATS blog post to learn more about plugins.

Follow us on Twitter or join the Slack community.

Getting Started

Contents

Contents of this repository:

Directory Description
Broker PubSub messaging; NATS, NSQ, RabbitMQ, Kafka
Client RPC Clients; gRPC, HTTP
Codec Message Encoding; BSON, Mercury
Micro Micro Toolkit Plugins
Registry Service Discovery; Etcd, Gossip, NATS
Selector Load balancing; Label, Cache, Static
Server RPC Servers; gRPC, HTTP
Transport Bidirectional Streaming; NATS, RabbitMQ
Wrapper Middleware; Circuit Breakers, Rate Limiting, Tracing, Monitoring

Usage

Plugins can be added to go-micro in the following ways. By doing so they'll be available to set via command line args or environment variables.

Import the plugins in a Go program then call service.Init to parse the command line and environment variables.

import (
	"github.com/micro/go-micro"
	_ "github.com/micro/go-plugins/broker/rabbitmq"
	_ "github.com/micro/go-plugins/registry/kubernetes"
	_ "github.com/micro/go-plugins/transport/nats"
)

func main() {
	service := micro.NewService(
		// Set service name
		micro.Name("my.service"),
	)

	// Parse CLI flags
	service.Init()
}
Flags

Specify the plugins as flags

go run service.go --broker=rabbitmq --registry=kubernetes --transport=nats
Env

Use env vars to specify the plugins

MICRO_BROKER=rabbitmq \
MICRO_REGISTRY=kubernetes \ 
MICRO_TRANSPORT=nats \ 
go run service.go
Options

Import and set as options when creating a new service

import (
	"github.com/micro/go-micro"
	"github.com/micro/go-plugins/registry/kubernetes"
)

func main() {
	registry := kubernetes.NewRegistry() //a default to using env vars for master API

	service := micro.NewService(
		// Set service name
		micro.Name("my.service"),
		// Set service registry
		micro.Registry(registry),
	)
}

Build

An anti-pattern is modifying the main.go file to include plugins. Best practice recommendation is to include plugins in a separate file and rebuild with it included. This allows for automation of building plugins and clean separation of concerns.

Create file plugins.go

package main

import (
	_ "github.com/micro/go-plugins/broker/rabbitmq"
	_ "github.com/micro/go-plugins/registry/kubernetes"
	_ "github.com/micro/go-plugins/transport/nats"
)

Build with plugins.go

go build -o service main.go plugins.go

Run with plugins

MICRO_BROKER=rabbitmq \
MICRO_REGISTRY=kubernetes \
MICRO_TRANSPORT=nats \
service

Contributions

A few contributions by others

Feature Description Author
Registry/Kubernetes Service discovery via the Kubernetes API @nickjackson
Registry/Zookeeper Service discovery using Zookeeper @HeavyHorst

Documentation

Overview

Package plugin provides the ability to load plugins

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(path string, p *Plugin) error

Build generates a dso plugin using the go command `go build -buildmode=plugin`

func Generate

func Generate(path string, p *Plugin) error

Generate creates a go file at the specified path. You must use `go build -buildmode=plugin`to build it.

func Init

func Init(p *Plugin) error

Init sets up the plugin

Types

type Plugin

type Plugin struct {
	// Name of the plugin e.g rabbitmq
	Name string
	// Type of the plugin e.g broker
	Type string
	// Path specifies the import path
	Path string
	// NewFunc creates an instance of the plugin
	NewFunc interface{}
}

Plugin is a plugin loaded from a file

func Load

func Load(path string) (*Plugin, error)

Load loads a plugin created with `go build -buildmode=plugin`

Directories

Path Synopsis
agent
broker
gocloud
Package gocloud provides a pubsub broker for Go Cloud.
Package gocloud provides a pubsub broker for Go Cloud.
googlepubsub
Package googlepubsub provides a Google cloud pubsub broker
Package googlepubsub provides a Google cloud pubsub broker
grpc
Package grpc is a point to point grpc broker
Package grpc is a point to point grpc broker
grpc/proto
Package broker is a generated protocol buffer package.
Package broker is a generated protocol buffer package.
kafka
Package kafka provides a kafka broker using sarama cluster
Package kafka provides a kafka broker using sarama cluster
mqtt
Package mqtt provides an mqtt broker
Package mqtt provides an mqtt broker
nats
Package nats provides a NATS broker
Package nats provides a NATS broker
nsq
Package nsq provides an NSQ broker
Package nsq provides an NSQ broker
proxy
Package proxy is a broker using the micro proxy
Package proxy is a broker using the micro proxy
rabbitmq
Package rabbitmq provides a RabbitMQ broker
Package rabbitmq provides a RabbitMQ broker
redis
Package redis provides a Redis broker
Package redis provides a Redis broker
sqs
stan
Package stan provides a NATS Streaming broker
Package stan provides a NATS Streaming broker
client
http
Package http provides a http client
Package http provides a http client
http/test
Package test is a generated protocol buffer package.
Package test is a generated protocol buffer package.
selector/label
Package label is a priority label based selector.
Package label is a priority label based selector.
selector/static
Package static is a selector which always returns the name specified with a port-number appended.
Package static is a selector which always returns the name specified with a port-number appended.
codec
bsonrpc
Package bsonrpc provides a bson-rpc codec
Package bsonrpc provides a bson-rpc codec
jsonrpc2
Package jsonrpc2 provides a json-rpc 2.0 codec Based on powerman/rpc-codec: The MIT License (MIT) Copyright (c) 2015 Alex Efros
Package jsonrpc2 provides a json-rpc 2.0 codec Based on powerman/rpc-codec: The MIT License (MIT) Copyright (c) 2015 Alex Efros
msgpackrpc
Package msgpackrpc provides a msgpack-rpc codec
Package msgpackrpc provides a msgpack-rpc codec
config
source/configmap
Package configmap config is an interface for dynamic configuration.
Package configmap config is an interface for dynamic configuration.
source/grpc/proto
Package grpc is a generated protocol buffer package.
Package grpc is a generated protocol buffer package.
source/runtimevar
package runtimevar is the source for gocloud.dev/runtimevar
package runtimevar is the source for gocloud.dev/runtimevar
source/url
Package url loads changesets from a url
Package url loads changesets from a url
micro
auth
Package auth provides auth management for micro
Package auth provides auth management for micro
auth/basic
Package basic provides basic auth using htpasswd
Package basic provides basic auth using htpasswd
auth/digest
Package digest provides digest auth using htdigest
Package digest provides digest auth using htdigest
auth/ldap
Package ldap provides ldap authentication
Package ldap provides ldap authentication
disable_rpc
Package disable_rpc disables the /rpc endpoint
Package disable_rpc disables the /rpc endpoint
gzip
Package gzip is a micro plugin for gzipping http response
Package gzip is a micro plugin for gzipping http response
index
Package index is a micro plugin for stripping a path index
Package index is a micro plugin for stripping a path index
ip_whitelist
Package ip_whitelist is a micro plugin for whitelisting ip addresses
Package ip_whitelist is a micro plugin for whitelisting ip addresses
metrics
Package metrics provides metrics for micro
Package metrics provides metrics for micro
metrics/prometheus
Package prometheus provides prometheus metrics via a http handler
Package prometheus provides prometheus metrics via a http handler
router
Package router is a micro plugin for defining HTTP routes
Package router is a micro plugin for defining HTTP routes
stats_auth
stats_auth enables basic auth on the /stats endpoint
stats_auth enables basic auth on the /stats endpoint
trace/awsxray
Package awsxray is a micro plugin for whitelisting service requests
Package awsxray is a micro plugin for whitelisting service requests
trace/uuid
Package uuid is a micro plugin for adding a trace header
Package uuid is a micro plugin for adding a trace header
whitelist
Package whitelist is a micro plugin for whitelisting service requests
Package whitelist is a micro plugin for whitelisting service requests
proxy
http
Package http provides a micro to http proxy
Package http provides a micro to http proxy
registry
etcd
Package etcd provides an etcd registry
Package etcd provides an etcd registry
etcdv3
Package etcdv3 provides an etcd version 3 registry
Package etcdv3 provides an etcd version 3 registry
eureka
Package eureka provides a Eureka registry
Package eureka provides a Eureka registry
eureka/mock
This file was generated by counterfeiter
This file was generated by counterfeiter
gossip
Package gossip provides a gossip registry based on hashicorp/memberlist
Package gossip provides a gossip registry based on hashicorp/memberlist
kubernetes
Package kubernetes provides a kubernetes registry
Package kubernetes provides a kubernetes registry
nats
Package nats provides a NATS registry using broadcast queries
Package nats provides a NATS registry using broadcast queries
proxy
Package proxy is a registry plugin for the micro proxy
Package proxy is a registry plugin for the micro proxy
zookeeper
Package zookeeper provides a zookeeper registry
Package zookeeper provides a zookeeper registry
server
http
Package http implements a go-micro.Server
Package http implements a go-micro.Server
service
kubernetes
Package kubernetes provides a micro service using k8s registry plugin
Package kubernetes provides a micro service using k8s registry plugin
store
consul
Package consul is a consul implementation of kv
Package consul is a consul implementation of kv
sync
lock/consul
Package consul is a consul implemenation of lock
Package consul is a consul implemenation of lock
lock/redis
Package redis is a redis implemenation of lock
Package redis is a redis implemenation of lock
transport
nats
Package nats provides a NATS transport
Package nats provides a NATS transport
rabbitmq
Package rabbitmq provides a RabbitMQ transport
Package rabbitmq provides a RabbitMQ transport
tcp
Package tcp provides a TCP transport
Package tcp provides a TCP transport
utp
Package utp implements a utp transport
Package utp implements a utp transport
web
kubernetes
Package kubernetes lets you initialise a web service using the k8s registry plugin
Package kubernetes lets you initialise a web service using the k8s registry plugin
wrapper
endpoint
Package endpoint provides a wrapper that executes other wrappers for specific methods
Package endpoint provides a wrapper that executes other wrappers for specific methods
select/roundrobin
Package roundrobin implements a roundrobin call strategy
Package roundrobin implements a roundrobin call strategy
select/shard
Package shard implements the sharding call strategy
Package shard implements the sharding call strategy
service
Package wrapper injects a go-micro.Service into the context
Package wrapper injects a go-micro.Service into the context
trace/awsxray
Package awsxray is a wrapper for AWS X-Ray distributed tracing
Package awsxray is a wrapper for AWS X-Ray distributed tracing
trace/datadog
Package datadog provides wrappers for Datadog ddtrace
Package datadog provides wrappers for Datadog ddtrace
trace/opencensus
Package opencensus provides wrappers for OpenCensus tracing.
Package opencensus provides wrappers for OpenCensus tracing.
trace/opentracing
Package opentracing provides wrappers for OpenTracing
Package opentracing provides wrappers for OpenTracing

Jump to

Keyboard shortcuts

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