plugin

package
v0.0.0-...-2b39aee Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PluginConstructor every plugin needs a constructor
	PluginConstructor = "NewPlugin"
	// PluginPre filter pre method
	PluginPre = "pre"
	// PluginPost filter post method
	PluginPost = "post"
	// PluginPostErr filter post error method
	PluginPostErr = "postErr"

	// PluginReturnCodeFieldName code field name in return json object
	PluginReturnCodeFieldName = "code"
	// PluginReturnErrorFieldName error field name in return json object
	PluginReturnErrorFieldName = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdResp

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

CmdResp redis cmd resp

func (*CmdResp) Error

func (r *CmdResp) Error() string

Error returns error

func (*CmdResp) HasError

func (r *CmdResp) HasError() bool

HasError returns has error

func (*CmdResp) Int64MapValue

func (r *CmdResp) Int64MapValue() map[string]int64

Int64MapValue returns int64 map value

func (*CmdResp) Int64Value

func (r *CmdResp) Int64Value() int64

Int64Value returns int64 value

func (*CmdResp) Int64sValue

func (r *CmdResp) Int64sValue() []int64

Int64sValue returns int64s value

func (*CmdResp) IntMapValue

func (r *CmdResp) IntMapValue() map[string]int

IntMapValue returns int map value

func (*CmdResp) IntValue

func (r *CmdResp) IntValue() int

IntValue returns int value

func (*CmdResp) IntsValue

func (r *CmdResp) IntsValue() []int

IntsValue returns ints value

func (*CmdResp) StringMapValue

func (r *CmdResp) StringMapValue() map[string]string

StringMapValue returns string map value

func (*CmdResp) StringValue

func (r *CmdResp) StringValue() string

StringValue returns string value

func (*CmdResp) StringsValue

func (r *CmdResp) StringsValue() []string

StringsValue returns strings value

type Ctx

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

Ctx plugin ctx

func (*Ctx) ForwardRequest

func (c *Ctx) ForwardRequest() *FastHTTPRequestAdapter

ForwardRequest return forward request

func (*Ctx) GetAttr

func (c *Ctx) GetAttr(key string) interface{}

GetAttr return attr value in the context

func (*Ctx) HasAttr

func (c *Ctx) HasAttr(key string) bool

HasAttr is attr in context

func (*Ctx) OriginRequest

func (c *Ctx) OriginRequest() *FastHTTPRequestAdapter

OriginRequest return origin request

func (*Ctx) Response

func (c *Ctx) Response() *FastHTTPResponseAdapter

Response return response

func (*Ctx) SetAttr

func (c *Ctx) SetAttr(key string, value interface{})

SetAttr set attr to context

type Engine

type Engine struct {
	filter.BaseFilter
	// contains filtered or unexported fields
}

Engine plugin engine

func NewEngine

func NewEngine(enable bool, name string) *Engine

NewEngine returns a plugin engine

func (*Engine) ApplyPlugins

func (eng *Engine) ApplyPlugins(plugins ...*metapb.Plugin) error

ApplyPlugins apply plugins

func (*Engine) Destroy

func (eng *Engine) Destroy()

Destroy destory all applied plugins

func (*Engine) Init

func (eng *Engine) Init(cfg string) error

Init returns error if init failed

func (*Engine) LastActive

func (eng *Engine) LastActive() time.Time

LastActive returns the time that last used

func (*Engine) Name

func (eng *Engine) Name() string

Name returns filter name

func (*Engine) Post

func (eng *Engine) Post(c filter.Context) (int, error)

Post filter post method

func (*Engine) PostErr

func (eng *Engine) PostErr(c filter.Context, code int, err error)

PostErr filter post error method

func (*Engine) Pre

func (eng *Engine) Pre(c filter.Context) (int, error)

Pre filter pre method

func (*Engine) UpdatePlugin

func (eng *Engine) UpdatePlugin(plugin *metapb.Plugin) error

UpdatePlugin update plugin

type FastHTTPRequestAdapter

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

