node

package
v1.0.25 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP    = 0
	WEBSOCK = 1
	UTF8    = "UTF-8"
)
View Source
const (
	TEXT_HTML        = "text/html"
	TEXT_PLAIN       = "text/plain"
	APPLICATION_JSON = "application/json"
)

Variables

View Source
var (
	Global = GlobalConfig{TokenName: "token"}
)

Functions

This section is empty.

Types

type CacheSessionManager

type CacheSessionManager struct {
}

func (*CacheSessionManager) Create

func (self *CacheSessionManager) Create(s Session) error

func (*CacheSessionManager) Delete

func (self *CacheSessionManager) Delete(s Session) error

func (*CacheSessionManager) GetActiveSessions

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

func (*CacheSessionManager) ReadSession

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

func (*CacheSessionManager) Update

func (self *CacheSessionManager) Update(s Session) error

type Context

type Context struct {
	Host       string
	Connection int
	Header     map[string]interface{}
	Params     map[string]interface{}
	Session    Session
	Response   *Response
}

type DefaultNode

type DefaultNode struct {
	Context        *Context
	SessionManager SessionManager
	OverrideFunc   *OverrideFunc
}

type GlobalConfig

type GlobalConfig struct {
	TokenName string
}

type HttpNode

type HttpNode struct {
	DefaultNode
	Input    *http.Request
	Output   http.ResponseWriter
	TemplDir string
}

func (*HttpNode) AfterCompletion

func (self *HttpNode) AfterCompletion(handle func(ctx *Context, resp *Response, err error) error, err error) error

func (*HttpNode) BindFuncByRouter

func (self *HttpNode) BindFuncByRouter(pattern string, handle func(ctx *Context) error)

func (*HttpNode) GetHeader

func (self *HttpNode) GetHeader(input interface{}) error

func (*HttpNode) GetParams

func (self *HttpNode) GetParams(input interface{}) error

func (*HttpNode) Html

func (self *HttpNode) Html(ctx *Context, view string, data interface{}) error

func (*HttpNode) InitContext

func (self *HttpNode) InitContext(ob, output, input interface{}) error

func (*HttpNode) Json

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

func (*HttpNode) PostHandle

func (self *HttpNode) PostHandle(handle func(resp *Response, err error) error, err error) error

func (*HttpNode) PreHandle

func (self *HttpNode) PreHandle(handle func(ctx *Context) error) error

func (*HttpNode) Proxy

func (self *HttpNode) Proxy(output, input interface{}, handle func(ctx *Context) error)

func (*HttpNode) Render

func (self *HttpNode) Render() error

func (*HttpNode) RenderError

func (self *HttpNode) RenderError(err error)

func (*HttpNode) SetContentType

func (self *HttpNode) SetContentType(contentType string)

func (*HttpNode) StartServer

func (self *HttpNode) StartServer()

func (*HttpNode) Text

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

func (*HttpNode) ValidSession

func (self *HttpNode) ValidSession() error

type JWTSession

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

func (*JWTSession) Build

func (self *JWTSession) Build(sub *jwt.Subject, srt string) (*jwt.Authorization, error)

func (*JWTSession) Expire

func (self *JWTSession) Expire() error

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) IsValid

func (self *JWTSession) IsValid() 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) 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() error

type OverrideFunc

type OverrideFunc struct {
	GetHeaderFunc       func(input interface{}) error
	GetParamsFunc       func(input interface{}) error
	PreHandleFunc       func(ctx *Context) error
	PostHandleFunc      func(resp *Response, err error) error
	AfterCompletionFunc func(ctx *Context, resp *Response, err error) error
	RenderErrorFunc     func(err error) error
	SessionHandleFunc   func(ctx *Context) error
}

type Response

type Response struct {
	ContentEncoding string
	ContentType     string
	RespEntity      interface{}
	TemplDir        string
	RespView        string
}

type Session

type Session interface {
	GetId() string

	GetStartTimestamp() int64

	GetLastAccessTime() int64

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

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

	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() error

	IsValid() bool
}

type SessionManager

type SessionManager interface {
	Create(s Session) error // 保存session

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

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

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

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

type ViewConfig

type ViewConfig struct {
	BaseDir  string
	Suffix   string
	FileName []string
	Templ    *template.Template
}

type WebNode

type WebNode interface {
	// 初始化上下文
	InitContext(ob, output, input interface{}) error
	// 校验会话
	ValidSession() error
	// 获取请求头数据
	GetHeader(input interface{}) error
	// 获取请求参数
	GetParams(input interface{}) error
	// 设置响应头格式
	SetContentType(contentType string)
	// 核心代理方法
	Proxy(output, input interface{}, handle func(ctx *Context) error)
	// 核心绑定路由方法
	BindFuncByRouter(pattern string, handle func(ctx *Context) error)
	// html响应模式
	Html(ctx *Context, view string, data interface{}) error
	// json响应模式
	Json(ctx *Context, data interface{}) error
	// text响应模式
	Text(ctx *Context, data interface{}) error
	// 前置检测方法(业务方法前执行)
	PreHandle(handle func(ctx *Context) error) error
	// 业务执行方法->自定义处理执行方法(业务方法执行后,视图渲染前执行)
	PostHandle(handle func(resp *Response, err error) error, err error) error
	// 最终响应执行方法(视图渲染后执行,可操作资源释放,保存日志等)
	AfterCompletion(handle func(ctx *Context, resp *Response, err error) error, err error) error
	// 渲染输出
	Render() error
	// 异常错误响应方法
	RenderError(err error)
	// 启动服务
	StartServer()
}

Jump to

Keyboard shortcuts

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