Documentation ¶
Overview ¶
Package webx is a simple and powerful web framework for Go.
Installation ¶
Make sure you have installed Go 1.1+ and then:
go get github.com/coscms/webx
More usage, please visit https://github.com/coscms/webx/
Package web is a lightweight web framework for Go. It's ideal for writing simple, performant backend web services.
Index ¶
- Constants
- Variables
- func Abort(code int, content ...string) error
- func Add(left interface{}, right interface{}) interface{}
- func AddAction(c ...interface{})
- func AddApp(a *App)
- func AddConfig(name string, value interface{})
- func AddEvent(eventName string, handler func(interface{}, func(bool)))
- func AddFilter(filter Filter)
- func AddRouter(url string, c interface{})
- func Assign(name string, varOrFun interface{})
- func AutoAction(c ...interface{})
- func AvgTime(items []time.Duration) time.Duration
- func BuildUrl(route, appName, servName string, size int) string
- func Close()
- func CloseZWriter(zwriter io.Writer)
- func Css(raw string) template.CSS
- func DelEvent(eventName string)
- func Download(w http.ResponseWriter, fpath string) error
- func Eq(left interface{}, right interface{}) bool
- func Error(w http.ResponseWriter, status int, content string) error
- func Event(eventName string, session interface{}, next func(bool))
- func FixDirSeparator(dir string) string
- func Forbidden(content ...string) error
- func FormatDate(t time.Time, format string) string
- func FriendlyBytes(bytes uint64) string
- func FriendlyTime(d time.Duration) string
- func GetAcceptEncodingZip(r *http.Request) string
- func GoEvent(eventName string, session interface{}, next func(bool))
- func Html(raw string) template.HTML
- func HtmlAttr(raw string) template.HTMLAttr
- func InternalServerError(content ...string) error
- func IsNil(a interface{}) bool
- func JoinPath(paths ...string) string
- func Js(raw string) template.JS
- func MultiAssign(t *T)
- func NewCookie(name string, value string, args ...interface{}) *http.Cookie
- func NotFound(content ...string) error
- func NotSupported(content ...string) error
- func Now() time.Time
- func PKCS5Padding(ciphertext []byte, blockSize int) []byte
- func PKCS5UnPadding(origData []byte) []byte
- func PageSize(total, limit int) int
- func PrintGCSummary(w io.Writer)
- func Process(w http.ResponseWriter, req *http.Request)
- func Run(addr string)
- func RunFcgi(addr string)
- func RunScgi(addr string)
- func RunTLS(addr string, config *tls.Config)
- func SetLogger(logger *log.Logger)
- func SetStaticDir(dir string)
- func SetTemplateDir(dir string)
- func SimpleParse(data string) map[string]string
- func SimpleTLSConfig(certFile, keyFile string) (*tls.Config, error)
- func Slug(s string, sep string) string
- func SplitJson(s string) ([]string, error)
- func StartCPUProfile()
- func StopCPUProfile()
- func Subtract(left interface{}, right interface{}) interface{}
- func Ternary(express bool, trueVal interface{}, falseVal interface{}) interface{}
- func ToHtmlAttrs(raw map[string]interface{}) (r map[template.HTMLAttr]interface{})
- func UnTitle(s string) string
- func Unauthorized(content ...string) error
- func Url(args ...string) string
- func UrlFor(args ...string) string
- func Urlencode(data map[string]string) string
- func XsrfName() string
- func ZeroPadding(ciphertext []byte, blockSize int) []byte
- func ZeroUnPadding(origData []byte) []byte
- type AbortError
- type Action
- func (c *Action) Abort(status int, body string) error
- func (c *Action) Arg(k int) string
- func (c *Action) Args() []string
- func (c *Action) Assign(name string, varOrFunc interface{})
- func (c *Action) BasePath() string
- func (c *Action) Body() []byte
- func (c *Action) BuildUrl(m string, obj interface{}) (jurl string)
- func (c *Action) Cookie(key string) string
- func (c *Action) CookieAuthKey() string
- func (c *Action) Debug(params ...interface{})
- func (c *Action) Debugf(format string, params ...interface{})
- func (c *Action) DelSession(keys ...string)
- func (c *Action) DisableHttpCache()
- func (c *Action) Domain() string
- func (c *Action) Error(params ...interface{})
- func (c *Action) Errorf(format string, params ...interface{})
- func (c *Action) Fatal(params ...interface{})
- func (c *Action) Fatalf(format string, params ...interface{})
- func (c *Action) Flush()
- func (c *Action) GetBool(key string) (bool, error)
- func (c *Action) GetConfig(name string) interface{}
- func (c *Action) GetConfigString(name string) string
- func (c *Action) GetCookie(cookieName string) (*http.Cookie, error)
- func (c *Action) GetFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (c *Action) GetFloat(key string) (float64, error)
- func (c *Action) GetForm() url.Values
- func (c *Action) GetFuncs() template.FuncMap
- func (c *Action) GetInt(key string) (int64, error)
- func (c *Action) GetLogger() *log.Logger
- func (c *Action) GetSecureCookie(name string) (string, bool)
- func (c *Action) GetSession(key string) interface{}
- func (c *Action) GetSlice(key string) []string
- func (c *Action) GetString(key string) string
- func (c *Action) Go(m string, anotherc ...interface{}) error
- func (c *Action) Header(key string) string
- func (c *Action) Host() string
- func (c *Action) HttpCache(content []byte) bool
- func (c *Action) IP() string
- func (c *Action) Include(tmplName string, args ...interface{}) interface{}
- func (c *Action) Info(params ...interface{})
- func (c *Action) Infof(format string, params ...interface{})
- func (c *Action) Is(method string) bool
- func (c *Action) IsAjax() bool
- func (c *Action) IsSecure() bool
- func (c *Action) IsUpload() bool
- func (c *Action) IsWebsocket() bool
- func (c *Action) MapForm(st interface{}, names ...string) error
- func (c *Action) Method() string
- func (c *Action) MultiAssign(t *T)
- func (c *Action) NamedRender(name, content string, params ...*T) error
- func (c *Action) Namespace() string
- func (c *Action) NewCookie(name string, value string, args ...interface{}) *http.Cookie
- func (c *Action) NotFound(message string) error
- func (c *Action) NotModified()
- func (c *Action) Panic(params ...interface{})
- func (c *Action) Panicf(format string, params ...interface{})
- func (c *Action) Port() int
- func (c *Action) Protocol() string
- func (c *Action) Proxy() []string
- func (c *Action) Query(key string) string
- func (c *Action) Redirect(url string, status ...int) error
- func (c *Action) Refer() string
- func (c *Action) Render(tmpl string, params ...*T) (err error)
- func (c *Action) RenderString(content string, params ...*T) error
- func (c *Action) SaveToFile(fromfile, tofile string) error
- func (c *Action) Scheme() string
- func (c *Action) Self() interface{}
- func (c *Action) ServeFile(fpath string)
- func (c *Action) ServeJson(obj interface{})
- func (c *Action) ServeJsonp(obj interface{}, callback string)
- func (c *Action) ServeXml(obj interface{})
- func (c *Action) Session() *httpsession.Session
- func (c *Action) SetArg(k int, v string) bool
- func (c *Action) SetBody(content []byte) error
- func (c *Action) SetConfig(name string, value interface{})
- func (c *Action) SetConfigString(name string, value string)
- func (c *Action) SetContentType(val string) string
- func (c *Action) SetCookie(cookie *http.Cookie)
- func (c *Action) SetHeader(key string, value string)
- func (c *Action) SetSecureCookie(name string, val string, args ...interface{})
- func (c *Action) SetSession(key string, value interface{})
- func (c *Action) Site() string
- func (c *Action) SubDomains() string
- func (c *Action) Uri() string
- func (c *Action) Url() string
- func (c *Action) UserAgent() string
- func (c *Action) Warn(params ...interface{})
- func (c *Action) Warnf(format string, params ...interface{})
- func (c *Action) Write(content string, values ...interface{}) error
- func (c *Action) WriteBytes(bytes []byte) error
- func (c *Action) XsrfFormHtml() template.HTML
- func (c *Action) XsrfValue() string
- type ActionInformation
- type ActionOption
- type AesCrypto
- type App
- func (app *App) Action(name string) interface{}
- func (app *App) AddAction(cs ...interface{})
- func (app *App) AddFilter(filter Filter)
- func (app *App) AddRouter(url string, c interface{})
- func (app *App) Assign(name string, varOrFun interface{})
- func (app *App) AutoAction(cs ...interface{})
- func (a *App) Close()
- func (app *App) Debug(params ...interface{})
- func (app *App) Debugf(format string, params ...interface{})
- func (a *App) DelDomain()
- func (a *App) ElapsedTime() float64
- func (a *App) ElapsedTimeString() string
- func (app *App) Error(params ...interface{})
- func (app *App) Errorf(format string, params ...interface{})
- func (app *App) Fatal(params ...interface{})
- func (app *App) Fatalf(format string, params ...interface{})
- func (app *App) GetConfig(name string) interface{}
- func (app *App) GetConfigString(name string) string
- func (app *App) Info(params ...interface{})
- func (app *App) Infof(format string, params ...interface{})
- func (a *App) InitHeadContent(w http.ResponseWriter, contentLength int64)
- func (a *App) IsRootApp() bool
- func (app *App) MultiAssign(t *T)
- func (app *App) Nodes() (r map[string]map[string][]string)
- func (app *App) Panic(params ...interface{})
- func (app *App) Panicf(format string, params ...interface{})
- func (app *App) Redirect(w http.ResponseWriter, requestPath, url string, status ...int) error
- func (a *App) SafelyCall(fn reflect.Value, args []reflect.Value) (resp []reflect.Value, err error)
- func (app *App) SetConfig(name string, val interface{})
- func (app *App) SetConfigString(name string, val string)
- func (a *App) SetDomain(domain string)
- func (a *App) SetStaticDir(dir string)
- func (a *App) SetTemplateDir(path string)
- func (a *App) StaticUrl(url string) string
- func (a *App) StructMap(m interface{}, r *http.Request) error
- func (a *App) TryServingFile(name string, req *http.Request, w http.ResponseWriter) (bool, int64)
- func (a *App) VisitedLog(req *http.Request, statusCode int, requestPath string, responseSize int64)
- func (app *App) Warn(params ...interface{})
- func (app *App) Warnf(format string, params ...interface{})
- type AppConfig
- type AutoResponse
- type CONF
- func (a *CONF) DelBool(k string)
- func (a *CONF) DelByte(k string)
- func (a *CONF) DelConf(k string)
- func (a *CONF) DelFloat(k string)
- func (a *CONF) DelInt(k string)
- func (a *CONF) DelInterface(k string)
- func (a *CONF) DelString(k string)
- func (a *CONF) GetBool(k string) bool
- func (a *CONF) GetByte(k string) []byte
- func (a *CONF) GetConf(k string) *CONF
- func (a *CONF) GetFloat(k string) float64
- func (a *CONF) GetInt(k string) int64
- func (a *CONF) GetInterface(k string) interface{}
- func (a *CONF) GetString(k string) string
- func (a *CONF) Init()
- func (a *CONF) InitBool()
- func (a *CONF) InitByte()
- func (a *CONF) InitConf()
- func (a *CONF) InitFloat()
- func (a *CONF) InitInt()
- func (a *CONF) InitInterface()
- func (a *CONF) InitString()
- func (a *CONF) SetBool(k string, v bool)
- func (a *CONF) SetByte(k string, v []byte)
- func (a *CONF) SetConf(k string, v *CONF)
- func (a *CONF) SetFloat(k string, v float64)
- func (a *CONF) SetInt(k string, v int64)
- func (a *CONF) SetInterface(k string, v interface{})
- func (a *CONF) SetString(k string, v string)
- type Cryptor
- type EventsInstance
- func (e *EventsInstance) Delete(eventName string)
- func (e *EventsInstance) Execute(eventName string, session interface{}, next func(bool))
- func (e *EventsInstance) GoExecute(eventName string, session interface{}, next func(bool))
- func (e *EventsInstance) Register(eventName string, handler func(interface{}, func(bool)))
- type FILE
- type Filter
- type FromConversion
- type JSON
- type JSONP
- type JSONResponse
- type JUMP
- type LoginFilter
- type Mapper
- type MemFile
- type MemFileInfo
- type Reflected
- type Response
- type SHOW
- type Server
- func (s *Server) AddAction(cs ...interface{})
- func (s *Server) AddApp(a *App)
- func (s *Server) AddConfig(name string, value interface{})
- func (s *Server) AddFilter(filter Filter)
- func (s *Server) AddRouter(url string, c interface{})
- func (s *Server) App(name string) *App
- func (s *Server) Assign(name string, varOrFun interface{})
- func (s *Server) AutoAction(c ...interface{})
- func (s *Server) Close()
- func (s *Server) GetConfig(name string) interface{}
- func (s *Server) InitSession()
- func (s *Server) IsRunning() bool
- func (s *Server) MultiAssign(t *T)
- func (s *Server) Process(w http.ResponseWriter, req *http.Request)
- func (s *Server) Run(addr string) error
- func (s *Server) RunFcgi(addr string)
- func (s *Server) RunScgi(addr string)
- func (s *Server) RunTLS(addr string, config *tls.Config) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (s *Server) SetConfig(name string, value interface{})
- func (s *Server) SetLogger(logger *log.Logger)
- func (s *Server) SetStaticDir(path string)
- func (s *Server) SetTemplateDir(path string)
- type ServerConfig
- type ServerInformation
- type StaticVerMgr
- func (self *StaticVerMgr) CacheAll(staticPath string) error
- func (self *StaticVerMgr) CacheDelete(url string)
- func (self *StaticVerMgr) CacheItem(url string)
- func (self *StaticVerMgr) Close()
- func (self *StaticVerMgr) DeleteCombined(url string)
- func (self *StaticVerMgr) GetVersion(url string) string
- func (self *StaticVerMgr) Init(app *App, staticPath string) error
- func (self *StaticVerMgr) IsCombined(combineUrl string) (ok bool)
- func (self *StaticVerMgr) Moniter(staticPath string) error
- func (self *StaticVerMgr) RecordCombined(fromUrl string, combineUrl string)
- func (self *StaticVerMgr) RecordCombines(combineUrl string)
- type T
- type TagMapper
- type ToConversion
- type XML
- type XMLResponse
- type XsrfCookieStorage
- type XsrfManager
- type XsrfSessionStorage
Constants ¶
const ( Debug = iota + 1 Product XSRF_TAG string = "_xsrf" )
const ( ForeBlack = iota + 30 //30 40 黑色 ForeRed //31 41 紅色 ForeGreen //32 42 綠色 ForeYellow //33 43 黃色 ForeBlue //34 44 藍色 ForePurple //35 45 紫紅色 ForeCyan //36 46 青藍色 ForeWhite //37 47 白色 )
const ( LevelTrace = iota + 1 LevelDebug LevelInfo LevelWarn LevelError LevelCritical )
const (
Version = "1.0.0"
)
Variables ¶
var ( DefaultFuncs template.FuncMap = template.FuncMap{ "Now": Now, "Eq": Eq, "FormatDate": FormatDate, "Add": Add, "Subtract": Subtract, "IsNil": IsNil, "Url": Url, "UrlFor": UrlFor, "Html": Html, "Js": Js, "Css": Css, "XsrfField": XsrfName, "HtmlAttr": HtmlAttr, "ToHtmlAttrs": ToHtmlAttrs, "BuildUrl": BuildUrl, } )
*
- 默认模板函数
- 除了这里定义的之外,还可以使用当前Action(即在方法中使用Render的Action)中定义的可导出的属性和方法(使用".属性"或".方法"来访问)
- 另外还支持函数:
- include —— Include(tmplName string) interface{}
- session —— GetSession(key string) interface{}
- cookie —— Cookie(key string) string
- XsrfFormHtml —— XsrfFormHtml() template.HTML
- XsrfValue —— XsrfValue() string
- XsrfName —— XsrfName() string
- StaticUrl —— StaticUrl(url string) string
- 支持变量:
- webxVer —— string
var (
DefaultHtmlFilter = func(v string) (r string) {
return v
}
)
var ExtensionValidator = make(map[string]func(*App, http.ResponseWriter, *http.Request) bool)
Functions ¶
func AutoAction ¶
func AutoAction(c ...interface{})
func CloseZWriter ¶
CloseZWriter closes the io.Writer after compressing static file.
func FixDirSeparator ¶
func GetAcceptEncodingZip ¶
GetAcceptEncodingZip returns accept encoding format in http header. zip is first, then deflate if both accepted. If no accepted, return empty string.
func InternalServerError ¶
func MultiAssign ¶
func MultiAssign(t *T)
func NewCookie ¶
NewCookie is a helper method that returns a new http.Cookie object. Duration is specified in seconds. If the duration is zero, the cookie is permanent. This can be used in conjunction with ctx.SetCookie.
func NotSupported ¶
func PKCS5Padding ¶
func PKCS5UnPadding ¶
func Process ¶
func Process(w http.ResponseWriter, req *http.Request)
Process invokes the main server's routing system.
func Run ¶
func Run(addr string)
Run starts the web application and serves HTTP requests for the main server.
func RunFcgi ¶
func RunFcgi(addr string)
RunFcgi starts the web application and serves FastCGI requests for the main server.
func RunScgi ¶
func RunScgi(addr string)
RunScgi starts the web application and serves SCGI requests for the main server.
func SetStaticDir ¶
func SetStaticDir(dir string)
func SetTemplateDir ¶
func SetTemplateDir(dir string)
func SimpleParse ¶
func Slug ¶
Slug is a helper function that returns the URL slug for string s. It's used to return clean, URL-friendly strings that can be used in routing.
func Ternary ¶
func Ternary(express bool, trueVal interface{}, falseVal interface{}) interface{}
the func is the same as condition ? true : false
func ToHtmlAttrs ¶
func Unauthorized ¶
func Url ¶
Usage:Url("/user/login","appName","servName") or Url("/user/login","appName") or Url("/user/login") or UrlFor()
func UrlFor ¶
Usage:UrlFor("main:root:/user/login") or UrlFor("root:/user/login") or UrlFor("/user/login") or UrlFor() 这里的main代表Server名称;root代表App名称;后面的内容为Action中方法函数所对应的网址
func Urlencode ¶
Urlencode is a helper method that converts a map into URL-encoded form data. It is a useful when constructing HTTP POST requests.
func ZeroPadding ¶
func ZeroUnPadding ¶
Types ¶
type AbortError ¶
func (*AbortError) Error ¶
func (a *AbortError) Error() string
type Action ¶
type Action struct { Request *http.Request App *App Option *ActionOption http.ResponseWriter C reflect.Value T T RequestBody []byte StatusCode int ResponseSize int64 JsonpCallback string ExtensionName string Exit bool // contains filtered or unexported fields }
An Action object or it's substruct is created for every incoming HTTP request. It provides information about the request, including the http.Request object, the GET and POST params, and acts as a Writer for the response.
func (*Action) Abort ¶
Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.
func (*Action) Cookie ¶
Cookie returns request cookie item string by a given key. if non-existed, return empty string.
func (*Action) CookieAuthKey ¶
func (*Action) DelSession ¶
func (*Action) DisableHttpCache ¶
func (c *Action) DisableHttpCache()
func (*Action) GetConfigString ¶
func (*Action) GetSession ¶
func (*Action) IP ¶
ClientIP implements a best effort algorithm to return the real client IP, it parses X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy.
func (*Action) IsWebsocket ¶
IsSecure returns boolean of this request is in webSocket.
func (*Action) MapForm ¶
ParseStruct mapping forms' name and values to struct's field For example:
<form> <input name="user.id"/> <input name="user.name"/> <input name="user.age"/> </form> type User struct { Id int64 Name string Age string } var user User err := action.MapForm(&user)
func (*Action) NamedRender ¶
render the template with vars map, you can have zero or one map
func (*Action) SaveToFile ¶
func (*Action) ServeJsonp ¶
func (*Action) Session ¶
func (c *Action) Session() *httpsession.Session
func (*Action) SetBody ¶
Body sets response body content. if EnableGzip, compress content string. it sends out response body directly.
func (*Action) SetConfigString ¶
func (*Action) SetContentType ¶
ContentType sets the Content-Type header for an HTTP response. For example, c.ContentType("json") sets the content-type to "application/json" If the supplied value contains a slash (/) it is set as the Content-Type verbatim. The return value is the content type as it was set, or an empty string if none was found.
func (*Action) SetHeader ¶
SetHeader sets a response header. the current value of that header will be overwritten .
func (*Action) SetSecureCookie ¶
func (*Action) SetSession ¶
func (*Action) SubDomains ¶
SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .
func (*Action) WriteBytes ¶
WriteString writes string data into the response object.
func (*Action) XsrfFormHtml ¶
type ActionInformation ¶
type ActionOption ¶
type App ¶
type App struct { BasePath string Name string Domain string Route *route.Route Server *Server AppConfig *AppConfig Config *CONF Actions map[string]interface{} ReflectedType map[string]reflect.Type Controllers map[reflect.Type]*sync.Pool Urls map[reflect.Type]map[string]*TagMapper FuncMaps template.FuncMap Logger *log.Logger VarMaps T SessionManager *httpsession.Manager //Session manager RootTemplate *template.Template ErrorTemplate *template.Template StaticVerMgr *StaticVerMgr TemplateEx *tplex.TemplateEx ContentEncoding string RequestTime time.Time RouteValidator func(*App, string) (string, error) ActionValidator func(*App, reflect.Type, reflect.Value) bool Cryptor XsrfManager // contains filtered or unexported fields }
func (*App) AutoAction ¶
func (app *App) AutoAction(cs ...interface{})
func (*App) ElapsedTime ¶
func (*App) ElapsedTimeString ¶
func (*App) GetConfigString ¶
func (*App) InitHeadContent ¶
func (a *App) InitHeadContent(w http.ResponseWriter, contentLength int64)
Init content-length header.
func (*App) MultiAssign ¶
func (*App) Nodes ¶
example:
{ "AdminAction":{ "Index":["GET","POST"], "Add": ["GET","POST"], "Edit": ["GET","POST"] } }
func (*App) SafelyCall ¶
safelyCall invokes `function` in recover block
func (*App) SetConfigString ¶
func (*App) SetStaticDir ¶
func (*App) SetTemplateDir ¶
func (*App) TryServingFile ¶
tryServingFile attempts to serve a static file, and returns whether or not the operation is successful.
func (*App) VisitedLog ¶
type AppConfig ¶
type AppConfig struct { Mode int StaticDir string TemplateDir string TemplateTheme string TemplateStyle string SessionOn bool MaxUploadSize int64 CookieSecret string CookieLimitIP bool CookieLimitUA bool CookiePrefix string CookieDomain string StaticFileVersion bool CacheTemplates bool ReloadTemplates bool CheckXsrf bool SessionTimeout time.Duration FormMapToStruct bool EnableHttpCache bool AuthBasedOnCookie bool StaticFileParser map[string]func(string, *http.Request, http.ResponseWriter) (bool, int64) }
func NewAppConfig ¶
func NewAppConfig() *AppConfig
type AutoResponse ¶
type AutoResponse struct { }
type CONF ¶
type CONF struct { Bool map[string]bool Interface map[string]interface{} String map[string]string Int map[string]int64 Float map[string]float64 Byte map[string][]byte Conf map[string]*CONF }
func (*CONF) DelInterface ¶
func (*CONF) GetInterface ¶
func (*CONF) InitInterface ¶
func (a *CONF) InitInterface()
func (*CONF) InitString ¶
func (a *CONF) InitString()
func (*CONF) SetInterface ¶
type Cryptor ¶
type EventsInstance ¶
type EventsInstance struct {
// contains filtered or unexported fields
}
var Events *EventsInstance = NewEvents()
func NewEvents ¶
func NewEvents() *EventsInstance
func (*EventsInstance) Delete ¶
func (e *EventsInstance) Delete(eventName string)
func (*EventsInstance) Execute ¶
func (e *EventsInstance) Execute(eventName string, session interface{}, next func(bool))
*
- 顺序执行事件
func (*EventsInstance) GoExecute ¶
func (e *EventsInstance) GoExecute(eventName string, session interface{}, next func(bool))
并发执行事件 [Examle 1:] Events.GoExecute("AfterHandler", session, func(_ bool) {//此匿名函数在本事件的最后执行
session.Response.Send() session.Response.Close() })
[Examle 2:] Events.Execute("AfterResponse", session, func(_ bool) {})
func (*EventsInstance) Register ¶
func (e *EventsInstance) Register(eventName string, handler func(interface{}, func(bool)))
注册事件 [Examle:]
Events.Register("AfterResponse", func(session interface{}, next func(bool)) { log.Println("Got AfterResponse event!") isSuccess := true next(isSuccess) //这里的next函数无论什么情况下必须执行。 })
采用不同的方式执行事件时,此处的next函数的作用也是不同的: 1、在并发执行事件的时候,next函数的作用是通知程序我已经执行完了(不理会这一步是否执行成功); 2、在顺序执行事件的时候,next函数的作用是通知程序是否继续执行下一步,next(true)是继续执行下一步,next(false)是终止执行下一步
type FromConversion ¶
a struct implements this interface can be convert from request param to a struct
type JSONResponse ¶
type JSONResponse struct { Status int Message interface{} Data interface{} }
type LoginFilter ¶
type LoginFilter struct { App *App SessionName string AnonymousUrls []*regexp.Regexp AskLoginUrls []*regexp.Regexp Redirect string }
func NewLoginFilter ¶
func NewLoginFilter(app *App, name string, redirect string) *LoginFilter
func (*LoginFilter) AddAnonymousUrls ¶
func (s *LoginFilter) AddAnonymousUrls(urls ...string)
func (*LoginFilter) AddAskLoginUrls ¶
func (s *LoginFilter) AddAskLoginUrls(urls ...string)
func (*LoginFilter) Do ¶
func (s *LoginFilter) Do(w http.ResponseWriter, req *http.Request) bool
type MemFile ¶
type MemFile struct {
// contains filtered or unexported fields
}
MemFile contains MemFileInfo and bytes offset when reading. it implements io.Reader,io.ReadCloser and io.Seeker.
func OpenMemZipFile ¶
OpenMemZipFile returns MemFile object with a compressed static file. it's used for serve static file if gzip enable.
func (*MemFile) Readdir ¶
read os.FileInfo of files in directory of memfile. it returns empty slice.
type MemFileInfo ¶
MemFileInfo contains a compressed file bytes and file information. it implements os.FileInfo interface.
func (*MemFileInfo) IsDir ¶
func (fi *MemFileInfo) IsDir() bool
IsDir returns the compressing file is a directory or not.
func (*MemFileInfo) ModTime ¶
func (fi *MemFileInfo) ModTime() time.Time
ModTime returns the last modified time of raw file.
func (*MemFileInfo) Name ¶
func (fi *MemFileInfo) Name() string
Name returns the compressed filename.
func (*MemFileInfo) Size ¶
func (fi *MemFileInfo) Size() int64
Size returns the raw file content size, not compressed size.
func (*MemFileInfo) Sys ¶
func (fi *MemFileInfo) Sys() interface{}
return nil. implement the os.FileInfo interface method.
type Server ¶
type Server struct { Config *ServerConfig Apps map[string]*App //r["root"] App2Domain map[string]string //r["root"]="www.coscms.com" Domain2App map[string]string //r["www.coscms.com"]="root" AppsNamePath map[string]string //r["root"]="/" Name string SessionManager *httpsession.Manager RootApp *App Logger *log.Logger Env map[string]interface{} Mux *http.ServeMux // contains filtered or unexported fields }
Server represents a webx server.
func MainServer ¶
func MainServer() *Server
func NewServer ¶
func NewServer(name string, args ...*ServerConfig) *Server
func (*Server) AutoAction ¶
func (s *Server) AutoAction(c ...interface{})
func (*Server) InitSession ¶
func (s *Server) InitSession()
func (*Server) MultiAssign ¶
func (*Server) Process ¶
func (s *Server) Process(w http.ResponseWriter, req *http.Request)
Process invokes the routing system for server s non-root app's route will override root app's if there is same path
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP is the interface method for Go's http server package
func (*Server) SetStaticDir ¶
func (*Server) SetTemplateDir ¶
type ServerConfig ¶
type ServerConfig struct { Addr string Port int RecoverPanic bool Profiler bool EnableGzip bool StaticExtensionsToGzip []string Url string UrlPrefix string UrlSuffix string StaticHtmlDir string SessionTimeout time.Duration MaxConnections int UseSSL bool TlsConfig *tls.Config Debug bool GracefulShutdown bool }
ServerConfig is configuration for server objects.
type ServerInformation ¶
type ServerInformation struct { *Server http.ResponseWriter *http.Request }
type StaticVerMgr ¶
type StaticVerMgr struct { Caches map[string]string Combined map[string][]string Combines map[string]bool Path string Ignores map[string]bool TimerCallback func() bool // contains filtered or unexported fields }
var DefaultStaticVerMgr *StaticVerMgr = new(StaticVerMgr)
func (*StaticVerMgr) CacheAll ¶
func (self *StaticVerMgr) CacheAll(staticPath string) error
func (*StaticVerMgr) CacheDelete ¶
func (self *StaticVerMgr) CacheDelete(url string)
func (*StaticVerMgr) CacheItem ¶
func (self *StaticVerMgr) CacheItem(url string)
func (*StaticVerMgr) Close ¶
func (self *StaticVerMgr) Close()
func (*StaticVerMgr) DeleteCombined ¶
func (self *StaticVerMgr) DeleteCombined(url string)
func (*StaticVerMgr) GetVersion ¶
func (self *StaticVerMgr) GetVersion(url string) string
func (*StaticVerMgr) IsCombined ¶
func (self *StaticVerMgr) IsCombined(combineUrl string) (ok bool)
func (*StaticVerMgr) Moniter ¶
func (self *StaticVerMgr) Moniter(staticPath string) error
func (*StaticVerMgr) RecordCombined ¶
func (self *StaticVerMgr) RecordCombined(fromUrl string, combineUrl string)
func (*StaticVerMgr) RecordCombines ¶
func (self *StaticVerMgr) RecordCombines(combineUrl string)
type TagMapper ¶
func NewTagMapper ¶
type ToConversion ¶
type ToConversion interface {
ToString() string
}
a struct implements this interface can be convert from struct to template variable Not Implemented
type XMLResponse ¶
type XMLResponse struct { Status int Message interface{} Data interface{} }
type XsrfCookieStorage ¶
type XsrfCookieStorage struct {
*Action
}
func (*XsrfCookieStorage) Get ¶
func (c *XsrfCookieStorage) Get(key string) string
func (*XsrfCookieStorage) Init ¶
func (c *XsrfCookieStorage) Init(a *Action)
func (*XsrfCookieStorage) Set ¶
func (c *XsrfCookieStorage) Set(key, val string)
func (*XsrfCookieStorage) Valid ¶
func (c *XsrfCookieStorage) Valid(key, val string) bool
type XsrfManager ¶
type XsrfManager interface { Init(*Action) Get(key string) string Set(key, val string) Valid(key, val string) bool }
var DefaultXsrfManager XsrfManager = &XsrfCookieStorage{}
type XsrfSessionStorage ¶
type XsrfSessionStorage struct {
*Action
}
func (*XsrfSessionStorage) Get ¶
func (c *XsrfSessionStorage) Get(key string) string
func (*XsrfSessionStorage) Init ¶
func (c *XsrfSessionStorage) Init(a *Action)
func (*XsrfSessionStorage) Set ¶
func (c *XsrfSessionStorage) Set(key, val string)
func (*XsrfSessionStorage) Valid ¶
func (c *XsrfSessionStorage) Valid(key, val string) bool
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
lib
|
|
httpsession
Package httpsession is a http server session implement for Go.
|
Package httpsession is a http server session implement for Go. |
tplex
* * 模板扩展 * @author swh <swh@admpub.com>
|
* * 模板扩展 * @author swh <swh@admpub.com> |
uuid
The uuid package generates and inspects UUIDs.
|
The uuid package generates and inspects UUIDs. |