goku_plugin

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

goku-plugin

goku网关自定义插件实现接口

Documentation

Index

Constants

View Source
const (
	MultipartForm  = "multipart/form-data"
	FormData       = "application/x-www-form-urlencoded"
	TEXT           = "text/plain"
	JSON           = "application/json"
	JavaScript     = "application/javascript"
	AppLicationXML = "application/xml"
	TextXML        = "text/xml"
	Html           = "text/html"
)

Variables

This section is empty.

Functions

func Debug added in v0.1.3

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard _logger.

func Debugf added in v0.1.3

func Debugf(format string, args ...interface{})

Debugf logs a message at level Debug on the standard _logger.

func Error added in v0.1.3

func Error(args ...interface{})

Error logs a message at level Error on the standard _logger.

func Errorf added in v0.1.3

func Errorf(format string, args ...interface{})

Errorf logs a message at level Error on the standard _logger.

func Info added in v0.1.3

func Info(args ...interface{})

Info logs a message at level Info on the standard _logger.

func Infof added in v0.1.3

func Infof(format string, args ...interface{})

Infof logs a message at level Info on the standard _logger.

func InitLog added in v0.1.3

func InitLog(logger Logger)

func SetRedisManager

func SetRedisManager(manager RedisManager)

func Version added in v0.1.2

func Version() string

func Warn added in v0.1.3

func Warn(args ...interface{})

Warn logs a message at level Warn on the standard _logger.

func Warnf added in v0.1.3

func Warnf(format string, args ...interface{})

Warnf logs a message at level Warn on the standard _logger.

func Warning added in v0.1.3

func Warning(args ...interface{})

Warning logs a message at level Warn on the standard _logger.

func Warningf added in v0.1.3

func Warningf(format string, args ...interface{})

Warningf logs a message at level Warn on the standard _logger.

Types

type Body

type Body interface {
	BodyDataReader
	BodyDatawriter
}

type BodyDataReader

type BodyDataReader interface {

	//Protocol() RequestType
	ContentType() string
	//content-Type = application/x-www-form-urlencoded 或 multipart/form-data,与原生request.Form不同,这里不包括 query 参数
	BodyForm() (url.Values, error)
	//content-Type = multipart/form-data 时有效
	Files() (map[string]*FileHeader, error)
	GetForm(key string) string
	GetFile(key string) (file *FileHeader, has bool)
	RawBody() ([]byte, error)
}

type BodyDatawriter

type BodyDatawriter interface {
	//设置form数据并将content-type设置 为 application/x-www-form-urlencoded 或 multipart/form-data
	SetForm(values url.Values) error
	SetToForm(key, value string) error
	AddForm(key, value string) error
	// 会替换掉对应掉file信息,并且将content-type 设置为 multipart/form-data
	AddFile(key string, file *FileHeader) error

	// 重置body,会清除掉未处理掉 form和file
	SetRaw(contentType string, body []byte)
}

type BodyGet

type BodyGet interface {
	GetBody() []byte
}

type BodySet

type BodySet interface {
	SetBody([]byte)
}

type BoolCmd

type BoolCmd interface {
	Val() bool
	Result() (bool, error)
	String() string
}

type BoolSliceCmd

type BoolSliceCmd interface {
	Val() []bool
	Result() ([]bool, error)
	String() string
}

type Cmd

type Cmd interface {
	Val() interface{}
	Result() (interface{}, error)
	String() (string, error)
	Int() (int, error)
	Int64() (int64, error)
	Uint64() (uint64, error)
	//Float32() (float32, error)
	Float64() (float64, error)
	Bool() (bool, error)
}

type Cmdable

