grpc_frame

package module
v0.0.0-...-f961e09 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

README

grpc-frame

采用grpc封装的frame

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB     *gorm.DB
	DBList = make(map[string]*gorm.DB)

	Redis *redis.Client
)

Functions

func HttpErrorHandler

func HttpErrorHandler(ctx context.Context, mux *runtime.ServeMux, m runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error)

func HttpSuccHandler

func HttpSuccHandler(ctx context.Context, w http.ResponseWriter, p proto.Message) error

Types

type ServerConfig

type ServerConfig struct {
	Path           string //配置类型:file->本地配置文件;consul->consul配置中心
	Type           string //配置路径: 如./config/config_develop.yaml 或 http://192.168.3.91:8500
	Token          string //consul的token,type=file时为空
	KvPath         string //consul的远程key/value路径
	RemoteType     string //consul远程配置类型,如:yaml、json、hcl
	GrpcServer     *grpc.Server
	GatewayService *http.Server
	GatewayConn    *grpc.ClientConn
	GatewayMux     *runtime.ServeMux
	Interceptors   []grpc.ServerOption //拦截器
	ServeMuxOption []runtime.ServeMuxOption
}

func (*ServerConfig) Gorm

func (t *ServerConfig) Gorm() *ServerConfig

Gorm 初始化gorm

func (*ServerConfig) GrpcGateway

func (t *ServerConfig) GrpcGateway() *ServerConfig

GrpcGateway 初始化grpc-gateway(前提需要先开启grpc服务)

func (*ServerConfig) Init

func (t *ServerConfig) Init() *ServerConfig

Init 初始化配置,包括:初始化gorm、redis、zap日志等等初始化行为

func (*ServerConfig) Redis

func (t *ServerConfig) Redis() *ServerConfig

Redis 初始化redis

func (*ServerConfig) RunGrpc

func (t *ServerConfig) RunGrpc()

RunGrpc 开启并运行grpc服务

func (*ServerConfig) RunGrpcGateway

func (t *ServerConfig) RunGrpcGateway(middleware ...func(next http.Handler) http.Handler)

RunGrpcGateway 开启并运行grpc-gateway服务(前提需要通过ServerConfig.GrpcGateway()进行初始化)

func (*ServerConfig) Wait

func (t *ServerConfig) Wait()

Wait 等待并阻塞和实现优雅关闭服务

type StandardResp

type StandardResp struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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