webing

package module
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 12 Imported by: 0

README

webing

web application framework

Documentation

Index

Constants

View Source
const (
	DEBUG   string = "debug"
	RELEASE string = "release"
)
View Source
const (
	COOKIE_SAME_SITE_STRICT string = "Strict"
	COOKIE_SAME_SITE_LAX    string = "Lax"
	COOKIE_SAME_SITE_NONE   string = "None"

	SESSION_IDENTITY  string = "__webing_s__"
	SESSION_NAME_KEY  string = "__session_name___"
	SESSION_STORE_KEY string = "__session_store__"
)
View Source
const (
	TOKEN_IDENTITY string = "__webing_t__"
)

================================================================================ * token * author: 美丽的地球啊 - mliu * ================================================================================

Variables

This section is empty.

Functions

func NewPaging

func NewPaging() *glib.Paging

func Start

func Start(args ...BootstrapFunc)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * launch an app * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Types

type ActionHandler

type ActionHandler func(*RequestContext) IActionResult

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Http请求动作接口 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type BootstrapFunc

type BootstrapFunc func(IApp)

================================================================================ * webing web framework * author: 美丽的地球啊 - mliu * ================================================================================

type CommandLine

type CommandLine struct {
	App      string
	Host     string
	Ports    []int
	Db       string
	IsSsl    bool
	IsDebug  bool
	IsTest   bool
	IsOnline bool
}

================================================================================ * webing web framework * author: 美丽的地球啊 - mliu * ================================================================================

type Cookie struct {
	Name       string `json:"name"`
	Path       string `json:"path"`
	Domain     string `json:"domain"`
	MaxAge     int    `json:"max_age"`
	SameSite   string `json:"same_site"`
	IsHttpOnly bool   `json:"is_http_only"` // Strict | Lax | None
	IsSecure   bool   `json:"is_secure"`
}

================================================================================ * session * author: 美丽的地球啊 - mliu * ================================================================================

type CustomError

type CustomError struct {
	Code int32  `json:"code"`
	Msg  string `json:"msg"`
}

================================================================================ * error * author: 美丽的地球啊 - mliu * ================================================================================

func NewCustomError

func NewCustomError(msg string) *CustomError

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * instantiate custom error * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func NewError

func NewError(code int32, msg string) *CustomError

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * instantiate custom error * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (CustomError) Error

func (err CustomError) Error() string

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * error interface implementation * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type Filter

type Filter struct {
	Name string
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * action filter interface * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type IActionFilter

type IActionFilter interface {
	Before(*RequestContext) IActionResult
	After(*RequestContext)
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * action filter interface * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type IActionFilterList

type IActionFilterList []IActionFilter

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * action filter interface * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type IActionResult

type IActionResult interface {
	Render()
}

================================================================================ * result * author: 美丽的地球啊 - mliu * ================================================================================

type IApp

type IApp interface {
	GetName() string
	GetCommandLine() *CommandLine
	GetBootstrap() BootstrapFunc

	Static(routerPath, filePath string)
	NoRoute(requestHandler RequestHandler)
	At(groupName string, actionFilters ...IActionFilter) IHttpAction
	Controller(groupName string, actionFilters ...IActionFilter) IHttpController

	Middleware(requestHandlers ...RequestHandler)
}

================================================================================ * app * author: 美丽的地球啊 - mliu * ================================================================================

func NewApp

func NewApp(name, templatePath string, bootstrapFunc BootstrapFunc) IApp

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * instantiating app * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type IHttpAction

type IHttpAction interface {
	Get(path string, actionHandler ActionHandler, args ...interface{}) IHttpController
	Post(path string, actionHandler ActionHandler, args ...interface{}) IHttpController
	Delete(path string, actionHandler ActionHandler, args ...interface{}) IHttpController
	Patch(path string, actionHandler ActionHandler, args ...interface{}) IHttpController
	Options(path string, actionHandler ActionHandler, args ...interface{}) IHttpController
	Head(path string, actionHandler ActionHandler, args ...interface{}) IHttpController
}

type IHttpController

type IHttpController interface {
	IHttpAction
	GetName() string
	GetToken(ctx *RequestContext) IToken
	GetApp() IApp
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * controller interface * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func NewController

func NewController(name string, app IApp, actionFilters ...IActionFilter) IHttpController

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * instantiating the controller * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type IHttpRouter

type IHttpRouter interface {
	Get(groupName, path string, requestHandler RequestHandler) IHttpRouter
	Post(groupName, path string, requestHandler RequestHandler) IHttpRouter
	Delete(groupName, path string, requestHandler RequestHandler) IHttpRouter
	Patch(groupName, path string, requestHandler RequestHandler) IHttpRouter
	Options(groupName, path string, requestHandler RequestHandler) IHttpRouter
	Head(groupName, path string, requestHandler RequestHandler) IHttpRouter
	NoRoute(requestHandler RequestHandler)
}

================================================================================ * http router * author: 美丽的地球啊 - mliu * ================================================================================

func NewHttpRouter

func NewHttpRouter(httpEngine *httpEngine) IHttpRouter

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * instantiating http router * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type ISession

type ISession interface {
	//SessionId() string
	Get(key interface{}) interface{}
	Set(key interface{}, val interface{})
	Values() map[interface{}]interface{}
	AddFlash(value interface{}, vars ...string)
	Flashes(vars ...string) []interface{}
	Save() error
	Delete(key interface{})
	Clear()
	Options(Cookie)
}

================================================================================ * session * author: 美丽的地球啊 - mliu * ================================================================================

type ISessionStore

type ISessionStore interface {
	sessions.Store
}

================================================================================ * session * author: 美丽的地球啊 - mliu * ================================================================================

type IToken

type IToken interface {
	GetToken() string
	ParseToken(token, userAgent string) error

	GetPayload() *TokenPayload
	SetPayload(payload *TokenPayload)

	SetExpire(expire int64)
	SetAuthenticated(isAuthenticated bool)

	IsAuthenticated() bool
	IsExpired() bool
	IsValid() bool
}

type PagingResult

type PagingResult struct {
	Result
	Paging *glib.Paging `json:"paging"`
}

================================================================================ * result * author: 美丽的地球啊 - mliu * ================================================================================

type RequestContext

type RequestContext struct {
	*gin.Context
}

================================================================================ * request context * author: 美丽的地球啊 - mliu * ================================================================================

func (*RequestContext) ClearSession

func (ctx *RequestContext) ClearSession()

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * clear session * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*RequestContext) DeleteSession

func (ctx *RequestContext) DeleteSession(name string)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * remove session value * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*RequestContext) GetApp

func (ctx *RequestContext) GetApp() IApp

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * get app * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*RequestContext) GetSession

