Documentation ¶
Index ¶
- Variables
- func AddController(ctrlName string, a interface{}, route ...string) (err error)
- func AddController2(ctrlName string, a interface{}, ...) (err error)
- func AddRouter(pattern string)
- func Fserve(ctx *Context, err error) error
- func NSregister(ns *Namespace) error
- func Run()
- func StopRun()
- type Context
- type Controller
- func (c *Controller) Finish()
- func (c *Controller) GetScheme() string
- func (c *Controller) GetURL() string
- func (c *Controller) Prepare()
- func (c *Controller) SetClientCache(second ...int)
- func (c *Controller) SetCookie(name, value string, maxAge int, domain ...string)
- func (c *Controller) WriteData(v ...interface{}) (n int, err error)
- func (c *Controller) WriteJSON(v interface{}) (n int, err error)
- func (c *Controller) WriteString(v string) (n int, err error)
- type Handler
- type Namespace
- type NsController
- type Router
- type SetStaticSpaceFunc
- type URLinfo
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // FserveList 文件服务,可以有多个 FserveList = make([]fserve, 0, 2) // Start 请求进来时执行的方法 Start = func(ctx *Context) {} // End 请求完成时执行的方法 End = func(ctx *Context, panicErr interface{}) { code := 200 if panicErr != nil { if panicErr == Errs.ErrControllerNotFound || panicErr == Errs.ErrFuncNotFound { panicErr = Fserve(ctx, panicErr.(error)) if panicErr != nil { code = 404 http.Error(ctx.W, (panicErr.(error)).Error(), code) } } else { code = 500 err := fmt.Sprint(panicErr) http.Error(ctx.W, err, code) fmt.Println(err) fmt.Println(util.BytesString(debug.Stack())) } } if AppConf.Debug { fmt.Printf("[%s] [%d] [%s] %s | %v\r\n", ctx.R.Method, code, ctx.R.RemoteAddr, ctx.R.URL.Path, time.Since(ctx.Now)) } } )
View Source
var AppConf = new(struct { Debug bool // 调试 FuncPrefix string // 方法前缀 })
AppConf app参数
View Source
var Conf *config.Conf
Conf 参数配置
View Source
var Errs = struct { ErrStopRun error // 主动停止运行产生的错误 ErrControllerNotFound error // 未找到控制器 ErrFuncNotFound error // 未找到方法 }{ errors.New("user stop run"), errors.New("controller not found"), errors.New("function not found"), }
Errs 预定义错误
View Source
var RouterList map[string]*Router
RouterList 路由列表 map[path]路由
Functions ¶
func AddController ¶
AddController 添加控制器 控制器名,控制器结构指针,路由(默认基础路由为 "/")
func AddController2 ¶
func AddController2(ctrlName string, a interface{}, ctrlStaticSpace, funcStaticSpace SetStaticSpaceFunc, route ...string) (err error)
AddController2 添加控制器
Types ¶
type Controller ¶
type Controller struct { Ctx *Context U *URLinfo CtrlStaticSpace, FuncStaticSpace interface{} // 业务方法静态内存空间 }
Controller 基础控制器
func (*Controller) SetClientCache ¶
func (c *Controller) SetClientCache(second ...int)
SetClientCache 设置客户端缓存 second默认很长时间
func (*Controller) SetCookie ¶
func (c *Controller) SetCookie(name, value string, maxAge int, domain ...string)
SetCookie 设置cookie
func (*Controller) WriteData ¶
func (c *Controller) WriteData(v ...interface{}) (n int, err error)
WriteData 应答
func (*Controller) WriteJSON ¶
func (c *Controller) WriteJSON(v interface{}) (n int, err error)
WriteJSON 以json格式数据应答
func (*Controller) WriteString ¶
func (c *Controller) WriteString(v string) (n int, err error)
WriteString 以字符串数据应答
type Handler ¶
type Handler interface { http.Handler HandleFunc(string, func(http.ResponseWriter, *http.Request)) }
Handler 路由处理器
var DefaultHandler Handler = http.DefaultServeMux
DefaultHandler 路由处理器目前使用的是标准库的DefaultServeMux 可以修改这个变量自定义路由处理器
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace Namespace
func NewNameSpace ¶
NewNameSpace 创建命名空间
type NsController ¶
type NsController struct {
// contains filtered or unexported fields
}
NsController NsController
func NSaddController ¶
func NSaddController(name string, c interface{}) *NsController
NSaddController 添加控制器
func (*NsController) SetStaticSpace ¶
func (nc *NsController) SetStaticSpace(cf, ff SetStaticSpaceFunc) *NsController
SetStaticSpace 设置用于设置控制器静态内存空间和业务方法静态内存空间的函数
type Router ¶
type Router struct { C map[string]*controllerType // map[控制器名]*controllerType UNC *controllerType // unnamed controller,可以为空 }
Router 路由
type SetStaticSpaceFunc ¶
type SetStaticSpaceFunc func(ctrlName, funcName string) interface{}
SetStaticSpaceFunc 用于设置静态内存空间的函数类型
Click to show internal directories.
Click to hide internal directories.