上一页 1 2 3 4 5 6 7 8 9 ··· 22 下一页
摘要: 使用中间件的方式包装日志输出 package Services import ( "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "golang.org/x/time/rate" "gomicro/utils" "strconv" )... 阅读全文
posted @ 2019-12-24 00:51 离地最远的星 阅读(794) 评论(0) 推荐(0) 编辑
摘要: package Services import ( "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "golang.org/x/time/rate" "gomicro/utils" "os" "strconv" ) typ... 阅读全文
posted @ 2019-12-23 23:15 离地最远的星 阅读(492) 评论(0) 推荐(0) 编辑
摘要: 熔断器一般部署在客户端或者网关里面 封装到服务端 package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "gomicro2/util" "log" "time" ) func main() { configA := hystrix.CommandConfig{... 阅读全文
posted @ 2019-12-23 21:57 离地最远的星 阅读(378) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "sync" "time" ) type Product struct { ID int Title string Price int } func getPro... 阅读全文
posted @ 2019-12-23 19:35 离地最远的星 阅读(1606) 评论(0) 推荐(0) 编辑
摘要: 熔断器控制最大并发数 package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "sync" "time" ) type Product struct { ID int Title string Price int } fun... 阅读全文
posted @ 2019-12-23 16:41 离地最远的星 阅读(421) 评论(0) 推荐(0) 编辑
摘要: 异步执行和服务降级,使用hystrix.Go()函数的返回值是chan err package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "time" ) type Product struct { ID int Title string ... 阅读全文
posted @ 2019-12-23 16:05 离地最远的星 阅读(345) 评论(0) 推荐(0) 编辑
摘要: 在hystrix的超时回调函数中处理超时推荐其他商品 package main import ( "errors" "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "time" ) type Product struct { ID int Title string ... 阅读全文
posted @ 2019-12-23 15:51 离地最远的星 阅读(408) 评论(0) 推荐(0) 编辑
摘要: ## 使用hystrix来实现监控超时 ```go package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "time" ) type Product struct { ID int Title string Price int... 阅读全文
posted @ 2019-12-23 15:34 离地最远的星 阅读(793) 评论(0) 推荐(0) 编辑
摘要: 简单来说就是浏览器想要拿到最终的结果需要需要经过A,B,C三个节点,A调用B,B调用C最终返回结果,但是如果C崩溃了,我们应该怎么做呢 先模拟一个延迟调用的例子 package main import ( "fmt" "math/rand" "time" ) type Product struct { ID int Title st... 阅读全文
posted @ 2019-12-23 15:20 离地最远的星 阅读(333) 评论(0) 推荐(0) 编辑
摘要: 自定义错误结构体 package utils type MyError struct { Code int Message string } func NewMyError(code int, msg string) error { return &MyError{Code: code, Messa 阅读全文
posted @ 2019-12-23 14:31 离地最远的星 阅读(383) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 22 下一页