Compare commits

...

33 Commits

Author SHA1 Message Date
Asim Aslam
6de3d9eb24 Update go mod 2019-05-22 16:11:06 +00:00
Asim Aslam
0016752fc1 accept publisher options 2019-05-21 07:49:30 +00:00
Asim Aslam
92ab814138 remove sponsors 2019-05-19 15:38:49 +00:00
Asim Aslam
dc5ec0cdb2 Merge pull request #478 from sneat/fix-watcher-across-datacenters
Use existing consul client for watcher
2019-05-16 08:12:40 +01:00
Blair McMillan
389d141c5a Use existing consul client for watcher 2019-05-16 12:37:48 +10:00
Asim Aslam
3dfe7d8703 Merge pull request #473 from unistack-org/health
add RegisterCheck server option for internal health checks
2019-05-15 15:11:27 +01:00
a13cdfcc34 add RegisterCheck server option for internal health checks
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-05-15 15:34:34 +03:00
Asim Aslam
4f5ff076d4 Merge pull request #472 from unistack-org/gossip2
fix race with rcache
2019-05-09 21:24:27 +01:00
58775249c5 fix race with rcache
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-05-09 23:02:32 +03:00
Asim Aslam
8d21dd456c Merge pull request #471 from unistack-org/gossip
fix data races in gossip registry
2019-05-09 20:37:04 +01:00
1a151a3348 fix data races in gossip registry
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2019-05-09 22:32:21 +03:00
Asim Aslam
dc2e150a58 Merge pull request #466 from Ak-Army/master
send requestBody to mock function if it can handle it
2019-05-07 14:16:04 +01:00
Hunyadvári Péter
aaf4a5c51a rename reqBody variable to request 2019-05-02 18:06:43 +02:00
Hunyadvári Péter
08d70c9d0a fix and add tests 2019-05-02 18:02:24 +02:00
Hunyadvári Péter
c1c0a8fb30 send requestBody to mock function if it can handle it 2019-05-02 17:14:41 +02:00
Asim Aslam
e4704a8f41 Merge pull request #461 from moorepatrick/patch-1
Update consul/watch import
2019-04-26 19:22:33 +01:00
Patrick Moore
afd1f9f50f Update consul/watch import
The watch package was moved from github.com/hashicorp/consul/watch to github.com/hashicorp/consul/api/watch to live in the API module.
Per: 6c885d383a
2019-04-26 10:40:10 -07:00
Asim Aslam
46f44fd8f8 update go mod 2019-04-23 07:15:03 +00:00
Asim Aslam
df6561165a gofmt 2019-04-23 07:13:21 +00:00
Asim Aslam
96ed20de7b Merge pull request #458 from leaxoy/master
cleanup deps
2019-04-22 15:02:04 +01:00
lixiaohui
c43d7137cf cleanup deps 2019-04-22 21:39:02 +08:00
Asim Aslam
a97a1009ae Merge pull request #455 from tongjichao/fix/client_retries
fix: client retries will be 0 when not set
2019-04-18 18:16:53 +01:00
tongjichao
fd2ca3a13a fix: client retries will be 0 when not set
fix: client retries will be 0 when not set
2019-04-19 00:05:02 +08:00
Asim Aslam
f824ba0779 non-blocking call chan when retries are 0 2019-04-18 09:05:22 +00:00
Asim Aslam
722a3682c8 Update go mod 2019-03-28 17:01:56 +00:00
Asim Aslam
ca77773fbf fix json tag parsing 2019-03-19 00:21:25 +00:00
Asim Aslam
dbe83c0fff bump travis 2019-03-07 20:29:40 +00:00
Asim Aslam
98108d6297 Update README.md 2019-03-05 13:13:56 +00:00
Asim Aslam
2a70aef658 Merge pull request #429 from printfcoder/master
add Chinese version guide
2019-03-03 13:46:12 +00:00
shuxian
598de823ba add Chinese version guide 2019-03-03 21:36:44 +08:00
shuxian
6802de63ff readme zh-cn version 2019-02-28 16:57:31 +08:00
Asim Aslam
99c80d0878 Merge pull request #426 from printfcoder/master
solve consul.NewRegistry httpclient 'nil pointer dereference' bug
2019-02-28 07:10:23 +00:00
shuxian
d3f447a732 solve NewRegistry httpclient 'nil pointer dereference' bug 2019-02-28 09:56:57 +08:00
18 changed files with 1396 additions and 56 deletions

View File

@@ -1,7 +1,7 @@
language: go
go:
- 1.10.x
- 1.11.x
- 1.12.x
notifications:
slack:
secure: aEvhLbhujaGaKSrOokiG3//PaVHTIrc3fBpoRbCRqfZpyq6WREoapJJhF+tIpWWOwaC9GmChbD6aHo/jMUgwKXVyPSaNjiEL87YzUUpL8B2zslNp1rgfTg/LrzthOx3Q1TYwpaAl3to0fuHUVFX4yMeC2vuThq7WSXgMMxFCtbc=

View File

@@ -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
View File

@@ -0,0 +1,36 @@
# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GoDoc](https://godoc.org/github.com/micro/go-micro?status.svg)](https://godoc.org/github.com/micro/go-micro) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/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)。

View File

@@ -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))

View File

@@ -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)
}
}
}

View File

@@ -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++ {

View File

@@ -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
View File

@@ -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

1088
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -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...)
}

View File

@@ -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

View File

@@ -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 <- &registry.Result{Action: "create", Service: &registry.Service{Name: service}}
}

View File

@@ -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)

View File

@@ -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 := &registry.Result{}
*nr = *r
return nr, nil
case <-m.stop:
return nil, registry.ErrWatcherStopped
}

View File

@@ -20,6 +20,10 @@ func extractValue(v reflect.Type, d int) *registry.Value {
v = v.Elem()
}
if len(v.Name()) == 0 {
return nil
}
arg := &registry.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:

View File

@@ -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) {

View File

@@ -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

View File

@@ -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