goku

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PRE_SIGNAL = iota
	POST_SIGNAL

	STATE_INIT
	STATE_RUNNING
	STATE_SHUTTING_DOWN
	STATE_TERMINATE
)

Variables

View Source
var (
	DefaultReadTimeOut    time.Duration
	DefaultWriteTimeOut   time.Duration
	DefaultMaxHeaderBytes int
	DefaultHammerTime     time.Duration
)

Functions

func CleanPath

func CleanPath(p string) string

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler) error

ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections. Handler is typically nil, in which case the DefaultServeMux is used.

func ListenAndServeTLS

func ListenAndServeTLS(addr string, certFile string, keyFile string, handler http.Handler) error

ListenAndServeTLS acts identically to ListenAndServe, except that it expects HTTPS connections. Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate followed by the CA's certificate.

func NewServer

func NewServer(addr string, handler http.Handler) (srv *endlessServer)

NewServer returns an intialized endlessServer Object. Calling Serve on it will actually "start" the server.

Types

type Api

type Api struct {
	RequestURL     string               `json:"request_url" yaml:"request_url"`
	BackendPath    string               `json:"backend_path" yaml:"backend_path"`
	ProxyURL       string               `json:"proxy_url" yaml:"proxy_url"`
	ProxyMethod    string               `json:"proxy_method" yaml:"proxy_method"`
	IsRaw          bool                 `json:"is_raw" yaml:"is_raw"`
	ProxyParams    []conf.Param         `json:"proxy_params" yaml:"proxy_params"`
	ConstantParams []conf.ConstantParam `json:"constant_params" yaml:"constant_params"`
	Follow         bool                 `json:"follow" yaml:"follow"`
}

type Context

type Context struct {
	GatewayInfo  Gateway
	StrategyInfo Strategy
	ApiInfo      Api
	Rate         map[string]Rate
	VisitCount   *Count
}

type Count

type Count struct {
	SuccessCount LimitRate
	FailureCount LimitRate
	TotalCount   LimitRate
	CurrentCount LimitRate
}

type Gateway

type Gateway struct {
	GatewayAlias  string   `json:"gateway_alias" yaml:"gateway_alias"`
	GatewayStatus string   `json:"gateway_status" yaml:"gateway_status"`
	IPLimitType   string   `json:"ip_limit_type" yaml:"ip_limit_type"`
	IPWhiteList   []string `json:"ip_white_list" yaml:"ip_white_list"`
	IPBlackList   []string `json:"ip_black_list" yaml:"ip_black_list"`
}

type Goku

type Goku struct {
	*Router

	ServiceConfig conf.GlobalConfig
	// contains filtered or unexported fields
}

func New

func New() *Goku

启动一个Goku实例

func (*Goku) Address

func (g *Goku) Address() string

func (*Goku) Listen

func (g *Goku) Listen() error

func (*Goku) Listener

func (g *Goku) Listener() net.Listener

func (*Goku) SetListener

func (g *Goku) SetListener(listener net.Listener)

func (*Goku) Stop

func (s *Goku) Stop()

type GokuServer

type GokuServer interface {
	Run() error
	Address() string
	Listener() net.Listener
	Listen() error
}

type Handle

type Handle func(http.ResponseWriter, *http.Request, Params, *Context)

Handle是一个可以被注册到路由中去处理http请求,类似于HandlerFunc,但是有第三个参数值

type LimitRate

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

LimitRate 限速

func (*LimitRate) DayLimit

func (l *LimitRate) DayLimit() bool

Limit Limit

func (*LimitRate) GetCount

func (l *LimitRate) GetCount() int

func (*LimitRate) HourLimit

func (l *LimitRate) HourLimit() bool

Limit Limit

func (*LimitRate) IsNeedReset

func (l *LimitRate) IsNeedReset() bool

判断是否需要重置

func (*LimitRate) MinLimit

func (l *LimitRate) MinLimit() bool

Limit Limit

func (*LimitRate) SecLimit

func (l *LimitRate) SecLimit() bool

Limit Limit

func (*LimitRate) SetRate

func (l *LimitRate) SetRate(rate int, end int, rateType string)

func (*LimitRate) UpdateCurrentCount

func (l *LimitRate) UpdateCurrentCount()

func (*LimitRate) UpdateDayCount

func (l *LimitRate) UpdateDayCount()

type Param

type Param struct {
	Key   string
	Value string
}

Param is a single URL parameter, consisting of a key and a value.

type Params

type Params []Param

Params是一个参数切片,作为路由的返回结果,这个切片是有序的 第一个URL参数会作为第一个切片值,因此通过索引来读值是安全的

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 Rate

type Rate struct {
	SecLimit    LimitRate
	MinuteLimit LimitRate
	HourLimit   LimitRate
	DayLimit    LimitRate
	IsInit      bool
	Limit       string
}

type Router

type Router struct {
	RedirectTrailingSlash bool

	RedirectFixedPath bool

	HandleMethodNotAllowed bool

	HandleOPTIONS bool

	NotFound http.Handler

	MethodNotAllowed http.Handler

	PanicHandler func(http.ResponseWriter, *http.Request, interface{})
	// contains filtered or unexported fields
}

Router是一个可以被用来调度请求去不同处理函数的Handler

func NewRouter

func NewRouter() *Router

func (*Router) Handle

func (r *Router) Handle(method, path string, handle Handle, context Context)

func (*Router) Lookup

func (r *Router) Lookup(method, path string) (Handle, Params, *Context, bool)

查找允许手动查找方法 + 路径组合。 这对于构建围绕此路由器的框架非常有用。 如果找到路径, 它将返回句柄函数和路径参数值 否则, 第三个返回值指示是否应执行与附加/不带尾随斜线的同一路径的重定向

func (*Router) RegisterRouter

func (r *Router) RegisterRouter(c conf.GlobalConfig, handle ...Handle)

注册路由

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP使用路由实现http.Handler接口

func (*Router) Use

func (r *Router) Use(handle Handle)

type Strategy

type Strategy struct {
	StrategyID        string               `json:"strategy_id" yaml:"strategy_id"`
	Auth              string               `json:"auth" yaml:"auth"`
	BasicUserName     string               `json:"basic_user_name" yaml:"basic_user_name"`
	BasicUserPassword string               `json:"basic_user_password" yaml:"basic_user_password"`
	ApiKey            string               `json:"api_key" yaml:"api_key"`
	IPLimitType       string               `json:"ip_limit_type" yaml:"ip_limit_type"`
	IPWhiteList       []string             `json:"ip_white_list" yaml:"ip_white_list"`
	IPBlackList       []string             `json:"ip_black_list" yaml:"ip_black_list"`
	RateLimitList     []conf.RateLimitInfo `json:"rate_limit_list" yaml:"rate_limit_list"`
}

Jump to

Keyboard shortcuts

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