type Cmdable interface {
	Ping() StatusCmd
	Del(keys ...string) IntCmd
	Unlink(keys ...string) IntCmd
	Dump(key string) StringCmd
	Exists(keys ...string) IntCmd
	Expire(key string, expiration time.Duration) BoolCmd
	ExpireAt(key string, tm time.Time) BoolCmd
	Keys(pattern string) StringSliceCmd

	RandomKey() StringCmd
	Rename(key, newkey string) StatusCmd
	RenameNX(key, newkey string) BoolCmd
	Restore(key string, ttl time.Duration, value string) StatusCmd
	RestoreReplace(key string, ttl time.Duration, value string) StatusCmd

	Append(key, value string) IntCmd
	//BitCountS(key string, Start, End int64) IntCmd
	BitOpAnd(destKey string, keys ...string) IntCmd
	BitOpOr(destKey string, keys ...string) IntCmd
	BitOpXor(destKey string, keys ...string) IntCmd
	BitOpNot(destKey string, key string) IntCmd
	BitPos(key string, bit int64, pos ...int64) IntCmd

	Decr(key string) IntCmd
	DecrBy(key string, decrement int64) IntCmd
	Get(key string) StringCmd
	GetBit(key string, offset int64) IntCmd
	GetRange(key string, start, end int64) StringCmd
	GetSet(key string, value interface{}) StringCmd
	Incr(key string) IntCmd
	IncrBy(key string, value int64) IntCmd
	IncrByFloat(key string, value float64) FloatCmd
	MGet(keys ...string) SliceCmd
	MSet(pairs ...interface{}) StatusCmd
	MSetNX(pairs ...interface{}) BoolCmd
	Set(key string, value interface{}, expiration time.Duration) StatusCmd
	SetBit(key string, offset int64, value int) IntCmd
	SetNX(key string, value interface{}, expiration time.Duration) BoolCmd
	SetXX(key string, value interface{}, expiration time.Duration) BoolCmd
	SetRange(key string, offset int64, value string) IntCmd
	StrLen(key string) IntCmd
	HDel(key string, fields ...string) IntCmd
	HExists(key, field string) BoolCmd
	HGet(key, field string) StringCmd
	HGetAll(key string) StringStringMapCmd
	HIncrBy(key, field string, incr int64) IntCmd
	HIncrByFloat(key, field string, incr float64) FloatCmd
	HKeys(key string) StringSliceCmd
	HLen(key string) IntCmd
	HMGet(key string, fields ...string) SliceCmd
	HMSet(key string, fields map[string]interface{}) StatusCmd
	HSet(key, field string, value interface{}) BoolCmd
	HSetNX(key, field string, value interface{}) BoolCmd
	HVals(key string) StringSliceCmd
	BLPop(timeout time.Duration, keys ...string) StringSliceCmd
	BRPop(timeout time.Duration, keys ...string) StringSliceCmd
	BRPopLPush(source, destination string, timeout time.Duration) StringCmd
	LIndex(key string, index int64) StringCmd
	LInsert(key, op string, pivot, value interface{}) IntCmd
	LInsertBefore(key string, pivot, value interface{}) IntCmd
	LInsertAfter(key string, pivot, value interface{}) IntCmd
	LLen(key string) IntCmd
	LPop(key string) StringCmd
	LPush(key string, values ...interface{}) IntCmd
	LPushX(key string, value interface{}) IntCmd
	LRange(key string, start, stop int64) StringSliceCmd
	LRem(key string, count int64, value interface{}) IntCmd
	LSet(key string, index int64, value interface{}) StatusCmd
	LTrim(key string, start, stop int64) StatusCmd
	RPop(key string) StringCmd
	RPopLPush(source, destination string) StringCmd
	RPush(key string, values ...interface{}) IntCmd
	RPushX(key string, value interface{}) IntCmd
	SAdd(key string, members ...interface{}) IntCmd
	SCard(key string) IntCmd
	SDiff(keys ...string) StringSliceCmd
	SDiffStore(destination string, keys ...string) IntCmd
	SInter(keys ...string) StringSliceCmd
	SInterStore(destination string, keys ...string) IntCmd
	SIsMember(key string, member interface{}) BoolCmd
	SMembers(key string) StringSliceCmd
	SMembersMap(key string) StringStructMapCmd
	SMove(source, destination string, member interface{}) BoolCmd
	SPop(key string) StringCmd
	SPopN(key string, count int64) StringSliceCmd
	SRandMember(key string) StringCmd
	SRandMemberN(key string, count int64) StringSliceCmd
	SRem(key string, members ...interface{}) IntCmd
	SUnion(keys ...string) StringSliceCmd
	SUnionStore(destination string, keys ...string) IntCmd
}

type Cmder

