node

package
v1.0.160 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 27 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)

func StartNodeEncipher added in v1.0.159

func StartNodeEncipher(addr string, enc Encipher)

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 ConnPool added in v1.0.146

type ConnPool map[string]map[string]*DevConn

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{}

	Encipher *EncipherClient
	// 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 DefaultEncipher added in v1.0.159

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

func NewDefaultEncipher added in v1.0.159

func NewDefaultEncipher(keyfile string) *DefaultEncipher

func (*DefaultEncipher) AesDecrypt added in v1.0.160

func (s *DefaultEncipher) AesDecrypt(input string) (string, error)

func (*DefaultEncipher) AesEncrypt added in v1.0.160

func (s *DefaultEncipher) AesEncrypt(input string) (string, error)

func (*DefaultEncipher) EccDecrypt added in v1.0.160

func (s *DefaultEncipher) EccDecrypt(input string) (string, error)

func (*DefaultEncipher) EccEncrypt added in v1.0.160

func (s *DefaultEncipher) EccEncrypt(input, publicTo string) (string, error)

func (*DefaultEncipher) LoadConfig added in v1.0.160

func (s *DefaultEncipher) LoadConfig(path string) (EncipherParam, error)

func (*DefaultEncipher) ReadConfig added in v1.0.160

func (s *DefaultEncipher) ReadConfig(key string) string

func (*DefaultEncipher) Signature added in v1.0.159

func (s *DefaultEncipher) Signature(input string) string

func (*DefaultEncipher) TokenCreate added in v1.0.160

func (s *DefaultEncipher) TokenCreate(input string) (string, error)

func (*DefaultEncipher) TokenDecrypt added in v1.0.160

func (s *DefaultEncipher) TokenDecrypt(token, input string) (string, error)

func (*DefaultEncipher) TokenEncrypt added in v1.0.160

func (s *DefaultEncipher) TokenEncrypt(token, input string) (string, error)

func (*DefaultEncipher) TokenSignature added in v1.0.160

func (s *DefaultEncipher) TokenSignature(token, input string) string

func (*DefaultEncipher) TokenVerify added in v1.0.160

func (s *DefaultEncipher) TokenVerify(input string) (string, error)

func (*DefaultEncipher) TokenVerifySignature added in v1.0.160

func (s *DefaultEncipher) TokenVerifySignature(token, input, sign string) bool

func (*DefaultEncipher) VerifySignature added in v1.0.159

func (s *DefaultEncipher) VerifySignature(input, sign string) bool

type DevConn added in v1.0.146

type DevConn struct {
	Sub  string
	Dev  string
	Life int64
	Last int64
	Ctx  *Context
	Conn *websocket.Conn
}

type Encipher added in v1.0.159

type Encipher interface {
	// LoadConfig 读取配置
	LoadConfig(path string) (EncipherParam, error)
	// ReadConfig 读取加密配置
	ReadConfig(key string) string
	// Signature 数据签名
	Signature(input string) string
	// TokenSignature JWT令牌数据签名
	TokenSignature(token, input string) string
	// VerifySignature 数据签名验证
	VerifySignature(input, sign string) bool
	// TokenVerifySignature JWT令牌数据签名验证
	TokenVerifySignature(token, input, sign string) bool
	// AesEncrypt AES数据加密
	AesEncrypt(input string) (string, error)
	// AesDecrypt AES数据解密
	AesDecrypt(input string) (string, error)
	// EccEncrypt 私钥和客户端公钥协商加密
	EccEncrypt(input, publicTo string) (string, error)
	// EccDecrypt 私钥和客户端公钥协商解密
	EccDecrypt(input string) (string, error)
	// TokenEncrypt JWT令牌加密数据
	TokenEncrypt(token, input string) (string, error)
	// TokenDecrypt JWT令牌解密数据
	TokenDecrypt(token, input string) (string, error)
	// TokenCreate JWT令牌生成
	TokenCreate(input string) (string, error)
	// TokenVerify JWT令牌校验
	TokenVerify(input string) (string, error)
}

type EncipherClient added in v1.0.160

type EncipherClient struct {
	Host      string
	EccObject *crypto.EccObj
	// contains filtered or unexported fields
}

func NewEncipherClient added in v1.0.160

func NewEncipherClient(host string) *EncipherClient

func (*EncipherClient) AesDecrypt added in v1.0.160

func (s *EncipherClient) AesDecrypt(input string) (string, error)

func (*EncipherClient) AesEncrypt added in v1.0.160

func (s *EncipherClient) AesEncrypt(input string) (string, error)