FastHTTPRequestAdapter fasthttp request adapter

func (*FastHTTPRequestAdapter) Body

func (req *FastHTTPRequestAdapter) Body() string

Body returns request body

func (*FastHTTPRequestAdapter) Cookie

func (req *FastHTTPRequestAdapter) Cookie(name string) string

Cookie returns cookie value

func (*FastHTTPRequestAdapter) Header

func (req *FastHTTPRequestAdapter) Header(name string) string

Header returns header value

func (*FastHTTPRequestAdapter) Query

func (req *FastHTTPRequestAdapter) Query(name string) string

Query returns query string value

func (*FastHTTPRequestAdapter) RemoveCookie

func (req *FastHTTPRequestAdapter) RemoveCookie(name string)

RemoveCookie remove cookie

func (*FastHTTPRequestAdapter) RemoveHeader

func (req *FastHTTPRequestAdapter) RemoveHeader(name string)

RemoveHeader remove header

func (*FastHTTPRequestAdapter) SetBody

func (req *FastHTTPRequestAdapter) SetBody(body string)

SetBody set body

func (*FastHTTPRequestAdapter) SetCookie

func (req *FastHTTPRequestAdapter) SetCookie(name, value string)

SetCookie set cookie value

func (*FastHTTPRequestAdapter) SetHeader

func (req *FastHTTPRequestAdapter) SetHeader(name, value string)

SetHeader set header value

type FastHTTPResponseAdapter

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

FastHTTPResponseAdapter fasthttp response adapter

func (*FastHTTPResponseAdapter) Body

func (rsp *FastHTTPResponseAdapter) Body() string

Body returns request body

func (*FastHTTPResponseAdapter) Cookie

func (rsp *FastHTTPResponseAdapter) Cookie(name string) string

Cookie returns cookie value

func (*FastHTTPResponseAdapter) Delegate

func (rsp *FastHTTPResponseAdapter) Delegate() *fasthttp.Response

Delegate returns delegate fasthttp response

func (*FastHTTPResponseAdapter) Header

func (rsp *FastHTTPResponseAdapter) Header(name string) string

Header returns header value

func (*FastHTTPResponseAdapter) RemoveCookie

func (rsp *FastHTTPResponseAdapter) RemoveCookie(name string)

RemoveCookie remove cookie

func (*FastHTTPResponseAdapter) RemoveHeader

func (rsp *FastHTTPResponseAdapter) RemoveHeader(name string)

RemoveHeader remove header

func (*FastHTTPResponseAdapter) SetBody

func (rsp *FastHTTPResponseAdapter) SetBody(body string)

SetBody set body

func (*FastHTTPResponseAdapter) SetCookie

func (rsp *FastHTTPResponseAdapter) SetCookie(domain, path, name, value string, expire int64, httpOnly, secure bool)

SetCookie set cookie value

func (*FastHTTPResponseAdapter) SetHeader

func (rsp *FastHTTPResponseAdapter) SetHeader(name, value string)

SetHeader set header value

func (*FastHTTPResponseAdapter) SetStatusCode

func (rsp *FastHTTPResponseAdapter) SetStatusCode(code int)

SetStatusCode set status code

type HTTPModule

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

HTTPModule http module

func (*HTTPModule) Delete

func (h *HTTPModule) Delete(url string, body string, header map[string][]string) *HTTPResult

Delete do delete

func (*HTTPModule) DeleteJSON

func (h *HTTPModule) DeleteJSON(url string, body string, header map[string][]string) *HTTPResult

DeleteJSON do delete json

func (*HTTPModule) Get

func (h *HTTPModule) Get(url string) *HTTPResult

Get go get

func (*HTTPModule) NewHTTPResponse

func (h *HTTPModule) NewHTTPResponse() *FastHTTPResponseAdapter

NewHTTPResponse returns http response

func (*HTTPModule) Post

func (h *HTTPModule) Post(url string, body string, header map[string][]string) *HTTPResult

