core

package module
v0.0.0-...-b91bce1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2014 License: BSD-2-Clause Imports: 11 Imported by: 1

README

core

TypePress WEB framework core, base on Martini.

TypePress WEB 框架核心, 基于 Martini.

提供

  • 全局可访问的对象和类型
  • 子路由
  • 延迟初始化
  • os.Signal 支持

License

BSD-2-Clause

Documentation

Overview

  core 提供全局可用变量, 方法.
  全局可用的类型定义请
	import "github.com/typepress/types"

Index

Constants

View Source
const (
	SessionName    = "TPSession"
	ServerShutDown = "ServerShutDown"
)

Variables

View Source
var (
	// global
	Conf toml.Toml
	Log  log.Loggers
	Db   db.Database
	PWD  string

	RouterGet     martini.Router // GET method only
	RouterPut     martini.Router // PUT method only
	RouterHead    martini.Router // HEAD method only
	RouterPost    martini.Router // POST method only
	RouterAjax    martini.Router // POST method only, with head: X-Requested-With "XMLHttpRequest"
	RouterPatch   martini.Router // PATCH method only
	RouterDelete  martini.Router // DELETE method only
	RouterOptions martini.Router // OPTIONS method only
	RouterAny     martini.Router // Any method
)

Functions

func FireSignal

func FireSignal(sig os.Signal, remove bool)
  FireSignal 按照 LIFO 的次序调用 Listen 增加的监听函数.
  如果捕获到 panic 中断调用, 并且监听函数会被剔除.
  参数:
	sig 指示触发信号
	remove 指示触发后是否剔除掉所有的触发函数

func Handler

func Handler(handler ...martini.Handler)

给内建 *Martini 对象添加 handler

func ListenSignal

func ListenSignal(fn func(os.Signal) bool, sigs ...os.Signal)
 ListenSignal 为监听 sigs 信号增加执行函数.
 参数:
	fn 执行函数, 返回值如果是 true, 表示触发后剔除此函数.
	sigs 为一组要监听的信号, 支持系统信号和自定义信号.

func Martini

func Martini(handler ...martini.Handler) (*martini.Martini, martini.Router)

返回内建 *Martini 和主 Router, 只能调用一次, 再次调用返回 nil. 参数 handler 会优先于通过 Handler 添加的 handler 执行. 已经执行过 .Action(Router.Handle)

func RBAC

func RBAC(rs []string) martini.Handler

RBAC 返回用于角色控制的 Handler 依据 RolesSet 设置的字符串角色集合对参数 rs 进行计算, 得到 types.Role 值并使用 accessflags 生成 Handler

func Recover

func Recover(fn func()) (err interface{})

Recover 执行函数 fn, 返回 recover() 结果

func RegisterInit

func RegisterInit(fn ...func())

注册初始化函数,fn 会在 Martini() 被调用的时候执行.

func RolesSet

func RolesSet(rs ...string)

RolesSet 设置字符串角色名称集合, 用于角色控制. 如果要启用角色控制, 必须在注册路由之前进行设置. 字符串值会被转化为小写, 排序, 剔重. 为 accessflags 传递 types.Role 值做准备.

func RolesToRole

func RolesToRole(rs []string) (x Role)

依据 RolesSet 设置的字符串角色集合对参数 rs 进行计算, 返回 types.Role 值.

func RouterDispatch

func RouterDispatch(res http.ResponseWriter, req *http.Request, c martini.Context)

RouterDispatch 仅用于主路由, 根据 req.Method 分派子路由.

Types

This section is empty.

Jump to

Keyboard shortcuts

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