service

package
v0.0.0-...-18bf7b2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(h Handler)

Register with the same name, the one registered last will take effect.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client struct

func CreateConnection

func CreateConnection(consulAddr string, serviceName string) (*Client, error)

CreateConnection with gRPC

func (*Client) Close

func (cli *Client) Close() error

Close grpc connection closed

func (*Client) SendJSON

func (cli *Client) SendJSON(traceID uint64, seqID uint64, path string, data []byte, timeout uint) (rTraceID uint64, rSeqID uint64, rData []byte)

SendJSON message

func (*Client) SendSocket

func (cli *Client) SendSocket(node string, socketID uint32, ipAddr string, traceID uint64, seqID uint64, cmd uint32, data []byte, timeout uint) (code uint32, rTraceID uint64, rSeqID uint64, rCmd uint32, rData []byte)

SendSocket message

type Handler

type Handler interface {
	HandleCmd(node string, socketID uint32, ipAddr string, cmd uint32, data []byte) (code uint32, reply []byte)
	HandleJSON(path string, data []byte) (relpy []byte)
}

Handler creates a service handler that will be used to handle message.

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 Service

type Service struct {
	// contains filtered or unexported fields
}

Service detail

func CreateService

func CreateService(consulAddr string, port int, name string, tags []string) (*Service, error)

CreateService serive

func (*Service) Start

func (s *Service) Start()

Start loop

func (*Service) Stop

func (s *Service) Stop()

Stop service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL