actions

package
v0.0.0-...-7647e70 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 35 Imported by: 127

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunAction

func RunAction(actionPtr interface{},
	spec *ActionSpec,
	request *http.Request,
	responseWriter http.ResponseWriter,
	params Params,
	helpers []interface{},
	initData Data,
) interface{}

RunAction 执行某个Action

Types

type Action

type Action struct {
	ActionObject
}

type ActionContext

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

ActionContext 上下文变量容器

func NewActionContext

func NewActionContext() *ActionContext

NewActionContext 获取新对象

func (*ActionContext) Get

func (this *ActionContext) Get(key string) interface{}

Get 获取变量

func (*ActionContext) GetBool

func (this *ActionContext) GetBool(key string) bool

GetBool 获取bool变量

func (*ActionContext) GetInt

func (this *ActionContext) GetInt(key string) int

GetInt 获取int变量

func (*ActionContext) GetInt64

func (this *ActionContext) GetInt64(key string) int64

GetInt64 获取int64变量

func (*ActionContext) GetString

func (this *ActionContext) GetString(key string) string

GetString 获取string变量

func (*ActionContext) Set

func (this *ActionContext) Set(key string, value interface{})

Set 设置变量

type ActionObject

type ActionObject struct {
	Spec *ActionSpec

	Request        *http.Request
	ResponseWriter http.ResponseWriter
	ParamsMap      Params

	Context *ActionContext

	Module string

	Code    int
	Data    Data
	Message string

	SessionManager interface{}

	Files []*File
	// contains filtered or unexported fields
}

func (*ActionObject) AddCookie

func (this *ActionObject) AddCookie(cookie *http.Cookie)

AddCookie 设置cookie

func (*ActionObject) AddHeader

func (this *ActionObject) AddHeader(name, value string)

AddHeader 设置头部信息

func (*ActionObject) Cache

func (this *ActionObject) Cache() *caches.Factory

Cache 缓存

func (*ActionObject) Error

func (this *ActionObject) Error(error string, code int)

输出错误信息

func (*ActionObject) Fail

func (this *ActionObject) Fail(message ...string)

Fail 失败返回

func (*ActionObject) FailField

func (this *ActionObject) FailField(field string, message ...string)

FailField 字段错误提示

func (*ActionObject) File

func (this *ActionObject) File(field string) *File

File 取得单个文件

func (*ActionObject) HasParam

func (this *ActionObject) HasParam(name string) bool

HasParam 判断是否有参数

func (*ActionObject) HasPrefix

func (this *ActionObject) HasPrefix(prefix ...string) bool

HasPrefix 判断URL的Path部分是否包含任一前缀

func (*ActionObject) Header

func (this *ActionObject) Header(name string) string

Header 获取Header值

func (*ActionObject) Next

func (this *ActionObject) Next(nextAction string, params map[string]interface{}, hash ...string) *ActionObject

Next 设置下一个动作

func (*ActionObject) Object

func (this *ActionObject) Object() *ActionObject

Object 取得内置的动作对象

func (*ActionObject) Param

func (this *ActionObject) Param(name string) (value string, found bool)

Param 获取参数

func (*ActionObject) ParamArray

func (this *ActionObject) ParamArray(name string) []string

ParamArray 获取参数数组

func (*ActionObject) ParamInt

func (this *ActionObject) ParamInt(name string) int

ParamInt 获取整型参数

func (*ActionObject) ParamInt64

func (this *ActionObject) ParamInt64(name string) int64

ParamInt64 获取int64参数

func (*ActionObject) ParamString

func (this *ActionObject) ParamString(name string) string

ParamString 获取字符串参数

func (*ActionObject) Pretty

func (this *ActionObject) Pretty() *ActionObject

Pretty 输出格式化后的JSON

func (*ActionObject) RedirectURL

func (this *ActionObject) RedirectURL(url string)

RedirectURL 跳转

func (*ActionObject) Refresh

func (this *ActionObject) Refresh() *ActionObject

Refresh 设置刷新

func (*ActionObject) RequestRemoteAddr

func (this *ActionObject) RequestRemoteAddr() string

RequestRemoteAddr 获取客户端的地址,有可能会包含端口

func (*ActionObject) RequestRemoteIP

func (this *ActionObject) RequestRemoteIP() string

RequestRemoteIP 获取客户端的地址

func (*ActionObject) Session

func (this *ActionObject) Session() *Session

Session 读取Session

func (*ActionObject) SetMaxSize

func (this *ActionObject) SetMaxSize(maxSize float64)

SetMaxSize 设置能接收的最大数据(字节)

func (*ActionObject) SetParam

func (this *ActionObject) SetParam(name, value string)

SetParam 设置参数

func (*ActionObject) SetSessionCookieName

func (this *ActionObject) SetSessionCookieName(cookieName string)

SetSessionCookieName 设置Session Cookie名称

func (*ActionObject) SetSessionManager

func (this *ActionObject) SetSessionManager(sessionManager interface{})

SetSessionManager 设置Session管理器

func (*ActionObject) Show

func (this *ActionObject) Show()

Show 显示模板

func (*ActionObject) Success

