runtime

package
v0.0.0-...-95af3ef Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const Cluster_Static = "-" //静态资源
View Source
const Cluster_This = "." //本地插件

Variables

This section is empty.

Functions

func GetRealClientIP

func GetRealClientIP(ctx *fasthttp.RequestCtx) string

func GetRuntimeContext

func GetRuntimeContext(api *meta.Api) *runtimeContext

func Hashcode

func Hashcode(s string) int

func Log

func Log(text string)

func PathExists

func PathExists(path string) bool

func SetAccessLogger

func SetAccessLogger(log core.AccessLogger)

Types

type AccessLogIntercepter

type AccessLogIntercepter struct {
	BaseIntercepter
	// contains filtered or unexported fields
}

访问日志

func (*AccessLogIntercepter) After

func (this *AccessLogIntercepter) After(api *meta.Api, id uint64, ctx *fasthttp.Response) (bool, error)

func (*AccessLogIntercepter) Before

func (this *AccessLogIntercepter) Before(api *meta.Api, ctx *fasthttp.RequestCtx) (bool, error)

type AuthIntercepter

type AuthIntercepter struct {
	BaseIntercepter
}

鉴权拦截器

func (*AuthIntercepter) Before

func (this *AuthIntercepter) Before(api *meta.Api, ctx *fasthttp.RequestCtx) (bool, error)

type BaseIntercepter

type BaseIntercepter struct {
}

抽象拦截器

func (*BaseIntercepter) After

func (this *BaseIntercepter) After(api *meta.Api, id uint64, ctx *fasthttp.Response) (bool, error)

func (*BaseIntercepter) Before

func (this *BaseIntercepter) Before(api *meta.Api, ctx *fasthttp.RequestCtx) (bool, error)

func (*BaseIntercepter) Release

func (this *BaseIntercepter) Release(api *meta.Api, ctx *fasthttp.RequestCtx) (bool, error)

type CiruitStatus

type CiruitStatus byte
const (
	CS_OPEN  CiruitStatus = 2 //熔断打开
	CS_CLOSE CiruitStatus = 0 //熔断关闭
	CS_HALF  CiruitStatus = 1 //熔断半打开状态

)

type DefaultRouter

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

路由器

type DispatchManager

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

func (*DispatchManager) AddApi

func (this *DispatchManager) AddApi(domain, clusterName string, api *meta.Api)

新增api

func (*DispatchManager) AddCluster

func (this *DispatchManager) AddCluster(cluster *meta.ServerCluster)

新增集群

func (*DispatchManager) AddServer

func (this *DispatchManager) AddServer(clusterName string, server *meta.Server)

新增服务器

func (*DispatchManager) DelApi

func (this *DispatchManager) DelApi(api *meta.Api)

删除Api

func (*DispatchManager) DelCluster

func (this *DispatchManager) DelCluster(name string)

删除集群

func (*DispatchManager) DelServer

func (this *DispatchManager) DelServer(clusterName string, id int64)

删除服务器

func (*DispatchManager) GetApi

func (this *DispatchManager) GetApi(domain, url string) *meta.Api

根据域名和url获取对应的API

func (*DispatchManager) GetCluster

func (this *DispatchManager) GetCluster(name string) *meta.ServerCluster

获取集群

func (*DispatchManager) Init

func (this *DispatchManager) Init()

type FastHTTPClient

type FastHTTPClient struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

FastHTTPClient fast http client

func NewFastHTTPClient

func NewFastHTTPClient() *FastHTTPClient

NewFastHTTPClient create FastHTTPClient instance

func NewFastHTTPClientOption

func NewFastHTTPClientOption(defaultOption *HTTPOption) *FastHTTPClient

NewFastHTTPClientOption create FastHTTPClient instance with default option

func (*FastHTTPClient) Do

func (c *FastHTTPClient) Do(req *fasthttp.Request, addr string, option *HTTPOption) (*fasthttp.Response, error)

Do do a http request

type HTTPOption

type HTTPOption struct {
	// Maximum number of connections which may be established to server
	MaxConns int
	// MaxConnDuration Keep-alive connections are closed after this duration.
	MaxConnDuration time.Duration
	// MaxIdleConnDuration Idle keep-alive connections are closed after this duration.
	MaxIdleConnDuration time.Duration
	// ReadBufferSize Per-connection buffer size for responses' reading.
	ReadBufferSize int
	// WriteBufferSize Per-connection buffer size for requests' writing.
	WriteBufferSize int
	// ReadTimeout Maximum duration for full response reading (including body).
	ReadTimeout time.Duration
	// WriteTimeout Maximum duration for full request writing (including body).
	WriteTimeout time.Duration
	// MaxResponseBodySize Maximum response body size.
	MaxResponseBodySize int
}

