node

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GatewayRateLimiterFilterName = "GatewayRateLimiterFilter"
	ParameterFilterName          = "ParameterFilter"
	SessionFilterName            = "SessionFilter"
	UserRateLimiterFilterName    = "UserRateLimiterFilter"
	RoleFilterName               = "RoleFilter"
	ReplayFilterName             = "ReplayFilter"
	PostHandleFilterName         = "PostHandleFilter"
	RenderHandleFilterName       = "RenderHandleFilter"
)
View Source
const (
	UTF8 = "UTF-8"

	ANDROID = "android"
	IOS     = "ios"
	WEB     = "web"

	TEXT_PLAIN       = "text/plain; charset=utf-8"
	APPLICATION_JSON = "application/json; charset=utf-8"

	GET     = "GET"
	POST    = "POST"
	PUT     = "PUT"
	PATCH   = "PATCH"
	DELETE  = "DELETE"
	HEAD    = "HEAD"
	OPTIONS = "OPTIONS"

	MAX_VALUE_LEN = 4000 // 最大参数值长度

	Authorization = "Authorization"
	RandomCode    = "RandomCode"
)

Variables

This section is empty.

Functions

func NewGracefulListener

func NewGracefulListener(address string, maxWaitTime time.Duration) net.Listener

NewGracefulListener wraps the given listener into 'graceful shutdown' listener.

func SetGatewayRateLimiter

func SetGatewayRateLimiter(option rate.Option)

func SetMethodRateLimiter

func SetMethodRateLimiter(option rate.Option)

func SetUserRateLimiter

func SetUserRateLimiter(option rate.Option)

Types

type CacheAware added in v1.0.5

type CacheAware func(ds ...string) (cache.Cache, error)

type Context

type Context struct {
	CacheAware    func(ds ...string) (cache.Cache, error)
	AcceptTimeout int64 // 超时主动断开客户端连接,秒
	Token         string
	Device        string
	CreateAt      int64
	Method        string
	Path          string
	RequestCtx    *fasthttp.RequestCtx
	Subject       *jwt.Payload
	JsonBody      *JsonBody
	Response      *Response

	RouterConfig *RouterConfig
	RSA          gorsa.RSA
	PermConfig   func(uid, url string, isRole ...bool) ([]int64, Permission, error)
	Storage      map[string]interface{}
	// contains filtered or unexported fields
}

func (*Context) AddStorage

func (self *Context) AddStorage(k string, v interface{})

func (*Context) Authenticated

func (self *Context) Authenticated() bool

func (*Context) DelStorage added in v1.0.3

func (self *Context) DelStorage(k string)

func (*Context) GetHmac256Sign

func (self *Context) GetHmac256Sign(d, n string, t, p int64, key ...string) string

func (*Context) GetJwtConfig

func (self *Context) GetJwtConfig() jwt.JwtConfig

func (*Context) GetStorage

func (self *Context) GetStorage(k string) interface{}

func (*Context) GetTokenSecret

func (self *Context) GetTokenSecret() string

func (*Context) Handle

func (self *Context) Handle() error

func (*Context) Parser

func (self *Context) Parser(v interface{}) error

type DefaultCacheSessionAware

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

func NewLocalCacheSessionAware

func NewLocalCacheSessionAware() *DefaultCacheSessionAware

func (*DefaultCacheSessionAware) CreateSession

func (self *DefaultCacheSessionAware) CreateSession(s Session) error

func (*DefaultCacheSessionAware) DeleteSession

func (self *DefaultCacheSessionAware) DeleteSession(s Session) error

func (*DefaultCacheSessionAware) GetActiveSessions

func (self *DefaultCacheSessionAware) GetActiveSessions() []Session

func (*DefaultCacheSessionAware) ReadSession

func (self *DefaultCacheSessionAware) ReadSession(s string) (Session, error)

func (*DefaultCacheSessionAware) UpdateSession

func (self *DefaultCacheSessionAware) UpdateSession(s Session) error

type Filter

type Filter interface {
	DoFilter(chain Filter, ctx *Context, args ...interface{}) error
}

type FilterObject

type FilterObject struct {
	Name         string
	Order        int
	Filter       Filter
	MatchPattern []string
}

type GatewayRateLimiterFilter

type GatewayRateLimiterFilter struct{}

