上一页 1 2 3 4 5 6 7 8 9 10 ··· 22 下一页
摘要: 首先放上httptransport.NewServer的源碼 func NewServer( e endpoint.Endpoint, dec DecodeRequestFunc, enc EncodeResponseFunc, options ...ServerOption, //这里的不定长参数可以用来自定义错误处理 ) *Server { s := ... 阅读全文
posted @ 2019-12-23 14:13 离地最远的星 阅读(678) 评论(0) 推荐(0) 编辑
摘要: 限流代码 package Services import ( "context" "errors" "fmt" "github.com/go-kit/kit/endpoint" "golang.org/x/time/rate" "gomicro/utils" "strconv" ) type UserRequest struct { /... 阅读全文
posted @ 2019-12-22 23:56 离地最远的星 阅读(420) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "golang.org/x/time/rate" "time" ) func main() { r := rate.NewLimiter(1, 5) //1表示每次放进筒内的数量,桶内的令牌数是5,最大令牌数也是5,这个筒子是自动补充的,你只要取了令牌不管你取多少个,这里都会在每次取完后自动加1个进来,因为... 阅读全文
posted @ 2019-12-22 23:38 离地最远的星 阅读(818) 评论(0) 推荐(0) 编辑
摘要: package main import ( "context" "fmt" "golang.org/x/time/rate" "log" "time" ) func main() { r := rate.NewLimiter(1, 5) //1表示每次放进筒内的数量,桶内的令牌数是5,最大令牌数也是5,这个筒子是自动补充的,你只要... 阅读全文
posted @ 2019-12-22 22:34 离地最远的星 阅读(491) 评论(0) 推荐(0) 编辑
摘要: package main import ( "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "github.com/go-kit/kit/sd" "github.com/go-kit/kit/sd/consul" "github.com... 阅读全文
posted @ 2019-12-22 22:07 离地最远的星 阅读(488) 评论(0) 推荐(0) 编辑
摘要: Client package main import ( "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "github.com/go-kit/kit/sd" "github.com/go-kit/kit/sd/consul" "gi... 阅读全文
posted @ 2019-12-22 22:05 离地最远的星 阅读(830) 评论(0) 推荐(0) 编辑
摘要: 注册初始化代码 package utils import ( "fmt" "github.com/google/uuid" consulapi "github.com/hashicorp/consul/api" "log" "strconv" ) var ConsulClient *consulapi.Client var ServiceID st... 阅读全文
posted @ 2019-12-22 21:47 离地最远的星 阅读(641) 评论(0) 推荐(0) 编辑
摘要: package main import ( "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "github.com/go-kit/kit/sd" "github.com/go-kit/kit/sd/consul" htt... 阅读全文
posted @ 2019-12-22 20:52 离地最远的星 阅读(3211) 评论(0) 推荐(0) 编辑
摘要: TransPoint代码 package Services import ( "context" "encoding/json" "errors" "net/http" "strconv" ) func GetUserInfo_Request(_ context.Context, request *http.Request, r inter... 阅读全文
posted @ 2019-12-22 19:54 离地最远的星 阅读(645) 评论(0) 推荐(0) 编辑
摘要: 注册和反注册代码 package utils import ( consulapi "github.com/hashicorp/consul/api" "log" ) var ConsulClient *consulapi.Client func init() { config := consulapi.DefaultConfig() config.Addr... 阅读全文
posted @ 2019-12-22 18:08 离地最远的星 阅读(742) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 22 下一页