func (ctx *RequestContext) GetSession(name string) string

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * get session value * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*RequestContext) GetToken

func (ctx *RequestContext) GetToken() IToken

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * get token * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*RequestContext) IsAjax

func (ctx *RequestContext) IsAjax() bool

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * is ajax request * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*RequestContext) SetSession

func (ctx *RequestContext) SetSession(name, value string)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * set session value * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*RequestContext) ValidateSession

func (ctx *RequestContext) ValidateSession(name, value string, args ...interface{}) bool

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * validate session value * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type RequestHandler

type RequestHandler func(*RequestContext)

================================================================================ * request context * author: 美丽的地球啊 - mliu * ================================================================================

type Result

type Result struct {
	Code int32       `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

================================================================================ * result * author: 美丽的地球啊 - mliu * ================================================================================

func NewResult

func NewResult() *Result

func (*Result) SetError

func (result *Result) SetError(err error)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * set error status information * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type Token

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

func NewToken

func NewToken(secret string) *Token

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * instantiating token * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) GetPayload

func (s *Token) GetPayload() *TokenPayload

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * get payload * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) GetToken

func (s *Token) GetToken() string

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * get token string * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) IsAuthenticated

func (s *Token) IsAuthenticated() bool

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * is certified * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) IsExpired

func (s *Token) IsExpired() bool

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * has token expired * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) IsValid

func (s *Token) IsValid() bool

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * token signature is valid * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) ParseToken

func (s *Token) ParseToken(token, userAgent string) error

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * parse token * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) SetAuthenticated

func (s *Token) SetAuthenticated(isAuthenticated bool)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * set is certified * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) SetExpire

func (s *Token) SetExpire(expire int64)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * set expire * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Token) SetPayload

func (s *Token) SetPayload(payload *TokenPayload)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * set payload * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type TokenPayload

type TokenPayload struct {
	Owner           string                 `json:"iss"`              //签发者
	Domain          string                 `json:"aud"`              //接收域
	AccountId       string                 `json:"account_id"`       //账号id
	AccountName     string                 `json:"account_name"`     //账号名
	UserId          string                 `json:"sub"`              //用户id
	Nickname        string                 `json:"nickname"`         //用户昵称
	Avatar          string                 `json:"avatar"`           //用户图像
	Roles           []string               `json:"roles"`            //角色名集合
	UserAgent       string                 `json:"ua"`               //客户端代理数据
	Extend          map[string]interface{} `json:"extend"`           //扩展数据
	IsAuthenticated bool                   `json:"is_authenticated"` //是否已验证
	Start           int64                  `json:"iat"`              //签发时间(距离1970-1-1的秒数)
	Expire          int64                  `json:"exp"`              //过期时间(距离1970-1-1的秒数)
}

func (*TokenPayload) AccountIdInt64 added in v0.1.7

func (s *TokenPayload) AccountIdInt64() int64

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * AccountId string to AccountId int64 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*TokenPayload) Deserialize

func (s *TokenPayload) Deserialize(payload string) error

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * TokenPayload json deserialization * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*TokenPayload) Serialize

func (s *TokenPayload) Serialize() (string, error)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * TokenPayload json serialization * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*TokenPayload) UserIdInt64

func (s *TokenPayload) UserIdInt64() int64

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * UserId string to UserId int64 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Directories

Path Synopsis
middleware
plugin

Jump to

Keyboard shortcuts

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