Post do post

func (*HTTPModule) PostJSON

func (h *HTTPModule) PostJSON(url string, body string, header map[string][]string) *HTTPResult

PostJSON do post

func (*HTTPModule) Put

func (h *HTTPModule) Put(url string, body string, header map[string][]string) *HTTPResult

Put do put

func (*HTTPModule) PutJSON

func (h *HTTPModule) PutJSON(url string, body string, header map[string][]string) *HTTPResult

PutJSON do put json

type HTTPResult

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

HTTPResult result

func (*HTTPResult) Body

func (res *HTTPResult) Body() string

Body returns http response body

func (*HTTPResult) Cookie

func (res *HTTPResult) Cookie() []*http.Cookie

Cookie returns http response cookie

func (*HTTPResult) Error

func (res *HTTPResult) Error() string

Error returns error

func (*HTTPResult) HasError

func (res *HTTPResult) HasError() bool

HasError returns true if has a error

func (*HTTPResult) Header

func (res *HTTPResult) Header() map[string][]string

Header returns http response header

func (*HTTPResult) StatusCode

func (res *HTTPResult) StatusCode() int

StatusCode returns status code

type JSONModule

type JSONModule struct {
}

JSONModule json builtin

func (*JSONModule) Parse

func (j *JSONModule) Parse(value string) map[string]interface{}

Parse parse a string to json

func (*JSONModule) Stringify

func (j *JSONModule) Stringify(value interface{}) string

Stringify returns json string

type LogModule

type LogModule struct {
}

LogModule log module

func (*LogModule) Debug

func (l *LogModule) Debug(v ...interface{})

Debug debug

func (*LogModule) Debugf

func (l *LogModule) Debugf(format string, v ...interface{})

Debugf debugf

func (*LogModule) Error

func (l *LogModule) Error(v ...interface{})

Error error

func (*LogModule) Errorf

func (l *LogModule) Errorf(format string, v ...interface{})

Errorf errorf

func (*LogModule) Fatal

func (l *LogModule) Fatal(v ...interface{})

Fatal fatal

func (*LogModule) Fatalf

func (l *LogModule) Fatalf(format string, v ...interface{})

Fatalf fatalf

func (*LogModule) Info

func (l *LogModule) Info(v ...interface{})

Info info

func (*LogModule) Infof

func (l *LogModule) Infof(format string, v ...interface{})

Infof infof

func (*LogModule) Warn

func (l *LogModule) Warn(v ...interface{})

Warn warn

func (*LogModule) Warnf

func (l *LogModule) Warnf(format string, v ...interface{})

Warnf warnf

func (*LogModule) Warning

func (l *LogModule) Warning(v ...interface{})

Warning warning

func (*LogModule) Warningf

func (l *LogModule) Warningf(format string, v ...interface{})

Warningf warningf

type RedisModule

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

RedisModule redis module

func (*RedisModule) CreateRedis

func (m *RedisModule) CreateRedis(cfg map[string]interface{}) *RedisOp

CreateRedis create redis

type RedisOp

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

RedisOp redis

func (*RedisOp) Do

func (r *RedisOp) Do(cmd string, args ...interface{}) *CmdResp

Do do redis cmd

type Runtime

type Runtime struct {
	sync.RWMutex
	filter.BaseFilter
	// contains filtered or unexported fields
}

Runtime plugin runtime

func NewRuntime

func NewRuntime(meta *metapb.Plugin) (*Runtime, error)

NewRuntime return a runtime

func (*Runtime) Post

func (rt *Runtime) Post(c *Ctx) (int, error)

Post filter post method

func (*Runtime) PostErr

func (rt *Runtime) PostErr(c *Ctx, code int, err error)

PostErr filter post error method

func (*Runtime) Pre

func (rt *Runtime) Pre(c *Ctx) (int, error)

Pre filter pre method

func (*Runtime) Require

func (rt *Runtime) Require(name string) interface{}

Require require module

Jump to

Keyboard shortcuts

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