func (this *ActionObject) Success(message ...string)

Success 成功返回

func (*ActionObject) TemplateFilter

func (this *ActionObject) TemplateFilter(filter func(body []byte) []byte)

TemplateFilter 设置模板过滤器

func (*ActionObject) View

func (this *ActionObject) View(viewTemplate string)

View 设置模板文件

func (*ActionObject) ViewDir

func (this *ActionObject) ViewDir(viewDir string)

ViewDir 设置模板目录

func (*ActionObject) ViewFunc

func (this *ActionObject) ViewFunc(name string, f interface{})

ViewFunc 设置模板文件中可以使用的自定义函数

func (*ActionObject) Write

func (this *ActionObject) Write(bytes []byte) (n int, err error)

输出二进制字节

func (*ActionObject) WriteFormat

func (this *ActionObject) WriteFormat(format string, args ...interface{}) (n int, err error)

WriteFormat 输出可以格式化的内容

func (*ActionObject) WriteJSON

func (this *ActionObject) WriteJSON(value interface{})

WriteJSON 写入JSON

func (*ActionObject) WriteString

func (this *ActionObject) WriteString(output ...string)

WriteString 输出内容

type ActionParamError

type ActionParamError struct {
	Param    string   `json:"param"`
	Messages []string `json:"messages"`
}

type ActionSpec

type ActionSpec struct {
	Type reflect.Type

	BeforeFunc *reflect.Value
	AfterFunc  *reflect.Value

	FuncMap map[string]*reflect.Value

	Module    string
	PkgPath   string
	ClassName string

	caches.CacheFactory

	Context *ActionContext
}

ActionSpec Action相关定义

func NewActionSpec

func NewActionSpec(actionPtr ActionWrapper) *ActionSpec

NewActionSpec 创建新定义

func (*ActionSpec) HasClassPrefix

func (this *ActionSpec) HasClassPrefix(prefix ...string) bool

HasClassPrefix class名是否包含任一前缀

func (*ActionSpec) NewPtrValue

func (this *ActionSpec) NewPtrValue() reflect.Value

NewPtrValue 新建一个Action指针

type ActionWrapper

type ActionWrapper interface {
	Object() *ActionObject
}

ActionWrapper 读取ActionObject对象的接口

type ActionWriter

type ActionWriter interface {
	Write([]byte) (n int, err error)
}

type Data

type Data = maps.Map

type File

type File struct {
	OriginFile *multipart.FileHeader

	Filename    string
	Size        int64
	Field       string
	Ext         string
	ContentType string
}

File 上传的文件封装

func (*File) Read

func (this *File) Read() ([]byte, error)

Read 读取文件内容

func (*File) Reader

func (this *File) Reader() (io.ReadCloser, error)

func (*File) WriteTo

func (this *File) WriteTo(writer io.Writer) (int64, error)

WriteTo 将文件内容写入到writer中

func (*File) WriteToPath

func (this *File) WriteToPath(path string) (int64, error)

WriteToPath 写入一个文件路径中

type Gzip

type Gzip struct {
	Level int
	// contains filtered or unexported fields
}

func (*Gzip) AfterAction

func (this *Gzip) AfterAction()

func (*Gzip) BeforeAction

func (this *Gzip) BeforeAction(ptr ActionWrapper, paramName string) (goNext bool)

func (*Gzip) Write

func (this *Gzip) Write(data []byte) (n int, err error)

type JSON

type JSON map[string]interface{}

type Must

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

func (*Must) BeforeAction

func (this *Must) BeforeAction(actionPtr ActionWrapper, paramName string) (goNext bool)

func (*Must) Code

func (this *Must) Code(code int) *Must

func (*Must) Email

func (this *Must) Email(message string) *Must

func (*Must) Equal

func (this *Must) Equal(value string, message string) *Must

func (*Must) Errors

func (this *Must) Errors() []ActionParamError

func (*Must) Expect

func (this *Must) Expect(fn func() (message string, success bool)) *Must

func (*Must) Field

func (this *Must) Field(field string, value interface{}) *Must

func (*Must) Gt

func (this *Must) Gt(value int64, message string) *Must

func (*Must) Gte

func (this *Must) Gte(value int64, message string) *Must

func (*Must) HasErrors

func (this *Must) HasErrors() bool

func (*Must) In

func (this *Must) In(values interface{}, message string) *Must

判断是否在一个值列表中

func (*Must) Lt

func (this *Must) Lt(value int64, message string) *Must

func (*Must) Lte

func (this *Must) Lte(value int64, message string) *Must

func (*Must) Match

func (this *Must) Match(expr string, message string) *Must

func (*Must) MaxCharacters

func (this *Must) MaxCharacters(charactersLength int, message string) *Must

最大字符长度

func (*Must) MaxLength

func (this *Must) MaxLength(length int, message string) *Must

最大长度

func (*Must) MinCharacters

func (this *Must) MinCharacters(charactersLength int, message string) *Must

最小字符长度

func (*Must) MinLength

func (this *Must) MinLength(length int, message string) *Must

最小长度

func (*Must) Mobile

func (this *Must) Mobile(message string) *Must

func (*Must) Require

func (this *Must) Require(message string) *Must

func (*Must) Trim

func (this *Must) Trim() *Must

func (*Must) Value

func (this *Must) Value(value interface{}) *Must

type Params

type Params map[string][]string

type Session

type Session struct {
	Sid     string
	Manager interface{}
}

Session定义

func (*Session) Delete

func (this *Session) Delete() bool

删除整个session

func (*Session) GetBool

func (this *Session) GetBool(key string) bool

获取bool值

func (*Session) GetFloat32

func (this *Session) GetFloat32(key string) float32

获取float32值

func (*Session) GetFloat64

func (this *Session) GetFloat64(key string) float64

获取64值

func (*Session) GetInt

func (this *Session) GetInt(key string) int

获取int值

func (*Session) GetInt32

func (this *Session) GetInt32(key string) int32

获取int32值

func (*Session) GetInt64

func (this *Session) GetInt64(key string) int64

获取int64值

func (*Session) GetString

func (this *Session) GetString(key string) string

获取字符串值

func (*Session) GetUint

func (this *Session) GetUint(key string) uint

获取uint值

func (*Session) GetUint32

func (this *Session) GetUint32(key string) uint32

获取uint32值

func (*Session) GetUint64

func (this *Session) GetUint64(key string) uint64

获取uint64值

func (*Session) SetSid

func (this *Session) SetSid(sid string)

设置sid

func (*Session) Values

func (this *Session) Values() map[string]string

取得所有存储在session中的值

func (*Session) Write

func (this *Session) Write(key, value string) bool

写入值

func (*Session) WriteInt

func (this *Session) WriteInt(key string, value int) bool

写入int值

func (*Session) WriteInt32

func (this *Session) WriteInt32(key string, value int32) bool

写入int32值

func (*Session) WriteInt64

func (this *Session) WriteInt64(key string, value int64) bool

写入int64值

func (*Session) WriteUint

func (this *Session) WriteUint(key string, value uint) bool

写入uint值

func (*Session) WriteUint32

func (this *Session) WriteUint32(key string, value uint32) bool

写入uint32值

func (*Session) WriteUint64

func (this *Session) WriteUint64(key string, value uint64) bool

写入uint64值

type SessionConfig

type SessionConfig struct {
	Life   uint
	Secret string
}

SESSION通用配置

type SessionWrapper

type SessionWrapper interface {
	Init(config *SessionConfig)
	Read(sid string) map[string]string
	WriteItem(sid string, key string, value string) bool
	Delete(sid string) bool
}

SESSION管理器接口

type Template

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

Template 模板定义

func NewTemplate

func NewTemplate(name string) *Template

NewTemplate 创建新模板

func (*Template) AddVar

func (this *Template) AddVar(varName, value string) *Template

AddVar 添加变量

func (*Template) Delims

func (this *Template) Delims(left, right string) *Template

Delims 设置分隔符

func (*Template) Execute

func (this *Template) Execute(wr io.Writer, data interface{}) error

Execute 执行模板

func (*Template) ExecuteTemplate

func (this *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error

ExecuteTemplate 执行模板

func (*Template) Funcs

func (this *Template) Funcs(funcMap template.FuncMap) *Template

Funcs 设置函数

func (*Template) HasVar

func (this *Template) HasVar(varName string) bool

HasVar 判断是否有某个变量

func (*Template) NewChild

func (this *Template) NewChild(name string) *Template

NewChild 获取子模板

func (*Template) Parse

func (this *Template) Parse(text string) (*Template, error)

Parse 分析文本

func (*Template) SetVars

func (this *Template) SetVars(vars maps.Map) *Template

SetVars 设置变量

func (*Template) VarValue

func (this *Template) VarValue(varName string) string

VarValue 取得变量值

type TemplateCache

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

type Testing

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

func NewTesting

func NewTesting(actionPtr ActionWrapper) *Testing

新建测试实例

func (*Testing) AddHeader

func (this *Testing) AddHeader(key string, value string) *Testing

添加Header

func (*Testing) Cost

func (this *Testing) Cost() *Testing

计算耗时

func (*Testing) Method

func (this *Testing) Method(method string) *Testing

设置请求方法

func (*Testing) Params

func (this *Testing) Params(params Params) *Testing

设置参数

func (*Testing) RemoteAddr

func (this *Testing) RemoteAddr(remoteAddr string) *Testing

设置终端地址

func (*Testing) Run

func (this *Testing) Run(t *testing.T) *TestingResponseWriter

执行

func (*Testing) SetHeader

func (this *Testing) SetHeader(key string, value string) *Testing

设置Header

func (*Testing) URL

func (this *Testing) URL(urlString string) *Testing

设置URL

type TestingResponseWriter

type TestingResponseWriter struct {
	Data []byte
}

func (*TestingResponseWriter) Header

func (this *TestingResponseWriter) Header() http.Header

func (*TestingResponseWriter) Write

func (this *TestingResponseWriter) Write(data []byte) (int, error)

func (*TestingResponseWriter) WriteHeader

func (this *TestingResponseWriter) WriteHeader(int)

Jump to

Keyboard shortcuts

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