service

package
Version: v0.0.0-...-235258f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTwoZeroes is an arbitrary business rule for the Add method.
	ErrTwoZeroes = errors.New("can't sum two zeroes")

	// ErrIntOverflow protects the Add method. We've decided that this error
	// indicates a misbehaving service and should count against e.g. circuit
	// breakers. So, we return it directly in endpoints, to illustrate the
	// difference. In a real service, this probably wouldn't be the case.
	ErrIntOverflow = errors.New("integer overflow")

	// ErrMaxSizeExceeded protects the Concat method.
	ErrMaxSizeExceeded = errors.New("result exceeds maximum size")
)

Functions

This section is empty.

Types

type AddsvcService

type AddsvcService interface {
	Sum(ctx context.Context, a int64, b int64) (rs int64, err error)
	Concat(ctx context.Context, a string, b string) (rs string, err error)
}

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(logger log.Logger, requestCount metrics.Counter, requestLatency metrics.Histogram) (s AddsvcService)

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

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

Watch HealthServer interface 有兩個方法 Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) Watch(*HealthCheckRequest, Health_WatchServer) error 所以在 HealthImpl 結構提不僅要實現 Check 方法,還要實現 Watch 方法

type Middleware

type Middleware func(AddsvcService) AddsvcService

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL