http_proxy

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusClosed   = iota //服务已经关闭
	StatusResolved        //服务正在运行
	StatusUpdating        //服务正在更新
	StatusClosing         //服务正在关闭
)

Variables

View Source
var (
	ErrInvalidHttpAddress     = errors.New("invalid http address ")
	ErrNoEffectiveServicePath = errors.New("no effective service config path ")
	ErrInitServiceDBError     = errors.New("create service data base error ")
	ErrRequestNotFound        = errors.New("http call info not found ")
	ErrRequestExpired         = errors.New("the http request has expired ")
	ErrRoutePathExist         = errors.New("route path already exists")
	ErrCertificateNotExist    = errors.New("certificate file does not exist")
	ErrInvalidTokenType       = errors.New("invalid token type")
)

Functions

func SemicolonMiddleware

func SemicolonMiddleware() gin.HandlerFunc

Types

type AuthOption added in v0.4.31

type AuthOption struct {
	Enable        bool   `yaml:"enable"`          //Enable 是否开启校验
	PublicKeyPath string `yaml:"public_key_path"` //PublicKeyPath 公钥路径
	AuthHeader    string `yaml:"auth_header"`     //AuthHeader http头部中用于鉴权的字段名
	TokenType     string `yaml:"token_type"`      //TokenType token 类型 如 Bearer
}

func NewAuthOption added in v0.4.31

func NewAuthOption() *AuthOption

type Authenticator

type Authenticator func(ctx *Context) error

Authenticator 鉴权函数Handle

type CallQueue

type CallQueue chan *requestInfo

CallQueue http 调用请求队列

type Context

type Context struct {
	*gin.Context
	// contains filtered or unexported fields
}

Context http_proxy 上下文,对外屏蔽内部使用的框架, 便于框架内部迭代而不影响外部api

func (*Context) GetRpcContext added in v0.5.3

func (ctx *Context) GetRpcContext() *RpcContext

func (*Context) SetRpcContext added in v0.5.3

func (ctx *Context) SetRpcContext(key string, value string)

type GroupRouteInfo added in v0.4.19

type GroupRouteInfo struct {
	Method string      // method type, GET POST PUT
	Path   string      //API 路径
	Handle RouteHandle //处理函数
}

GroupRouteInfo 添加GroupAPI

type HttpProxy

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

HttpProxy http 代理,启动http服务器,将收到http 转化为 plato rpc协议

func MakeHttpProxy

func MakeHttpProxy(opts ...Option) *HttpProxy

func (*HttpProxy) AddGroupRoute added in v0.4.19

func (hp *HttpProxy) AddGroupRoute(groupName string, auth Authenticator, routes ...*GroupRouteInfo) error

AddGroupRoute 添加自定义groupName, 使用auth 函数对组内所有 handle api进行鉴权, 鉴权函数可以为空

func (*HttpProxy) AddRoute added in v0.4.19

func (hp *HttpProxy) AddRoute(method string, path string, handle RouteHandle, auth Authenticator) error

AddRoute 添加自定义的API路径path, 执行函数handle, 以及是否需要使用auth 进行鉴权,鉴权函数可以为空

func (*HttpProxy) Init

func (hp *HttpProxy) Init(option *Options) error

Init 初始化配置

func (*HttpProxy) IsResolved

func (hp *HttpProxy) IsResolved() bool

IsResolved 返回是否可以正常提供服务的状态

func (*HttpProxy) OnRpcResponse

func (hp *HttpProxy) OnRpcResponse(ret *protocol.ProxyRespPackage) error

func (*HttpProxy) SetHttpRequestHandle

func (hp *HttpProxy) SetHttpRequestHandle(handle ProxyRequestHandle)

func (*HttpProxy) SetOptions added in v0.4.31

func (hp *HttpProxy) SetOptions(options ...Option)

func (*HttpProxy) ShutDown

func (hp *HttpProxy) ShutDown()

func (*HttpProxy) Start

func (hp *HttpProxy) Start() error

func (*HttpProxy) Tick

func (hp *HttpProxy) Tick()

type JWTAuthenticator added in v0.4.31

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

JWTAuthenticator JWT Token校验鉴权工具,框架内置默认的鉴权工具

func NewJWTAuthenticator added in v0.4.31

func NewJWTAuthenticator(opt *AuthOption) *JWTAuthenticator

func (*JWTAuthenticator) Authenticate added in v0.4.31

func (t *JWTAuthenticator) Authenticate(ctx *Context) error

type Option

type Option func(options *Options)

Option 设置函数

func WithAuthenticator added in v0.4.31

func WithAuthenticator(authenticator Authenticator) Option

func WithCustomLogger

func WithCustomLogger(logger slog.BoxLogger) Option

func WithJwtAuthenticator added in v0.4.31

func WithJwtAuthenticator(authOpt *AuthOption) Option

type Options

type Options struct {
	Address         string `yaml:"address"`          //监听地址
	ServicePath     string `yaml:"service_path"`     //服务配置路径
	Mode            string `yaml:"mode"`             //运行模式 debug release
	ShutdownTimeout uint32 `yaml:"shutdown_timeout"` //停机超时时间, 单位毫秒
	CacheSize       uint32 `yaml:"cache_size"`       //命令排队数量,默认是1024,框架处理速率是每秒 5000 条命令左右 不应该有太多堆积
	SSLKey          string `yaml:"ssl_key"`          //https 私聊
	SSLPem          string `yaml:"ssl_pem"`          //https 证书
	InternalMode    bool   `yaml:"internal_mode"`    //内部模式
	PbVersion       int    `yaml:"pb_version"`       //pb版本
	// contains filtered or unexported fields
}

Options http proxy 模块配置

func NewDefaultOptions added in v0.4.24

func NewDefaultOptions() *Options

type ProxyRequestHandle

type ProxyRequestHandle func(req *protocol.ProxyRequestPackage) (uint32, error)

ProxyRequestHandle http 请求转换为rpc 请求后回调函数 成功返回 call id 和 nil 错误; 失败 则返回0 和具体错误

type ProxyWriter

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

ProxyWriter 日志包装器

func (*ProxyWriter) Write

func (pw *ProxyWriter) Write(p []byte) (n int, err error)

type Response

type Response map[string]interface{}

Response http 回包结构

type RouteHandle

type RouteHandle func(*Context)

RouteHandle 自定义 api 方法处理原型,在独立协程中运行

type RpcContext added in v0.5.3

type RpcContext struct {
	Context map[string]string `json:"context"`
}

Jump to

Keyboard shortcuts

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