gorpc

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 15 Imported by: 0

README

1.github上下载一个cpp包:https://github.com/google/protobuf/releases make make install安装即可

$ wget https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/protobuf-cpp-3.13.0.tar.gz
$ tar xvfz protobuf-cpp-3.13.0.tar.gz
$ cd protobuf-cpp-3.13.0
$ ./configure && make && make install
  1. 安装go插件 protoc-gen-go
$ go get -u github.com/golang/protobuf/protoc-gen-go

3.安装go-micro插件 protoc-gen-micro

$ go get github.com/micro/protoc-gen-micro
  1. 启动consul
  • Windows
@echo off
consul agent -server -bootstrap-expect 1 -data-dir .\data -node=s1 -bind=127.0.0.1 -http-port=8500  -dns-port=5600 -rejoin -config-dir=.\etc\consul.d -client 0.0.0.0
pause
  • Linux
$ sudo mkdir -p /data/consul
$ sudo chmod 0777 /data/consul
nohup consul agent -server -bootstrap-expect 1 -data-dir /data/consul -node=s1 -bind=127.0.0.1 -http-port=8500  -dns-port=8600 -rejoin -config-dir=/etc/consul.d/ -client 0.0.0.0 > /tmp/consul.log 2>&1 &

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func FromContext added in v1.1.2

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

get metadata from context

func GetMetadata added in v1.1.2

func GetMetadata(ctx context.Context, key string) (value string)

get metadata value from context

func NewContext added in v1.1.2

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

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 EndpointType

type EndpointType int
const (
	EndpointType_MDNS      EndpointType = 0 // multicast DNS
	EndpointType_ETCD      EndpointType = 1 // etcd
	EndpointType_CONSUL    EndpointType = 2 // consul
	EndpointType_ZOOKEEPER EndpointType = 3 // zookeeper
)

func (EndpointType) String

func (t EndpointType) String() string

type GoRPC

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

func NewGoRPC

func NewGoRPC(endpointType EndpointType) (g *GoRPC)

func (*GoRPC) NewClient

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

new a go-micro client

func (*GoRPC) NewServer

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

new a go-micro server

Directories

Path Synopsis
example
client command
server command

Jump to

Keyboard shortcuts

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