摘要:
首先放上httptransport.NewServer的源碼 func NewServer( e endpoint.Endpoint, dec DecodeRequestFunc, enc EncodeResponseFunc, options ...ServerOption, //这里的不定长参数可以用来自定义错误处理 ) *Server { s := ... 阅读全文
摘要:
限流代码 package Services import ( "context" "errors" "fmt" "github.com/go-kit/kit/endpoint" "golang.org/x/time/rate" "gomicro/utils" "strconv" ) type UserRequest struct { /... 阅读全文
摘要:
package main import ( "fmt" "golang.org/x/time/rate" "time" ) func main() { r := rate.NewLimiter(1, 5) //1表示每次放进筒内的数量,桶内的令牌数是5,最大令牌数也是5,这个筒子是自动补充的,你只要取了令牌不管你取多少个,这里都会在每次取完后自动加1个进来,因为... 阅读全文
摘要:
package main import ( "context" "fmt" "golang.org/x/time/rate" "log" "time" ) func main() { r := rate.NewLimiter(1, 5) //1表示每次放进筒内的数量,桶内的令牌数是5,最大令牌数也是5,这个筒子是自动补充的,你只要... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
注册初始化代码 package utils import ( "fmt" "github.com/google/uuid" consulapi "github.com/hashicorp/consul/api" "log" "strconv" ) var ConsulClient *consulapi.Client var ServiceID st... 阅读全文
摘要:
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... 阅读全文
摘要:
TransPoint代码 package Services import ( "context" "encoding/json" "errors" "net/http" "strconv" ) func GetUserInfo_Request(_ context.Context, request *http.Request, r inter... 阅读全文
摘要:
注册和反注册代码 package utils import ( consulapi "github.com/hashicorp/consul/api" "log" ) var ConsulClient *consulapi.Client func init() { config := consulapi.DefaultConfig() config.Addr... 阅读全文