type Cmder interface {
	Name() string
	Args() []interface{}

	Err() error
}

type Context

type Context interface {
	ResponseWriter // 处理返回
	StoreContainer // cache
	RequestId() string
	FinalTargetServer() string
	RetryTargetServers() string
}

type ContextAccess

type ContextAccess interface {
	Context        // 处理返回
	ContextApiInfo // api 信息
	Request() RequestReader
	Proxy() Request // 请求信息,包含原始请求数据以及被更高优先级处理过的结果
}

转发前

type ContextApiInfo

type ContextApiInfo interface {
	StrategyId() string
	StrategyName() string
	ApiID() int
}

请求基本接口信息

type ContextBeforeMatch

type ContextBeforeMatch interface {
	Context // 处理返回
	Request() RequestReader
	Proxy() Request // 请求信息,包含原始请求数据以及被更高优先级处理过的结果
}

type ContextProxy

type ContextProxy interface {
	Context                        // 处理返回
	ContextApiInfo                 // api 信息
	ProxyResponse() ResponseReader // 转发后返回的结果
}

转发后

type CookieReader

type CookieReader interface {
	Cookie(name string) (*http.Cookie, error)
	Cookies() []*http.Cookie
}

type CookieWriter

type CookieWriter interface {
	AddCookie(c *http.Cookie)
}

type DurationCmd

type DurationCmd interface {
	Val() time.Duration
	Result() (time.Duration, error)
	String() string
}

type FileHeader

type FileHeader struct {
	FileName string
	Header   textproto.MIMEHeader
	Data     []byte
}

type FloatCmd

type FloatCmd interface {
	Val() float64
	Result() (float64, error)
	String() string
}
type Header interface {
	HeaderReader
	HeaderWriter
}

type HeaderReader

type HeaderReader interface {
	GetHeader(name string) string
	// 返回所有header,返回值为一个副本,对他的修改不会生效
	Headers() http.Header
}

type HeaderWriter

type HeaderWriter interface {
	SetHeader(key, value string)
	AddHeader(key, value string)
	DelHeader(key string)
}

type IntCmd

type IntCmd interface {
	Val() int64
	Result() (int64, error)
	String() string
}

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})

	Warnf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})

	Debug(args ...interface{})
	Info(args ...interface{})

	Warn(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
}

func GenLogger added in v0.1.3

func GenLogger(pluginName string) Logger

type Pipeliner

type Pipeliner interface {
	StatefulCmdable
	Do(args ...interface{}) Cmd
	//Process(cmd Cmder) error
	Close() error
	Discard() error
	Exec() ([]Cmder, error)
}

type PluginAccess

type PluginAccess interface {
	Access(ctx ContextAccess) (isContinue bool, e error)
}

type PluginBeforeMatch

type PluginBeforeMatch interface {
	BeforeMatch(ctx ContextBeforeMatch) (isContinue bool, e error)
}

type PluginFactory

type PluginFactory interface {
	Create(config string, clusterName string, updateTag string, strategyId string, apiId int) (*PluginObj, error)
}

定义插件实现函数

type PluginLogProxy added in v0.1.3

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

func (*PluginLogProxy) Debug added in v0.1.3

func (l *PluginLogProxy) Debug(args ...interface{})

func (*PluginLogProxy) Debugf added in v0.1.3

func (l *PluginLogProxy) Debugf(format string, args ...interface{})

func (*PluginLogProxy) Error added in v0.1.3

func (l *PluginLogProxy) Error(args ...interface{})

func (*PluginLogProxy) Errorf added in v0.1.3

func (l *PluginLogProxy) Errorf(format string, args ...interface{})

func (*PluginLogProxy) Info added in v0.1.3

func (l *PluginLogProxy) Info(args ...interface{})

func (*PluginLogProxy) Infof added in v0.1.3

func (l *PluginLogProxy) Infof(format string, args ...interface{})

func (*PluginLogProxy) Warn added in v0.1.3

func (l *PluginLogProxy) Warn(args ...interface{})

func (*PluginLogProxy) Warnf added in v0.1.3

func (l *PluginLogProxy) Warnf(format string, args ...interface{})

func (*PluginLogProxy) Warning added in v0.1.3

func (l *PluginLogProxy) Warning(args ...interface{})

