gomicro

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 13 Imported by: 0

README

gomicro

golang grpc+go-micro.v2 wrapper

install protoc and golang plugins binaries

https://github.com/civet148/protoc-plugins

install protoc from source code

    1. download proto compiler source code
$ wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protobuf-cpp-3.19.1.tar.gz
$ tar xvfz protobuf-cpp-3.19.0.tar.gz
$ cd protobuf-cpp-3.19.0
$ ./configure && sudo make && sudo make install
    1. install protoc-gen-go
$ go get -u github.com/golang/protobuf/protoc-gen-go
    1. install protoc-gen-micro v2
$ go get -u github.com/micro/protoc-gen-micro/v2

Documentation

Index

Constants

View Source
const (
	DISCOVERY_DEFAULT_INTERVAL = 3
	DISCOVERY_DEFAULT_TTL      = 10
	DEFAULT_RPC_TIMEOUT        = 30
)

Variables

View Source
var (
	DefaultMaxMsgSize = 512 * 1024 * 1024 //default allow 512 MiB data transport
)

Functions

func FromContext

func FromContext(ctx context.Context) (md metadata.Metadata)

FromContext get metadata from context

func NewContext

func NewContext(md map[string]string, timeout int) context.Context

NewContext md -> metadata of RPC call, set to nil if have no any meta-data timeout -> timeout seconds of RPC call, if <=0 will set it to DEFAULT_RPC_TIMEOUT

Types

type Discovery

type Discovery struct {
	ServiceName string   // register service name [required]
	RpcAddr     string   // register server RPC address [required]
	Interval    int      // register interval default 3 seconds [optional]
	TTL         int      // register TTL default 10 seconds [optional]
	Endpoints   []string // register endpoints of etcd/consul/zookeeper eg. ["192.168.0.10:2379","192.168.0.11:2379"]
}

type GoRPC

type GoRPC struct {
	// contains filtered or unexported fields
}

func NewGoRPC

func NewGoRPC(registryType RegistryType, maxSize ...int) (g *GoRPC)

sizes: max send or receive msg size in byte

func (*GoRPC) NewClient

func (g *GoRPC) NewClient(endPoints ...string) (c client.Client)

NewClient new a go-micro client

func (*GoRPC) NewServer

func (g *GoRPC) NewServer(discovery *Discovery) (s server.Server)

NewServer new a go-micro server

type RegistryType

type RegistryType int
const (
	RegistryType_MDNS RegistryType = 0 // multicast DNS
	RegistryType_ETCD RegistryType = 1 // etcd

)

func (RegistryType) String

func (t RegistryType) String() string

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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