zdpgo_grpc

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT Imports: 8 Imported by: 0

README

zdpgo_grpc

基于GRPC的微服务底层框架

项目地址:https://github.com/zhangdapeng520/zdpgo_grpc

版本历史

  • v0.1.0 2022/05/21 新增:支持权限校验
  • v0.1.1 2022/05/24 优化:模块名变更

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Debug       bool   `yaml:"debug" json:"debug"`                 // 是否为debug模式
	LogFilePath string `yaml:"log_file_path" json:"log_file_path"` // 日志路径
	ListenType  string `yaml:"listen_type" json:"listen"`          // 监听类型:默认tcp,还支持tcp4/tcp6/unix/unixpacket
	Server      Server `yaml:"server" json:"server"`               // 服务器配置
	Client      Server `yaml:"client" json:"client"`               // 客户端配置
}

type Credential

type Credential struct {
	Metadata map[string]string // 校验数据
}

func (Credential) GetRequestMetadata

func (c Credential) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

GetRequestMetadata 设置metadata

func (Credential) RequireTransportSecurity

func (c Credential) RequireTransportSecurity() bool

RequireTransportSecurity 是否使用安全协议

type Grpc

type Grpc struct {
	Log        *zdpgo_log.Log // 日志对象
	Config     *Config        // 配置对象
	Credential *Credential    // 自定义校验对象
}

Grpc 核心对象

func New

func New() *Grpc

func NewWithConfig

func NewWithConfig(config *Config) *Grpc

func (*Grpc) CloseClient

func (g *Grpc) CloseClient(conn *grpc.ClientConn)

func (*Grpc) GetAuthInterceptor

func (g *Grpc) GetAuthInterceptor(username, password string) grpc.ServerOption

GetAuthInterceptor 设置权限校验拦截器

func (*Grpc) GetClientConn

func (g *Grpc) GetClientConn() (conn *grpc.ClientConn, err error)

GetClientConn 获取GRPC客户端连接

func (*Grpc) GetInterceptor

func (g *Grpc) GetInterceptor(beforeFunc func(ctx context.Context) error, afterFunc func(ctx context.Context)) grpc.ServerOption

GetInterceptor 获取拦截器

func (*Grpc) RunServer

func (g *Grpc) RunServer(
	registerFunc func(grpcServerRegister grpc.ServiceRegistrar, implGrpcServer interface{}),
	implServerArg interface{},
	interceptors ...grpc.ServerOption,
)

RunServer 运行GRPC服务

type Server

type Server struct {
	Host string `yaml:"host" json:"host"` // 主机地址
	Port int    `yaml:"port" json:"port"` // 端口号
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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