func (*GatewayRateLimiterFilter) DoFilter

func (self *GatewayRateLimiterFilter) DoFilter(chain Filter, ctx *Context, args ...interface{}) error

type GracefulListener

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

func (*GracefulListener) Accept

func (ln *GracefulListener) Accept() (net.Conn, error)

func (*GracefulListener) Addr

func (ln *GracefulListener) Addr() net.Addr

func (*GracefulListener) Close

func (ln *GracefulListener) Close() error

Close closes the inner listener and waits until all the pending open connections are closed before returning.

type HookNode

type HookNode struct {
	Context *Context
}

type HttpLog

type HttpLog struct {
	Method   string // 请求方法
	LogNo    string // 日志唯一标记
	CreateAt int64  // 日志创建时间
	UpdateAt int64  // 日志完成时间
	CostMill int64  // 业务耗时,毫秒
}

type HttpNode

type HttpNode struct {
	HookNode
}

func (*HttpNode) AddCache added in v1.0.5

func (self *HttpNode) AddCache(aware CacheAware)

func (*HttpNode) AddFilter

func (self *HttpNode) AddFilter(object *FilterObject)

func (*HttpNode) AddJwtConfig

func (self *HttpNode) AddJwtConfig(config jwt.JwtConfig)

func (*HttpNode) AddRSA added in v1.0.5

func (self *HttpNode) AddRSA(rsa gorsa.RSA)

func (*HttpNode) ClearFilterChain

func (self *HttpNode) ClearFilterChain()

func (*HttpNode) DELETE

func (self *HttpNode) DELETE(path string, handle func(ctx *Context) error, routerConfig *RouterConfig)

func (*HttpNode) GET

func (self *HttpNode) GET(path string, handle func(ctx *Context) error, routerConfig *RouterConfig)

func (*HttpNode) HEAD

func (self *HttpNode) HEAD(path string, handle func(ctx *Context) error, routerConfig *RouterConfig)

func (*HttpNode) Json

func (self *HttpNode) Json(ctx *Context, data interface{}) error

func (*HttpNode) OPTIONS

func (self *HttpNode) OPTIONS(path string, handle func(ctx *Context) error, routerConfig *RouterConfig)

func (*HttpNode) PATCH

func (self *HttpNode) PATCH(path string, handle func(ctx *Context) error, routerConfig *RouterConfig)

func (*HttpNode) POST

func (self *HttpNode) POST(path string, handle func(ctx *Context) error, routerConfig *RouterConfig)

func (*HttpNode) PUT

func (self *HttpNode) PUT(path string, handle func(ctx *Context) error, routerConfig *RouterConfig)

func (*HttpNode) StartServer

func (self *HttpNode) StartServer(addr string)

func (*HttpNode) Text

func (self *HttpNode) Text(ctx *Context, data string) error

type JWTSession

type JWTSession struct {
	Id             string
	StartTimestamp int64
	LastAccessTime int64
	Timeout        int64
	StopTime       int64
	Host           string
	Expire         bool
	Attributes     map[string]interface{}
}

func (*JWTSession) GetAttribute

func (self *JWTSession) GetAttribute(k string) (interface{}, error)

func (*JWTSession) GetAttributeKeys

func (self *JWTSession) GetAttributeKeys() ([]string, error)

func (*JWTSession) GetHost

func (self *JWTSession) GetHost() string

func (*JWTSession) GetId

func (self *JWTSession) GetId() string

func (*JWTSession) GetLastAccessTime

func (self *JWTSession) GetLastAccessTime() int64

func (*JWTSession) GetStartTimestamp

func (self *JWTSession) GetStartTimestamp() int64

func (*JWTSession) GetTimeout

func (self *JWTSession) GetTimeout() (int64, error)

func (*JWTSession) Invalid

func (self *JWTSession) Invalid() bool

func (*JWTSession) IsTimeout

func (self *JWTSession) IsTimeout() bool

func (*JWTSession) RemoveAttribute

func (self *JWTSession) RemoveAttribute(k string) error

func (*JWTSession) SetAttribute

func (self *JWTSession) SetAttribute(k string, v interface{}) error

func (*JWTSession) SetHost

func (self *JWTSession) SetHost(host string)

func (*JWTSession) SetTimeout

func (self *JWTSession) SetTimeout(t int64) error

