摘要: 限流代码 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) 编辑
摘要: 编写注册函数 package utils import ( consulapi "github.com/hashicorp/consul/api" "log" ) func RegService() { config := consulapi.DefaultConfig() config.Address = "192.168.3.14:8500" re... 阅读全文
posted @ 2019-12-22 17:41 离地最远的星 阅读(1732) 评论(0) 推荐(0) 编辑
摘要: package main import ( httptransport "github.com/go-kit/kit/transport/http" mymux "github.com/gorilla/mux" "gomicro/Services" "net/http" ) func main() { user := Services.UserService{} ... 阅读全文
posted @ 2019-12-22 10:48 离地最远的星 阅读(1314) 评论(0) 推荐(0) 编辑