func (*EncipherClient) CheckReady added in v1.0.160

func (s *EncipherClient) CheckReady() error

func (*EncipherClient) Config added in v1.0.160

func (s *EncipherClient) Config(input string) (string, error)

func (*EncipherClient) EccDecrypt added in v1.0.160

func (s *EncipherClient) EccDecrypt(input string) (string, error)

func (*EncipherClient) EccEncrypt added in v1.0.160

func (s *EncipherClient) EccEncrypt(input, publicTo string) (string, error)

func (*EncipherClient) Handshake added in v1.0.160

func (s *EncipherClient) Handshake() error

func (*EncipherClient) NextId added in v1.0.160

func (s *EncipherClient) NextId() (string, error)

func (*EncipherClient) PublicKey added in v1.0.160

func (s *EncipherClient) PublicKey() (string, error)

func (*EncipherClient) Signature added in v1.0.160

func (s *EncipherClient) Signature(input string) (string, error)

func (*EncipherClient) SignatureVerify added in v1.0.160

func (s *EncipherClient) SignatureVerify(input, target string) (bool, error)

func (*EncipherClient) TokenCreate added in v1.0.160

func (s *EncipherClient) TokenCreate(input string) (string, error)

func (*EncipherClient) TokenDecrypt added in v1.0.160

func (s *EncipherClient) TokenDecrypt(token, input string) (string, error)

func (*EncipherClient) TokenEncrypt added in v1.0.160

func (s *EncipherClient) TokenEncrypt(token, input string) (string, error)

func (*EncipherClient) TokenSignature added in v1.0.160

func (s *EncipherClient) TokenSignature(token, input string) (string, error)

func (*EncipherClient) TokenSignatureVerify added in v1.0.160

func (s *EncipherClient) TokenSignatureVerify(token, input, target string) (bool, error)

func (*EncipherClient) TokenVerify added in v1.0.160

func (s *EncipherClient) TokenVerify(input string) (string, error)

type EncipherParam added in v1.0.159

type EncipherParam struct {
	EncryptKey      string
	SignKey         string
	SignDepth       int
	EcdsaPrivateKey string
	EcdsaPublicKey  string
	// contains filtered or unexported fields
}

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 Handle added in v1.0.146

type Handle func(*Context, []byte) (interface{}, error) // 如响应数据为nil则不回复

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) ProxyRequest added in v1.0.160

func (self *HttpNode) ProxyRequest(ctx *Context, proxy *fasthttp.HostClient, uri, host string) error

ProxyRequest ctx: 上下文实例 proxy: 代理客户端 uri: 目标请求URI host: 目标域名

func (*HttpNode) SetEncipher added in v1.0.160

func (self *HttpNode) SetEncipher(client *EncipherClient)

func (*HttpNode) SetSystem added in v1.0.115

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

func (*HttpNode) StartServer

func (self *HttpNode) StartServer(addr string, timeout ...int)

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 Ping added in v1.0.146

type Ping struct {
	HealthCheck string `json:"healthCheck"`
}

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 TokenAuth added in v1.0.146

type TokenAuth struct {
	Token  string
	Secret string
}

type UserRateLimiterFilter

type UserRateLimiterFilter struct{}

func (*UserRateLimiterFilter) DoFilter

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

type WsClient added in v1.0.146

type WsClient struct {
	Origin string
	Addr   string
	Path   string

	AuthCall    func() (string, string, error)
	ReceiveCall func(message []byte) (interface{}, error) // 如响应数据为nil,则不回复服务端
	// contains filtered or unexported fields
}

func (*WsClient) Ready added in v1.0.146

func (client *WsClient) Ready() bool

func (*WsClient) SendMessage added in v1.0.146

func (client *WsClient) SendMessage(reply interface{}) error

func (*WsClient) StartWebsocket added in v1.0.146

func (client *WsClient) StartWebsocket(auto bool, n ...int)

type WsServer added in v1.0.146

type WsServer struct {
	Debug bool
	HookNode
	// contains filtered or unexported fields
}

func (*WsServer) AddJwtConfig added in v1.0.146

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

func (*WsServer) AddRouter added in v1.0.146

func (self *WsServer) AddRouter(path string, handle Handle, routerConfig *RouterConfig)

func (*WsServer) NewPool added in v1.0.146

func (self *WsServer) NewPool(maxConn, limit, bucket, ping int)

func (*WsServer) SendMessage added in v1.0.146

func (self *WsServer) SendMessage(data interface{}, subject string, dev ...string) error

func (*WsServer) StartWebsocket added in v1.0.146

func (self *WsServer) StartWebsocket(addr string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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