goo_grpc

package
v1.1.135 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

README

服务端

  • Config 配置信息
    • ServiceName 服务名称
    • Addr 服务地址,必须明确 ip:port
  • 信号监控
    • kill -USR1 开启 pprof 监控
    • kill -USR2 停止 pprof 监控,可以获取监控文件
    • kill -1 平滑重启
    • kill -9 退出应用程序,目前监控不到
    • kill -QUIT 退出应用程序
    • ctrl + C 退出应用程序
  • 拦截器
    • grpc.ChainUnaryInterceptor 服务端单向拦截器(也叫"一元拦截器")
      • serverUnaryInterceptorLog() 记录日志信息
      • unaryServerInterceptorAuth() 鉴权处理
        • AuthFunc() 自定义鉴权方法
    • grpc.ChainStreamInterceptor 服务端流式拦截器
      • 同上
  • Register2ETCD() 服务注册到etcd
    • key 格式: /
    • value 格式: json格式,示例 {"Op":0,"Addr":"127.0.0.1:19001","Metadata":null}

客户端

  • Dial() 链接 grpc
  • DialWithEtcd() 通过 etcd 链接 grpc
    • target 格式 etcd:///<service>
  • 返回拦截

grpc 版本要求

最高使用 v1.52.3, 否则导致 Target.Endpoint 无效,因为高版本把属性定义为了方法

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func DialContext added in v1.1.72

func DialContext(ctx context.Context, addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func DialContextWithEtcd added in v1.1.72

func DialContextWithEtcd(ctx context.Context, serviceName string, cli *goo_etcd.Client) (*grpc.ClientConn, error)

func DialWithEtcd added in v1.0.2

func DialWithEtcd(serviceName string, cli *goo_etcd.Client) (*grpc.ClientConn, error)

Types

type AuthFunc added in v1.1.1

type AuthFunc func(md metadata.MD, ctx context.Context, fullMethod string) (context.Context, error)

type Config added in v1.0.2

type Config struct {
	// 服务名称
	ServiceName string `json:"service_name" yaml:"service_name"`

	// 服务地址
	Addr string `json:"addr" yaml:"addr"`
}

type PProf added in v1.1.1

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

type Server

type Server struct {
	*gracenet.Net
	*grpc.Server
	// contains filtered or unexported fields
}

func New

func New(conf Config, opt ...ServerOption) *Server

func (*Server) Register2Etcd added in v1.0.2

func (s *Server) Register2Etcd(cli *goo_etcd.Client) *Server

func (*Server) Serve

func (s *Server) Serve() (err error)

type ServerOption added in v1.1.1

type ServerOption interface {
	// contains filtered or unexported methods
}

定义配置项抽象

func AuthFuncOption added in v1.1.1

func AuthFuncOption(authFunc AuthFunc) ServerOption

配置项 - 认证方法

func ServerOptions added in v1.1.1

func ServerOptions(opt ...grpc.ServerOption) ServerOption

配置项 - grpc server options

Jump to

Keyboard shortcuts

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