func (*JWTSession) Stop

func (self *JWTSession) Stop() error

func (*JWTSession) Touch

func (self *JWTSession) Touch() error

func (*JWTSession) Validate

func (self *JWTSession) Validate(accessToken, secretKey string) (int64, error)

type JsonBody

type JsonBody struct {
	Data  interface{} `json:"d"`
	Time  int64       `json:"t"`
	Nonce string      `json:"n"`
	Plan  int64       `json:"p"` // 0.默认 1.AES 2.RSA登录
	Sign  string      `json:"s"`
}

type JsonResp

type JsonResp struct {
	Code    int         `json:"c"`
	Message string      `json:"m"`
	Data    interface{} `json:"d"`
	Time    int64       `json:"t"`
	Nonce   string      `json:"n"`
	Plan    int64       `json:"p"`
	Sign    string      `json:"s"`
}

type ParameterFilter

type ParameterFilter struct{}

func (*ParameterFilter) DoFilter

func (self *ParameterFilter) DoFilter(chain Filter, ctx *Context, args ...interface{}) error

type Permission

type Permission struct {
	Ready     bool
	MathchAll int64
	NeedLogin int64
	NeedRole  []int64
}

type PostHandle

type PostHandle func(*Context) error

type PostHandleFilter

type PostHandleFilter struct{}

func (*PostHandleFilter) DoFilter

func (self *PostHandleFilter) DoFilter(chain Filter, ctx *Context, args ...interface{}) error

type RenderHandleFilter

type RenderHandleFilter struct{}

func (*RenderHandleFilter) DoFilter

func (self *RenderHandleFilter) DoFilter(chain Filter, ctx *Context, args ...interface{}) error

type ReplayFilter

type ReplayFilter struct{}

func (*ReplayFilter) DoFilter

func (self *ReplayFilter) DoFilter(chain Filter, ctx *Context, args ...interface{}) error

type Response

type Response struct {
	Encoding      string
	ContentType   string
	ContentEntity interface{}
	// response result
	StatusCode        int
	ContentEntityByte []byte
}

type RoleFilter

type RoleFilter struct{}

func (*RoleFilter) DoFilter

func (self *RoleFilter) DoFilter(chain Filter, ctx *Context, args ...interface{}) error

type RouterConfig

type RouterConfig struct {
	Guest bool // 游客模式 false.否 true.是
	Login bool // 是否登录请求 false.否 true.是
	//Original    bool // 是否原始方式 false.否 true.是
	AesRequest  bool // 请求是否必须AES加密 false.否 true.是
	AesResponse bool // 响应是否必须AES加密 false.否 true.是
}

type Session

type Session interface {
	GetId() string

	GetStartTimestamp() int64

	GetLastAccessTime() int64

	GetTimeout() (int64, error) // 抛出校验会话异常

	SetTimeout(t int64) error // 抛出校验会话异常

	SetHost(host string)

	GetHost() string

	Touch() error // 刷新最后授权时间,抛出校验会话异常

	Stop() error // 抛出校验会话异常

	GetAttributeKeys() ([]string, error) // 抛出校验会话异常

	GetAttribute(k string) (interface{}, error) // 抛出校验会话异常

	SetAttribute(k string, v interface{}) error // 抛出校验会话异常

	RemoveAttribute(k string) error // 抛出校验会话异常

	Validate(accessToken, secretKey string) (int64, error) // 校验会话

	Invalid() bool // 判断会话是否有效

	IsTimeout() bool // 判断会话是否已超时
}

type SessionAware

type SessionAware interface {
	CreateSession(s Session) error // 保存session

	ReadSession(s string) (Session, error) // 通过id读取session,抛出未知session异常

	UpdateSession(s Session) error // 更新session,抛出未知session异常

	DeleteSession(s Session) error // 删除session,抛出未知session异常

	GetActiveSessions() []Session // 获取活动的session集合
}

type SessionFilter

type SessionFilter struct{}

func (*SessionFilter) DoFilter

func (self *SessionFilter) DoFilter(chain Filter, ctx *Context, args ...interface{}) error

type UserRateLimiterFilter

type UserRateLimiterFilter struct{}

func (*UserRateLimiterFilter) DoFilter

func (self *UserRateLimiterFilter) DoFilter(chain Filter, ctx *Context, args ...interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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