node

package
v1.0.145 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GatewayRateLimiterFilterName = "GatewayRateLimiterFilter"
	ParameterFilterName          = "ParameterFilter"
	SessionFilterName            = "SessionFilter"
	UserRateLimiterFilterName    = "UserRateLimiterFilter"
	RoleFilterName               = "RoleFilter"
	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 = 200000 // 最大参数值长度
	MAX_TOKEN_LEN = 2048   // 最大Token值长度
	MAX_CODE_LEN  = 1024   // 最大Code值长度

	Authorization = "Authorization"
	RandomCode    = "RandomCode"
)

Variables

This section is empty.

Functions

func ErrorMsgToLang added in v1.0.129

func ErrorMsgToLang(ctx *Context, msg string, args ...string) string

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 Configs added in v1.0.113

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

type Context

type Context struct {
	CacheAware func(ds ...string) (cache.Cache, error)
	Method     string
	Path       string
	System     *System
	RequestCtx *fasthttp.RequestCtx
	Subject    *jwt.Subject
	JsonBody   *JsonBody
	Response   *Response

	RouterConfig *RouterConfig
	RSA          crypto.Cipher

	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) ClientDevice added in v1.0.104

func (self *Context) ClientDevice() string

func (*Context) ClientLanguage added in v1.0.107

func (self *Context) ClientLanguage() string

func (*Context) DelStorage added in v1.0.3

func (self *Context) DelStorage(k string)

func (*Context) GetHeader added in v1.0.134

func (self *Context) GetHeader(key string) 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) GetPostBody added in v1.0.134

func (self *Context) GetPostBody() string

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) Json added in v1.0.120

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

func (*Context) Parser

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

func (*Context) RemoteIP added in v1.0.104

func (self *Context) RemoteIP() string

func (*Context) Text added in v1.0.120

func (self *Context) Text(data string) 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 ErrorHandle added in v1.0.121

type ErrorHandle func(ctx *Context, throw ex.Throw) 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
	// contains filtered or unexported fields
}

type HttpLog

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

type HttpNode

type HttpNode struct {
	HookNode
	// contains filtered or unexported fields
}

func (*HttpNode) AddCache added in v1.0.5

func (self *HttpNode) AddCache(cacheAware CacheAware)

func (*HttpNode) AddCipher added in v1.0.72

func (self *HttpNode) AddCipher(cipher crypto.Cipher)

func (*HttpNode) AddErrorHandle added in v1.0.121

func (self *HttpNode) AddErrorHandle(errorHandle func(ctx *Context, throw ex.Throw) error) error

func (*HttpNode) AddFilter

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

func (*HttpNode) AddJwtConfig

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

func (*HttpNode) AddLanguage added in v1.0.107

func (self *HttpNode) AddLanguage(langDs, filePath string) error

func (*HttpNode) AddLanguageByJson added in v1.0.128

func (self *HttpNode) AddLanguageByJson(langDs string, bs []byte) error

func (*HttpNode) AddRoleRealm added in v1.0.115

func (self *HttpNode) AddRoleRealm(roleRealm func(ctx *Context, onlyRole bool) (*Permission, error)) error

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) EnableECC added in v1.0.72

func (self *HttpNode) EnableECC(enable bool)

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) SetSystem added in v1.0.115

func (self *HttpNode) SetSystem(name, version string)

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/ECC模式(匿名状态) 3.独立验签模式(匿名状态)
	Sign  string      `json:"s"`
}

func (*JsonBody) ParseData added in v1.0.22

func (self *JsonBody) ParseData(dst interface{}) error

func (*JsonBody) RawData added in v1.0.22

func (self *JsonBody) RawData() []byte

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    // true.已有权限配置
	MatchAll  bool    // true.满足所有权限角色才放行
	NeedLogin bool    // true.需要登录状态
	HasRole   []int64 // 拥有角色ID列表
	NeedRole  []int64 // 所需角色ID列表
}

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 Response

type Response struct {
	Encoding      string
	ContentType   string
	ContentEntity interface{}
	// response result
	StatusCode        int
	ContentEntityByte bytes.Buffer
}

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.是
	UseRSA      bool // 非登录状态使用RSA模式请求 false.否 true.是
	UseHAX      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 System added in v1.0.116

type System struct {
	Name          string // 系统名
	Version       string // 系统版本
	AcceptTimeout int64  // 超时主动断开客户端连接,秒
	// contains filtered or unexported fields
}

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