func (*PluginLogProxy) Warningf added in v0.1.3

func (l *PluginLogProxy) Warningf(format string, args ...interface{})

type PluginObj

type PluginObj struct {
	BeforeMatch PluginBeforeMatch
	Access      PluginAccess
	Proxy       PluginProxy
}

type PluginProxy

type PluginProxy interface {
	Proxy(ctx ContextProxy) (isContinue bool, e error)
}

type PriorityHeader

type PriorityHeader interface {
	HeaderReader // 读已经设置的header
	HeaderWriter // 设置header
	// 非Priority的header会被 proxy 的同名项替换掉,
	Set() Header    // 这里设置的header会替换掉proxy的内容
	Append() Header // 这里设置的header会追加到proxy的内容
}

带优先的header

type Redis

type Redis interface {
	Cmdable
	Pipeline() Pipeliner
	Pipelined(fn func(Pipeliner) error) ([]Cmder, error)
}

func GetRedis

func GetRedis() Redis

func GetRedisByName

func GetRedisByName(name string) (Redis, bool)

type RedisManager

type RedisManager interface {
	Default() Redis
	Get(name string) (redis Redis, has bool)
}

type Request

type Request interface {
	CookieReader
	HeaderReader
	HeaderWriter
	CookieWriter
	Body
	Querys() url.Values
	TargetServer() string
	TargetURL() string
}

用于组装转发的request

type RequestData

type RequestData interface {
	BodyDataReader
	Method() string
	URL() *url.URL
	RequestURI() string
	Host() string
	RemoteAddr() string
	Proto() string
}

type RequestReader

type RequestReader interface {
	CookieReader
	HeaderReader
	RequestData
}

原始请求数据的读

type ResponseReader

type ResponseReader interface {
	CookieReader
	HeaderReader
	BodyGet
	StatusGet
}

读取转发结果的response

type ResponseWriter

type ResponseWriter interface {
	PriorityHeader
	CookieReader // 已经设置的cookie
	CookieWriter // 设置返回的cookie
	StatusGet
	StatusSet // 设置返回状态
	BodySet   // 设置返回内容
	BodyGet
}

返回给client端的

type SliceCmd

type SliceCmd interface {
	Val() []interface{}
	Result() ([]interface{}, error)
	String() string
}

type StatefulCmdable

type StatefulCmdable interface {
	Cmdable
	Auth(password string) StatusCmd
	Select(index int) StatusCmd
	SwapDB(index1, index2 int) StatusCmd
	ClientSetName(name string) BoolCmd
}

type StatusCmd

type StatusCmd interface {
	Val() string
	Result() (string, error)
	String() string
}

type StatusGet

type StatusGet interface {
	StatusCode() int
	Status() string
}

type StatusSet

type StatusSet interface {
	SetStatus(code int, status string)
}

type Store

type Store interface {
	Set(value interface{})
	Get() (value interface{})
}

单存储

type StoreContainer

type StoreContainer interface {
	Store() Store // 私有存储
	SetCache(name string, value interface{})
	GetCache(name string) (value interface{}, has bool)
}

存储容器

type StringCmd

type StringCmd interface {
	Val() string
	Result() (string, error)
	Bytes() ([]byte, error)
	Int() (int, error)
	Int64() (int64, error)
	Uint64() (uint64, error)
	//Float32() (float32, error)
	Float64() (float64, error)
	Scan(val interface{}) error
	String() string
}

type StringIntMapCmd

type StringIntMapCmd interface {
	Val() map[string]int64
	Result() (map[string]int64, error)
	String() string
}

type StringSliceCmd

type StringSliceCmd interface {
	Val() []string
	Result() ([]string, error)
	String() string
	ScanSlice(container interface{}) error
}

type StringStringMapCmd

type StringStringMapCmd interface {
	Val() map[string]string
	Result() (map[string]string, error)
	String() string
}

type StringStructMapCmd

type StringStructMapCmd interface {
	Val() map[string]struct{}
	Result() (map[string]struct{}, error)
	String() string
}

type TimeCmd

type TimeCmd interface {
	Val() time.Time
	Result() (time.Time, error)
	String() string
}

Jump to

Keyboard shortcuts

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