HTTPOption http client option

func DefaultHTTPOption

func DefaultHTTPOption() *HTTPOption

DefaultHTTPOption returns a HTTP Option

type Handle

type Handle interface{}

type HandlePlugin

type HandlePlugin func(req *fasthttp.Request) *fasthttp.Response

内部处理插件

type HttpConfig

type HttpConfig struct {
	Root string
	Port int
}

type HttpProxy

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

基本的代理

func (*HttpProxy) AddIntercepter

func (this *HttpProxy) AddIntercepter(i Intercepter)

func (*HttpProxy) AddPlugin

func (this *HttpProxy) AddPlugin(name string, plugin HandlePlugin)

func (*HttpProxy) Init

func (this *HttpProxy) Init(dispatch *DispatchManager)

func (*HttpProxy) ServeHTTP

func (this *HttpProxy) ServeHTTP(ctx *fasthttp.RequestCtx)

func (*HttpProxy) SetConfig

func (this *HttpProxy) SetConfig(config HttpConfig)

配置

func (*HttpProxy) Start

func (this *HttpProxy) Start()

type IPHash

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

*

ip hash loadbalance

func (*IPHash) Config

func (this *IPHash) Config(p string)

func (IPHash) Select

func (rr IPHash) Select(req *fasthttp.RequestCtx, servers *[]*meta.Server) *meta.Server

type Intercepter

type Intercepter interface {
	Before(api *meta.Api, ctx *fasthttp.RequestCtx) (bool, error)         //调用之前
	After(api *meta.Api, id uint64, ctx *fasthttp.Response) (bool, error) //调用完成之后
	Release(api *meta.Api, ctx *fasthttp.RequestCtx) (bool, error)        //网关完成返回处理完之后释放资源
}

type LimitIntercepter

type LimitIntercepter struct {
	BaseIntercepter
}

限流拦截器

func (*LimitIntercepter) Before

func (this *LimitIntercepter) Before(api *meta.Api, ctx *fasthttp.RequestCtx) (bool, error)

type LoadBalance

type LoadBalance interface {
	Config(p string)
	Select(req *fasthttp.RequestCtx, servers *[]*meta.Server) *meta.Server
}

负载均衡器

func NewRoundRobin

func NewRoundRobin() LoadBalance

type Param

type Param struct {
	Key   string
	Value string
}

type Params

type Params []Param

Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.

func (Params) ByName

func (ps Params) ByName(name string) string

ByName returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.

type PluginType

type PluginType byte
const (
	PT_Balance PluginType = 10 //负载均衡插件类型
	PT_Handle  PluginType = 11 //内部服务插件

)

func ParsePluginType

func ParsePluginType(pt string) PluginType

type QPSCount

type QPSCount struct {
	Max int64
	// contains filtered or unexported fields
}

QPS记录器

func (*QPSCount) Count

func (this *QPSCount) Count() int64

func (QPSCount) Incr

func (this QPSCount) Incr() bool

计数

func (*QPSCount) Init

func (this *QPSCount) Init()

type RoundRobin

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

*

随机均衡负载器

func (*RoundRobin) Config

func (this *RoundRobin) Config(p string)

func (RoundRobin) Select

func (rr RoundRobin) Select(req *fasthttp.RequestCtx, servers *[]*meta.Server) *meta.Server

Select select a server from servers using RoundRobin

type SimpleDispatch

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

*

dispatch

func (*SimpleDispatch) AddUrl

func (this *SimpleDispatch) AddUrl(url string, handle interface{})

func (*SimpleDispatch) GetUrl

func (this *SimpleDispatch) GetUrl(url string) interface{}

func (*SimpleDispatch) Init

func (this *SimpleDispatch) Init()

type TagLoadBalance

type TagLoadBalance struct {
	Tag string //tag
	// contains filtered or unexported fields
}

根据标签进行处理

func (*TagLoadBalance) Config

func (this *TagLoadBalance) Config(p string)

func (*TagLoadBalance) Select

func (this *TagLoadBalance) Select(req *fasthttp.RequestCtx, servers *[]*meta.Server) *meta.Server

Jump to

Keyboard shortcuts

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