http_proxy

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2023 License: MIT Imports: 20 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")
)

Functions

func SemicolonMiddleware

func SemicolonMiddleware() gin.HandlerFunc

func SetAuthHandle

func SetAuthHandle(auth Authenticator)

Types

type Authenticator

type Authenticator func(ctx *Context) error

Authenticator 鉴权函数Handle

type CallQueue

type CallQueue chan *requestInfo

CallQueue http 调用请求队列

type Context

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

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

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

func (*Context) GetRawData

func (c *Context) GetRawData() ([]byte, error)

func (*Context) Set

func (c *Context) Set(key string, value interface{})

func (*Context) SetErr

func (c *Context) SetErr(err error)

func (*Context) SetHeader added in v0.4.19

func (c *Context) SetHeader(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) ShutDown

func (hp *HttpProxy) ShutDown()

func (*HttpProxy) Start

func (hp *HttpProxy) Start() error

func (*HttpProxy) Tick

func (hp *HttpProxy) Tick()

type Option

type Option func(options *Options)

Option 设置函数

func WithCustomLogger

func WithCustomLogger(logger slog.BoxLogger) Option

type Options

type Options struct {
	Address         string `yaml:"address"`          //监听地址
	Auth            string `yaml:"auth"`             //鉴权类型,留空不开启鉴权
	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 证书
	// contains filtered or unexported fields
}

Options http proxy 模块配置

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) (int, Response)

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

Jump to

Keyboard shortcuts

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