Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FoosvcService ¶
Service describes a service that adds things together Implement yor service methods methods. e.x: Foo(ctx context.Context, s string)(rs string, err error)
func New ¶
func New(addsvc addsvcservice.AddsvcService, logger log.Logger, requestCount metrics.Counter, requestLatency metrics.Histogram) (s FoosvcService)
New return a new instance of the service. If you want to add service middleware this is the place to put them.
type HealthImpl ¶
type HealthImpl struct { }
HealthImpl grpc 健康檢查 https://studygolang.com/articles/18737
func (*HealthImpl) Check ¶
func (h *HealthImpl) Check(ctx context.Context, req *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error)
Check 實現健康檢查接口,這裏直接返回健康狀態,這裏也可以有更復雜的健康檢查策略, 比如根據服務器負載來返回 https://github.com/hashicorp/consul/blob/master/agent/checks/grpc.go consul 檢查服務器的健康狀態,consul 用 google.golang.org/grpc/health/grpc_health_v1.HealthServer 接口, 實現了對 grpc健康檢查的支持,所以我們只需要實現先這個接口,consul 就能利用這個接口作健康檢查了
func (*HealthImpl) Watch ¶
func (h *HealthImpl) Watch(req *grpc_health_v1.HealthCheckRequest, w grpc_health_v1.Health_WatchServer) error
Watch HealthServer interface 有兩個方法 Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) Watch(*HealthCheckRequest, Health_WatchServer) error 所以在 HealthImpl 結構提不僅要實現 Check 方法,還要實現 Watch 方法
type Middleware ¶
type Middleware func(FoosvcService) FoosvcService
Middleware describes a service (as opposed to endpoint) middleware.
func InstrumentingMiddleware ¶
func InstrumentingMiddleware(requestCount metrics.Counter, requestLatency metrics.Histogram) Middleware
InstrumentingMiddleware returns a service middleware that instruments the number of integers summed and characters concatenated over the lifetime of the service.
func LoggingMiddleware ¶
func LoggingMiddleware(logger log.Logger) Middleware
LoggingMiddleware takes a logger as a dependency and returns a ServiceMiddleware.