jsonpb

package
v0.5.25 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnSupportCoderType = errors.New("unkown jsonpn coder type")
	InvalidConfigPath  = errors.New("invalid service config path")
)

Functions

func RegisterToFactory

func RegisterToFactory(name string, factoryFunc FactoryFunc)

RegisterToFactory 注册JsonPbCoder的类型

Types

type FactoryFunc added in v0.5.20

type FactoryFunc func(...Option) (IJsonPbCoder, error)

FactoryFunc 工厂函数原型

type IJsonPbCoder

type IJsonPbCoder interface {
	//Init 初始化coder 模块
	Init(...Option) error
	//Restart 重启整个模块,会重新加载配置
	Restart() error
	//JsonStrToProtoBuffer json 请求字符串转化为pb 序列化字节流
	JsonStrToProtoBuffer(string, string, string) ([]byte, error)
	//JsonStrToProtoBufferWithContext json 请求字符串转化为pb 序列化字节流, 附带填充context信息
	JsonStrToProtoBufferWithContext(string, string, string, string) ([]byte, error)
	//ProtoBufferToJson pb 字节流 转化为 json 格式
	ProtoBufferToJson(string, string, []byte) (string, error)
	//UnInit 卸载coder 模块
	UnInit() error
}

IJsonPbCoder json string to pb 的编码器

func MakeJsonPbWithType

func MakeJsonPbWithType(name string, opts ...Option) (IJsonPbCoder, error)

MakeJsonPbWithType 根据类型创建jsonpb转码器

type Option

type Option func(options *Options)

Option 设置函数

func WithConfigPath

func WithConfigPath(path string) Option

func WithPbVersion added in v0.5.7

func WithPbVersion(version int) Option

type Options

type Options struct {
	//CfgPath 加载配置路径
	CfgPath string `yaml:"cfg_path"`
	//pbVersion pb版本
	PbVersion int `yaml:"pb_version"`
}

Options 模块配置

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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