Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6de3d9eb24 | ||
|
0016752fc1 | ||
|
92ab814138 | ||
|
dc5ec0cdb2 | ||
|
389d141c5a | ||
|
3dfe7d8703 | ||
a13cdfcc34 | |||
|
4f5ff076d4 | ||
58775249c5 | |||
|
8d21dd456c | ||
1a151a3348 | |||
|
dc2e150a58 | ||
|
aaf4a5c51a | ||
|
08d70c9d0a | ||
|
c1c0a8fb30 | ||
|
e4704a8f41 | ||
|
afd1f9f50f | ||
|
46f44fd8f8 | ||
|
df6561165a | ||
|
96ed20de7b | ||
|
c43d7137cf | ||
|
a97a1009ae | ||
|
fd2ca3a13a | ||
|
f824ba0779 | ||
|
722a3682c8 | ||
|
ca77773fbf | ||
|
dbe83c0fff | ||
|
98108d6297 | ||
|
2a70aef658 | ||
|
598de823ba | ||
|
6802de63ff | ||
|
99c80d0878 | ||
|
d3f447a732 |
@@ -1,7 +1,7 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- 1.12.x
|
||||
notifications:
|
||||
slack:
|
||||
secure: aEvhLbhujaGaKSrOokiG3//PaVHTIrc3fBpoRbCRqfZpyq6WREoapJJhF+tIpWWOwaC9GmChbD6aHo/jMUgwKXVyPSaNjiEL87YzUUpL8B2zslNp1rgfTg/LrzthOx3Q1TYwpaAl3to0fuHUVFX4yMeC2vuThq7WSXgMMxFCtbc=
|
||||
|
@@ -47,8 +47,3 @@ are pluggable and allows Go Micro to be runtime agnostic. You can plugin any und
|
||||
|
||||
See the [docs](https://micro.mu/docs/go-micro.html) for detailed information on the architecture, installation and use of go-micro.
|
||||
|
||||
## Sponsors
|
||||
|
||||
Sixt is an Enterprise Sponsor of Micro
|
||||
|
||||
<a href="https://micro.mu/blog/2016/04/25/announcing-sixt-sponsorship.html"><img src="https://micro.mu/sixt_logo.png" width=150px height="auto" /></a>
|
||||
|
36
README.zh-cn.md
Normal file
36
README.zh-cn.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Go Micro [](https://opensource.org/licenses/Apache-2.0) [](https://godoc.org/github.com/micro/go-micro) [](https://travis-ci.org/micro/go-micro) [](https://goreportcard.com/report/github.com/micro/go-micro)
|
||||
|
||||
Go Micro是基于Golang的微服务开发框架。
|
||||
|
||||
## 概览
|
||||
|
||||
Go Micro提供分布式系统开发的核心库,包含RPC与事件驱动的通信机制。
|
||||
|
||||
**micro**的设计哲学是可插拔的架构理念,她提供可快速构建系统的组件,并且可以根据自身的需求剥离默认实现并自行定制。
|
||||
|
||||
<img src="https://micro.mu/docs/images/go-micro.svg" />
|
||||
|
||||
所有插件可在仓库[github.com/micro/go-plugins](https://github.com/micro/go-plugins)中找到。
|
||||
|
||||
可以订阅我们的[Twitter](https://twitter.com/microhq)或者加入[Slack](http://slack.micro.mu/)论坛。
|
||||
|
||||
## 特性
|
||||
|
||||
Go Micro把分布式系统的各种细节抽象出来。下面是它的主要特性。
|
||||
|
||||
- **服务发现(Service Discovery)** - 自动服务注册与名称解析。服务发现是微服务开发中的核心。当服务A要与服务B协作时,它得知道B在哪里。默认的服务发现系统是Consul,而multicast DNS (mdns,组播)机制作为本地解决方案,或者零依赖的P2P网络中的SWIM协议(gossip)。
|
||||
|
||||
- **负载均衡(Load Balancing)** - 在服务发现之上构建了负载均衡机制。当我们得到一个服务的任意多个的实例节点时,我们要一个机制去决定要路由到哪一个节点。我们使用随机处理过的哈希负载均衡机制来保证对服务请求颁发的均匀分布,并且在发生问题时进行重试。
|
||||
|
||||
- **消息编码(Message Encoding)** - 支持基于内容类型(content-type)动态编码消息。客户端和服务端会一起使用content-type的格式来对Go进行无缝编/解码。各种各样的消息被编码会发送到不同的客户端,客户端服服务端默认会处理这些消息。content-type默认包含proto-rpc和json-rpc。
|
||||
|
||||
- **Request/Response** - RPC通信基于支持双向流的请求/响应方式,我们提供有抽象的同步通信机制。请求发送到服务时,会自动解析、负载均衡、拨号、转成字节流。默认的传输协议是http/1.1,而tls下使用http2协议。
|
||||
|
||||
- **异步消息(Async Messaging)** - 发布订阅(PubSub)头等功能内置在异步通信与事件驱动架构中。事件通知在微服务开发中处于核心位置。默认的消息传送使用点到点http/1.1,激活tls时则使用http2。
|
||||
|
||||
- **可插拔接口(Pluggable Interfaces)** - Go Micro为每个分布式系统抽象出接口。因此,Go Micro的接口都是可插拔的,允许其在运行时不可知的情况下仍可支持。所以只要实现接口,可以在内部使用任何的技术。更多插件请参考:[github.com/micro/go-plugins](https://github.com/micro/go-plugins)。
|
||||
|
||||
## 快速上手
|
||||
|
||||
更多关于架构、安装的资料可以查看[文档](https://micro.mu/docs/go-micro_cn.html)。
|
||||
|
@@ -83,7 +83,11 @@ func (m *MockClient) Call(ctx context.Context, req client.Request, rsp interface
|
||||
}
|
||||
response := r.Response
|
||||
if t := reflect.TypeOf(r.Response); t.Kind() == reflect.Func {
|
||||
response = reflect.ValueOf(r.Response).Call([]reflect.Value{})[0].Interface()
|
||||
var request []reflect.Value
|
||||
if t.NumIn() == 1 {
|
||||
request = append(request, reflect.ValueOf(req.Body()))
|
||||
}
|
||||
response = reflect.ValueOf(r.Response).Call(request)[0].Interface()
|
||||
}
|
||||
|
||||
v.Set(reflect.ValueOf(response))
|
||||
|
@@ -18,12 +18,18 @@ func TestClient(t *testing.T) {
|
||||
{Endpoint: "Foo.Fail", Error: errors.InternalServerError("go.mock", "failed")},
|
||||
{Endpoint: "Foo.Func", Response: func() string { return "string" }},
|
||||
{Endpoint: "Foo.FuncStruct", Response: func() *TestResponse { return &TestResponse{Param: "aparam"} }},
|
||||
{Endpoint: "Foo.FuncWithReqBody", Response: func(req interface{}) string {
|
||||
if req.(map[string]string)["foo"] == "bar" {
|
||||
return "string"
|
||||
}
|
||||
return "wrong"
|
||||
}},
|
||||
}
|
||||
|
||||
c := NewClient(Response("go.mock", response))
|
||||
|
||||
for _, r := range response {
|
||||
req := c.NewRequest("go.mock", r.Endpoint, map[string]interface{}{"foo": "bar"})
|
||||
req := c.NewRequest("go.mock", r.Endpoint, map[string]string{"foo": "bar"})
|
||||
var rsp interface{}
|
||||
|
||||
err := c.Call(context.TODO(), req, &rsp)
|
||||
@@ -33,6 +39,20 @@ func TestClient(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Log(rsp)
|
||||
if r.Endpoint == "Foo.FuncWithReqBody" {
|
||||
req := c.NewRequest("go.mock", r.Endpoint, map[string]string{"foo": "wrong"})
|
||||
var rsp interface{}
|
||||
|
||||
err := c.Call(context.TODO(), req, &rsp)
|
||||
|
||||
if err != r.Error {
|
||||
t.Fatalf("Expecter error %v got %v", r.Error, err)
|
||||
}
|
||||
if rsp.(string) != "wrong" {
|
||||
t.Fatalf("Expecter response 'wrong' got %v", rsp)
|
||||
}
|
||||
t.Log(rsp)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -382,7 +382,7 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
|
||||
return err
|
||||
}
|
||||
|
||||
ch := make(chan error, callOpts.Retries)
|
||||
ch := make(chan error, callOpts.Retries+1)
|
||||
var gerr error
|
||||
|
||||
for i := 0; i <= callOpts.Retries; i++ {
|
||||
@@ -463,7 +463,7 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt
|
||||
err error
|
||||
}
|
||||
|
||||
ch := make(chan response, callOpts.Retries)
|
||||
ch := make(chan response, callOpts.Retries+1)
|
||||
var grr error
|
||||
|
||||
for i := 0; i <= callOpts.Retries; i++ {
|
||||
|
@@ -71,6 +71,7 @@ var (
|
||||
cli.IntFlag{
|
||||
Name: "client_retries",
|
||||
EnvVar: "MICRO_CLIENT_RETRIES",
|
||||
Value: client.DefaultRetries,
|
||||
Usage: "Sets the client retries. Default: 1",
|
||||
},
|
||||
cli.IntFlag{
|
||||
|
176
go.mod
176
go.mod
@@ -1,22 +1,176 @@
|
||||
module github.com/micro/go-micro
|
||||
|
||||
require (
|
||||
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 // indirect
|
||||
cloud.google.com/go v0.39.0 // indirect
|
||||
contrib.go.opencensus.io/exporter/ocagent v0.5.0 // indirect
|
||||
github.com/Azure/azure-sdk-for-go v29.0.0+incompatible // indirect
|
||||
github.com/Azure/go-autorest v12.1.0+incompatible // indirect
|
||||
github.com/DataDog/dd-trace-go v1.14.0 // indirect
|
||||
github.com/DataDog/zstd v1.4.0 // indirect
|
||||
github.com/Jeffail/gabs v1.4.0 // indirect
|
||||
github.com/Microsoft/go-winio v0.4.12 // indirect
|
||||
github.com/NYTimes/gziphandler v1.1.1 // indirect
|
||||
github.com/OneOfOne/xxhash v1.2.5 // indirect
|
||||
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
||||
github.com/SAP/go-hdb v0.14.1 // indirect
|
||||
github.com/Shopify/sarama v1.22.1 // indirect
|
||||
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190522081930-582d16a078d0 // indirect
|
||||
github.com/aliyun/aliyun-oss-go-sdk v1.9.6 // indirect
|
||||
github.com/araddon/gou v0.0.0-20190110011759-c797efecbb61 // indirect
|
||||
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
|
||||
github.com/aws/aws-sdk-go v1.19.35 // indirect
|
||||
github.com/boombuler/barcode v1.0.0 // indirect
|
||||
github.com/chrismalek/oktasdk-go v0.0.0-20181212195951-3430665dfaa0 // indirect
|
||||
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect
|
||||
github.com/coredns/coredns v1.5.0 // indirect
|
||||
github.com/coreos/etcd v3.3.13+incompatible // indirect
|
||||
github.com/coreos/go-semver v0.3.0 // indirect
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
|
||||
github.com/dancannon/gorethink v4.0.0+incompatible // indirect
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3 // indirect
|
||||
github.com/denverdino/aliyungo v0.0.0-20190410085603-611ead8a6fed // indirect
|
||||
github.com/dgryski/go-sip13 v0.0.0-20190329191031-25c5027a8c7b // indirect
|
||||
github.com/digitalocean/godo v1.15.0 // indirect
|
||||
github.com/dnaeon/go-vcr v1.0.1 // indirect
|
||||
github.com/dnstap/golang-dnstap v0.0.0-20190521061535-1a0dab85b926 // indirect
|
||||
github.com/docker/go-connections v0.4.0 // indirect
|
||||
github.com/docker/go-units v0.4.0 // indirect
|
||||
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
|
||||
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f // indirect
|
||||
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
|
||||
github.com/envoyproxy/go-control-plane v0.8.0 // indirect
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible // indirect
|
||||
github.com/farsightsec/golang-framestream v0.0.0-20190425193708-fa4b164d59b8 // indirect
|
||||
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa // indirect
|
||||
github.com/gammazero/workerpool v0.0.0-20190521015540-3b91a70bc0a1 // indirect
|
||||
github.com/garyburd/redigo v1.6.0 // indirect
|
||||
github.com/go-ldap/ldap v3.0.3+incompatible // indirect
|
||||
github.com/go-log/log v0.1.0
|
||||
github.com/golang/protobuf v1.2.0
|
||||
github.com/google/uuid v1.1.0
|
||||
github.com/hashicorp/consul v1.4.2
|
||||
github.com/hashicorp/memberlist v0.1.3
|
||||
github.com/mattn/go-colorable v0.1.1 // indirect
|
||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.19.0 // indirect
|
||||
github.com/go-openapi/spec v0.19.0 // indirect
|
||||
github.com/go-openapi/swag v0.19.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.4.1 // indirect
|
||||
github.com/go-stomp/stomp v2.0.3+incompatible // indirect
|
||||
github.com/gocql/gocql v0.0.0-20190423091413-b99afaf3b163 // indirect
|
||||
github.com/gogo/googleapis v1.2.0 // indirect
|
||||
github.com/golang/mock v1.3.1 // indirect
|
||||
github.com/golang/protobuf v1.3.1
|
||||
github.com/google/btree v1.0.0 // indirect
|
||||
github.com/google/gofuzz v1.0.0 // indirect
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f // indirect
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/gophercloud/gophercloud v0.0.0-20190520235722-e87e5f90e7e6 // indirect
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect
|
||||
github.com/gorilla/mux v1.7.2 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0 // indirect
|
||||
github.com/hashicorp/consul v1.5.0
|
||||
github.com/hashicorp/consul/api v1.1.0
|
||||
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
|
||||
github.com/hashicorp/go-discover v0.0.0-20190522154730-8aba54d36e17 // indirect
|
||||
github.com/hashicorp/go-hclog v0.9.2 // indirect
|
||||
github.com/hashicorp/go-memdb v1.0.2 // indirect
|
||||
github.com/hashicorp/go-msgpack v0.5.5 // indirect
|
||||
github.com/hashicorp/go-version v1.2.0 // indirect
|
||||
github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 // indirect
|
||||
github.com/hashicorp/memberlist v0.1.4
|
||||
github.com/hashicorp/nomad/api v0.0.0-20190522160243-df84e07c1a46 // indirect
|
||||
github.com/hashicorp/raft v1.0.1 // indirect
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea // indirect
|
||||
github.com/hashicorp/serf v0.8.3 // indirect
|
||||
github.com/hashicorp/vault v1.1.2 // indirect
|
||||
github.com/hashicorp/vault-plugin-auth-alicloud v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-auth-azure v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-auth-centrify v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-auth-jwt v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-auth-kubernetes v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-secrets-ad v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-secrets-alicloud v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-secrets-azure v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-secrets-gcp v0.5.2 // indirect
|
||||
github.com/hashicorp/vault-plugin-secrets-gcpkms v0.5.1 // indirect
|
||||
github.com/hashicorp/vault-plugin-secrets-kv v0.5.1 // indirect
|
||||
github.com/hashicorp/vault/api v1.0.2 // indirect
|
||||
github.com/hashicorp/vault/sdk v0.1.11 // indirect
|
||||
github.com/influxdata/influxdb v1.7.6 // indirect
|
||||
github.com/jarcoal/httpmock v1.0.4 // indirect
|
||||
github.com/jefferai/jsonx v1.0.0 // indirect
|
||||
github.com/joyent/triton-go v0.0.0-20190112182421-51ffac552869 // indirect
|
||||
github.com/keybase/go-crypto v0.0.0-20190416182011-b785b22cc757 // indirect
|
||||
github.com/kisielk/errcheck v1.2.0 // indirect
|
||||
github.com/klauspost/cpuid v1.2.1 // indirect
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
|
||||
github.com/kr/pty v1.1.4 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/lib/pq v1.1.1 // indirect
|
||||
github.com/linode/linodego v0.8.1 // indirect
|
||||
github.com/lucas-clemente/quic-go v0.11.1 // indirect
|
||||
github.com/lyft/protoc-gen-validate v0.0.14 // indirect
|
||||
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 // indirect
|
||||
github.com/mattbaird/elastigo v0.0.0-20170123220020-2fe47fd29e4b // indirect
|
||||
github.com/mattn/go-isatty v0.0.8 // indirect
|
||||
github.com/mholt/caddy v1.0.0 // indirect
|
||||
github.com/mholt/certmagic v0.5.1 // indirect
|
||||
github.com/michaelklishin/rabbit-hole v1.5.0 // indirect
|
||||
github.com/micro/cli v0.1.0
|
||||
github.com/micro/go-log v0.1.0
|
||||
github.com/micro/go-rcache v0.2.1
|
||||
github.com/micro/h2c v1.0.0
|
||||
github.com/micro/go-rcache v0.3.0
|
||||
github.com/micro/mdns v0.1.0
|
||||
github.com/micro/util v0.2.0
|
||||
github.com/miekg/dns v1.1.12 // indirect
|
||||
github.com/mitchellh/hashstructure v1.0.0
|
||||
github.com/mitchellh/pointerstructure v0.0.0-20190430161007-f252a8fd71c8 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20190414153302-2ae31c8b6b30 // indirect
|
||||
github.com/opentracing/opentracing-go v1.1.0 // indirect
|
||||
github.com/openzipkin/zipkin-go-opentracing v0.3.5 // indirect
|
||||
github.com/ory-am/common v0.4.0 // indirect
|
||||
github.com/pborman/uuid v1.2.0 // indirect
|
||||
github.com/pkg/errors v0.8.1
|
||||
golang.org/x/crypto v0.0.0-20190222235706-ffb98f73852f // indirect
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd
|
||||
golang.org/x/sys v0.0.0-20190222171317-cd391775e71e // indirect
|
||||
github.com/pquerna/otp v1.1.0 // indirect
|
||||
github.com/prometheus/client_golang v0.9.3 // indirect
|
||||
github.com/prometheus/common v0.4.1 // indirect
|
||||
github.com/prometheus/procfs v0.0.0-20190522114515-bc1a522cf7b1 // indirect
|
||||
github.com/prometheus/tsdb v0.8.0 // indirect
|
||||
github.com/rogpeppe/fastuuid v1.1.0 // indirect
|
||||
github.com/russross/blackfriday v2.0.0+incompatible // indirect
|
||||
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec // indirect
|
||||
github.com/shirou/gopsutil v2.18.12+incompatible // indirect
|
||||
github.com/sirupsen/logrus v1.4.2 // indirect
|
||||
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect
|
||||
github.com/softlayer/softlayer-go v0.0.0-20190508182157-7c592eb2559c // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94 // indirect
|
||||
github.com/stretchr/objx v0.2.0 // indirect
|
||||
github.com/ugorji/go v1.1.4 // indirect
|
||||
github.com/vmware/govmomi v0.20.1 // indirect
|
||||
go.uber.org/atomic v1.4.0 // indirect
|
||||
go.uber.org/zap v1.10.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522 // indirect
|
||||
golang.org/x/image v0.0.0-20190516052701-61b8692d9a5c // indirect
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect
|
||||
golang.org/x/mobile v0.0.0-20190509164839-32b2708ab171 // indirect
|
||||
golang.org/x/net v0.0.0-20190522155817-f3200d17e092
|
||||
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07 // indirect
|
||||
golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5 // indirect
|
||||
golang.org/x/tools v0.0.0-20190521203540-521d6ed310dd // indirect
|
||||
google.golang.org/appengine v1.6.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20190516172635-bb713bdc0e52 // indirect
|
||||
gopkg.in/gorethink/gorethink.v4 v4.1.0 // indirect
|
||||
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
|
||||
gopkg.in/ory-am/dockertest.v2 v2.2.3 // indirect
|
||||
honnef.co/go/tools v0.0.0-20190522022531-bad1bd262ba8 // indirect
|
||||
k8s.io/api v0.0.0-20190515023547-db5a9d1c40eb // indirect
|
||||
k8s.io/client-go v11.0.0+incompatible // indirect
|
||||
k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20190510232812-a01b7d5d6c22 // indirect
|
||||
k8s.io/utils v0.0.0-20190520173318-324c5df7d3f0 // indirect
|
||||
layeh.com/radius v0.0.0-20190322222518-890bc1058917 // indirect
|
||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190521201008-1c46bef2e9c8 // indirect
|
||||
)
|
||||
|
||||
replace github.com/golang/lint => github.com/golang/lint v0.0.0-20190227174305-8f45f776aaf1
|
||||
|
@@ -12,5 +12,5 @@ type publisher struct {
|
||||
}
|
||||
|
||||
func (p *publisher) Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error {
|
||||
return p.c.Publish(ctx, p.c.NewMessage(p.topic, msg))
|
||||
return p.c.Publish(ctx, p.c.NewMessage(p.topic, msg), opts...)
|
||||
}
|
||||
|
@@ -105,11 +105,12 @@ func configure(c *consulRegistry, opts ...registry.Option) {
|
||||
}
|
||||
}
|
||||
|
||||
if config.HttpClient == nil {
|
||||
config.HttpClient = new(http.Client)
|
||||
}
|
||||
|
||||
// requires secure connection?
|
||||
if c.opts.Secure || c.opts.TLSConfig != nil {
|
||||
if config.HttpClient == nil {
|
||||
config.HttpClient = new(http.Client)
|
||||
}
|
||||
|
||||
config.Scheme = "https"
|
||||
// We're going to support InsecureSkipVerify
|
||||
|
@@ -2,10 +2,12 @@ package consul
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/consul/api"
|
||||
"github.com/hashicorp/consul/watch"
|
||||
"github.com/hashicorp/consul/api/watch"
|
||||
"github.com/micro/go-micro/registry"
|
||||
)
|
||||
|
||||
@@ -43,7 +45,7 @@ func newConsulWatcher(cr *consulRegistry, opts ...registry.WatchOption) (registr
|
||||
}
|
||||
|
||||
wp.Handler = cw.handle
|
||||
go wp.Run(cr.Address)
|
||||
go wp.RunWithClientAndLogger(cr.Client, log.New(os.Stderr, "", log.LstdFlags))
|
||||
cw.wp = wp
|
||||
|
||||
return cw, nil
|
||||
@@ -208,7 +210,7 @@ func (cw *consulWatcher) handle(idx uint64, data interface{}) {
|
||||
})
|
||||
if err == nil {
|
||||
wp.Handler = cw.serviceHandler
|
||||
go wp.Run(cw.r.Address)
|
||||
go wp.RunWithClientAndLogger(cw.r.Client, log.New(os.Stderr, "", log.LstdFlags))
|
||||
cw.watchers[service] = wp
|
||||
cw.next <- ®istry.Result{Action: "create", Service: ®istry.Service{Name: service}}
|
||||
}
|
||||
|
@@ -159,6 +159,10 @@ func configure(g *gossipRegistry, opts ...registry.Option) error {
|
||||
|
||||
// shutdown old member
|
||||
g.Stop()
|
||||
|
||||
// lock internals
|
||||
g.Lock()
|
||||
|
||||
// new done chan
|
||||
g.done = make(chan bool)
|
||||
|
||||
@@ -250,16 +254,12 @@ func configure(g *gossipRegistry, opts ...registry.Option) error {
|
||||
events: g.events,
|
||||
}
|
||||
}
|
||||
|
||||
// create the memberlist
|
||||
m, err := memberlist.Create(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// set internals
|
||||
g.Lock()
|
||||
|
||||
if len(curAddrs) > 0 {
|
||||
for _, addr := range curAddrs {
|
||||
g.members[addr] = nodeActionUnknown
|
||||
@@ -547,9 +547,13 @@ func (g *gossipRegistry) expiryLoop(updates *updates) {
|
||||
ticker := time.NewTicker(ExpiryTick)
|
||||
defer ticker.Stop()
|
||||
|
||||
g.RLock()
|
||||
done := g.done
|
||||
g.RUnlock()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-g.done:
|
||||
case <-done:
|
||||
return
|
||||
case <-ticker.C:
|
||||
now := uint64(time.Now().UnixNano())
|
||||
@@ -576,10 +580,13 @@ func (g *gossipRegistry) expiryLoop(updates *updates) {
|
||||
|
||||
// process member events
|
||||
func (g *gossipRegistry) eventLoop() {
|
||||
g.RLock()
|
||||
done := g.done
|
||||
g.RUnlock()
|
||||
for {
|
||||
select {
|
||||
// return when done
|
||||
case <-g.done:
|
||||
case <-done:
|
||||
return
|
||||
case ev := <-g.events:
|
||||
// TODO: nonblocking update
|
||||
@@ -603,10 +610,12 @@ func (g *gossipRegistry) run() {
|
||||
// event loop
|
||||
go g.eventLoop()
|
||||
|
||||
g.RLock()
|
||||
// connect loop
|
||||
if g.connectRetry {
|
||||
go g.connectLoop()
|
||||
}
|
||||
g.RUnlock()
|
||||
|
||||
// process the updates
|
||||
for u := range g.updates {
|
||||
@@ -808,7 +817,6 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
|
||||
watchers: make(map[string]chan *registry.Result),
|
||||
members: make(map[string]int32),
|
||||
}
|
||||
|
||||
// run the updater
|
||||
go g.run()
|
||||
|
||||
@@ -816,7 +824,6 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
|
||||
if err := configure(g, opts...); err != nil {
|
||||
log.Fatalf("[gossip] Error configuring registry: %v", err)
|
||||
}
|
||||
|
||||
// wait for setup
|
||||
<-time.After(g.interval * 2)
|
||||
|
||||
|
@@ -34,7 +34,9 @@ func (m *gossipWatcher) Next() (*registry.Result, error) {
|
||||
if len(m.wo.Service) > 0 && r.Service.Name != m.wo.Service {
|
||||
continue
|
||||
}
|
||||
return r, nil
|
||||
nr := ®istry.Result{}
|
||||
*nr = *r
|
||||
return nr, nil
|
||||
case <-m.stop:
|
||||
return nil, registry.ErrWatcherStopped
|
||||
}
|
||||
|
@@ -20,6 +20,10 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
if len(v.Name()) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arg := ®istry.Value{
|
||||
Name: v.Name(),
|
||||
Type: v.Name(),
|
||||
@@ -37,6 +41,9 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
||||
// if we can find a json tag use it
|
||||
if tags := f.Tag.Get("json"); len(tags) > 0 {
|
||||
parts := strings.Split(tags, ",")
|
||||
if parts[0] == "-" || parts[0] == "omitempty" {
|
||||
continue
|
||||
}
|
||||
val.Name = parts[0]
|
||||
}
|
||||
|
||||
@@ -45,6 +52,11 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
||||
val.Name = v.Field(i).Name
|
||||
}
|
||||
|
||||
// still no name then continue
|
||||
if len(val.Name) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
arg.Values = append(arg.Values, val)
|
||||
}
|
||||
case reflect.Slice:
|
||||
|
@@ -25,6 +25,8 @@ type Options struct {
|
||||
HdlrWrappers []HandlerWrapper
|
||||
SubWrappers []SubscriberWrapper
|
||||
|
||||
// RegisterCheck runs a check function before registering the service
|
||||
RegisterCheck func(context.Context) error
|
||||
// The register expiry time
|
||||
RegisterTTL time.Duration
|
||||
// The interval on which to register
|
||||
@@ -67,6 +69,10 @@ func newOptions(opt ...Option) Options {
|
||||
opts.DebugHandler = debug.DefaultDebugHandler
|
||||
}
|
||||
|
||||
if opts.RegisterCheck == nil {
|
||||
opts.RegisterCheck = DefaultRegisterCheck
|
||||
}
|
||||
|
||||
if len(opts.Address) == 0 {
|
||||
opts.Address = DefaultAddress
|
||||
}
|
||||
@@ -163,6 +169,13 @@ func Metadata(md map[string]string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterCheck run func before registry service
|
||||
func RegisterCheck(fn func(context.Context) error) Option {
|
||||
return func(o *Options) {
|
||||
o.RegisterCheck = fn
|
||||
}
|
||||
}
|
||||
|
||||
// Register the service with a TTL
|
||||
func RegisterTTL(t time.Duration) Option {
|
||||
return func(o *Options) {
|
||||
|
@@ -468,9 +468,14 @@ func (s *rpcServer) Start() error {
|
||||
|
||||
log.Logf("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address())
|
||||
|
||||
// announce self to the world
|
||||
if err := s.Register(); err != nil {
|
||||
log.Log("Server register error: ", err)
|
||||
// use RegisterCheck func before register
|
||||
if err = s.opts.RegisterCheck(s.opts.Context); err != nil {
|
||||
log.Logf("Server %s-%s register check error: %s", config.Name, config.Id, err)
|
||||
} else {
|
||||
// announce self to the world
|
||||
if err = s.Register(); err != nil {
|
||||
log.Log("Server %s-%s register error: %s", config.Name, config.Id, err)
|
||||
}
|
||||
}
|
||||
|
||||
exit := make(chan bool)
|
||||
@@ -518,8 +523,19 @@ func (s *rpcServer) Start() error {
|
||||
select {
|
||||
// register self on interval
|
||||
case <-t.C:
|
||||
if err := s.Register(); err != nil {
|
||||
log.Log("Server register error: ", err)
|
||||
s.RLock()
|
||||
registered := s.registered
|
||||
s.RUnlock()
|
||||
if err = s.opts.RegisterCheck(s.opts.Context); err != nil && registered {
|
||||
log.Logf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err)
|
||||
// deregister self in case of error
|
||||
if err := s.Deregister(); err != nil {
|
||||
log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err)
|
||||
}
|
||||
} else {
|
||||
if err := s.Register(); err != nil {
|
||||
log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err)
|
||||
}
|
||||
}
|
||||
// wait for exit
|
||||
case ch = <-s.exit:
|
||||
@@ -531,7 +547,7 @@ func (s *rpcServer) Start() error {
|
||||
|
||||
// deregister self
|
||||
if err := s.Deregister(); err != nil {
|
||||
log.Log("Server deregister error: ", err)
|
||||
log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err)
|
||||
}
|
||||
|
||||
// wait for requests to finish
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-log"
|
||||
log "github.com/micro/go-log"
|
||||
"github.com/micro/go-micro/codec"
|
||||
"github.com/micro/go-micro/registry"
|
||||
)
|
||||
@@ -115,12 +115,13 @@ type Subscriber interface {
|
||||
type Option func(*Options)
|
||||
|
||||
var (
|
||||
DefaultAddress = ":0"
|
||||
DefaultName = "server"
|
||||
DefaultVersion = "latest"
|
||||
DefaultId = uuid.New().String()
|
||||
DefaultServer Server = newRpcServer()
|
||||
DefaultRouter = newRpcRouter()
|
||||
DefaultAddress = ":0"
|
||||
DefaultName = "server"
|
||||
DefaultVersion = "latest"
|
||||
DefaultId = uuid.New().String()
|
||||
DefaultServer Server = newRpcServer()
|
||||
DefaultRouter = newRpcRouter()
|
||||
DefaultRegisterCheck = func(context.Context) error { return nil }
|
||||
)
|
||||
|
||||
// DefaultOptions returns config options for the default service
|
||||
|
Reference in New Issue
Block a user