本文整理汇总了Golang中github.com/astaxie/beego/context.NewOutput函数的典型用法代码示例。如果您正苦于以下问题:Golang NewOutput函数的具体用法?Golang NewOutput怎么用?Golang NewOutput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewOutput函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ServeHTTP
func (n *Namespace) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
//trim the preifix from URL.Path
r.URL.Path = strings.TrimPrefix(r.URL.Path, n.prefix)
// init context
context := &beecontext.Context{
ResponseWriter: rw,
Request: r,
Input: beecontext.NewInput(r),
Output: beecontext.NewOutput(),
}
context.Output.Context = context
context.Output.EnableGzip = EnableGzip
if context.Input.IsWebsocket() {
context.ResponseWriter = rw
}
if n.condition != nil && !n.condition(context) {
http.Error(rw, "Method Not Allowed", 405)
}
n.handlers.ServeHTTP(rw, r)
}
开发者ID:happyluo,项目名称:beego,代码行数:21,代码来源:namespace.go
示例2: ServeHTTP
// Implement http.Handler interface.
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
if err == USERSTOPRUN {
return
}
if _, ok := err.(middleware.HTTPException); ok {
// catch intented errors, only for HTTP 4XX and 5XX
} else {
if RunMode == "dev" {
if !RecoverPanic {
panic(err)
} else {
if ErrorsShow {
if handler, ok := middleware.ErrorMaps[fmt.Sprint(err)]; ok {
handler(rw, r)
return
}
}
var stack string
Critical("the request url is ", r.URL.Path)
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
stack = stack + fmt.Sprintln(file, line)
}
middleware.ShowErr(err, rw, r, stack)
}
} else {
if !RecoverPanic {
panic(err)
} else {
// in production model show all infomation
if ErrorsShow {
handler := p.getErrorHandler(fmt.Sprint(err))
handler(rw, r)
return
} else {
Critical("the request url is ", r.URL.Path)
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
}
}
}
}
}
}
}()
starttime := time.Now()
requestPath := r.URL.Path
var runrouter reflect.Type
var findrouter bool
var runMethod string
params := make(map[string]string)
w := &responseWriter{writer: rw}
w.Header().Set("Server", BeegoServerName)
// init context
context := &beecontext.Context{
ResponseWriter: w,
Request: r,
Input: beecontext.NewInput(r),
Output: beecontext.NewOutput(),
}
context.Output.Context = context
context.Output.EnableGzip = EnableGzip
if context.Input.IsWebsocket() {
context.ResponseWriter = rw
}
// defined filter function
do_filter := func(pos int) (started bool) {
if p.enableFilter {
if l, ok := p.filters[pos]; ok {
for _, filterR := range l {
if ok, p := filterR.ValidRouter(r.URL.Path); ok {
context.Input.Params = p
filterR.filterFunc(context)
if w.started {
return true
}
}
}
}
}
//.........这里部分代码省略.........
开发者ID:jrodriguezjr,项目名称:beego,代码行数:101,代码来源:router.go
示例3: ServeHTTP
// Implement http.Handler interface.
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
defer p.recoverPanic(rw, r)
starttime := time.Now()
var runrouter reflect.Type
var findrouter bool
var runMethod string
var routerInfo *controllerInfo
w := &responseWriter{writer: rw}
if RunMode == "dev" {
w.Header().Set("Server", BeegoServerName)
}
// init context
context := &beecontext.Context{
ResponseWriter: w,
Request: r,
Input: beecontext.NewInput(r),
Output: beecontext.NewOutput(),
}
context.Output.Context = context
context.Output.EnableGzip = EnableGzip
var urlPath string
if !RouterCaseSensitive {
urlPath = strings.ToLower(r.URL.Path)
} else {
urlPath = r.URL.Path
}
// defined filter function
do_filter := func(pos int) (started bool) {
if p.enableFilter {
if l, ok := p.filters[pos]; ok {
for _, filterR := range l {
if ok, p := filterR.ValidRouter(urlPath); ok {
context.Input.Params = p
filterR.filterFunc(context)
if filterR.returnOnOutput && w.started {
return true
}
}
}
}
}
return false
}
// filter wrong httpmethod
if _, ok := HTTPMETHOD[r.Method]; !ok {
http.Error(w, "Method Not Allowed", 405)
goto Admin
}
// filter for static file
if do_filter(BeforeStatic) {
goto Admin
}
serverStaticRouter(context)
if w.started {
findrouter = true
goto Admin
}
// session init
if SessionOn {
var err error
context.Input.CruSession, err = GlobalSessions.SessionStart(w, r)
if err != nil {
Error(err)
middleware.Exception("503", rw, r, "")
return
}
defer func() {
context.Input.CruSession.SessionRelease(w)
}()
}
if r.Method != "GET" && r.Method != "HEAD" {
if CopyRequestBody && !context.Input.IsUpload() {
context.Input.CopyBody()
}
context.Input.ParseFormOrMulitForm(MaxMemory)
}
if do_filter(BeforeRouter) {
goto Admin
}
if context.Input.RunController != nil && context.Input.RunMethod != "" {
findrouter = true
runMethod = context.Input.RunMethod
runrouter = context.Input.RunController
}
if !findrouter {
http_method := r.Method
//.........这里部分代码省略.........
开发者ID:gogogo2015,项目名称:archci,代码行数:101,代码来源:router.go
示例4: ServeHTTP
// AutoRoute
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
errstr := fmt.Sprint(err)
if handler, ok := middleware.ErrorMaps[errstr]; ok && ErrorsShow {
handler(rw, r)
} else {
if !RecoverPanic {
// go back to panic
panic(err)
} else {
var stack string
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
if RunMode == "dev" {
stack = stack + fmt.Sprintln(file, line)
}
}
if RunMode == "dev" {
middleware.ShowErr(err, rw, r, stack)
}
}
}
}
}()
w := &responseWriter{writer: rw}
w.Header().Set("Server", BeegoServerName)
context := &beecontext.Context{
ResponseWriter: w,
Request: r,
Input: beecontext.NewInput(r),
Output: beecontext.NewOutput(w),
}
context.Output.Context = context
context.Output.EnableGzip = EnableGzip
if context.Input.IsWebsocket() {
context.ResponseWriter = rw
context.Output = beecontext.NewOutput(rw)
}
if SessionOn {
context.Input.CruSession = GlobalSessions.SessionStart(w, r)
}
var runrouter *controllerInfo
var findrouter bool
params := make(map[string]string)
if p.enableFilter {
if l, ok := p.filters["BeforRouter"]; ok {
for _, filterR := range l {
if filterR.ValidRouter(r.URL.Path) {
filterR.filterFunc(context)
if w.started {
return
}
}
}
}
}
//static file server
for prefix, staticDir := range StaticDir {
if r.URL.Path == "/favicon.ico" {
file := staticDir + r.URL.Path
http.ServeFile(w, r, file)
w.started = true
return
}
if strings.HasPrefix(r.URL.Path, prefix) {
file := staticDir + r.URL.Path[len(prefix):]
finfo, err := os.Stat(file)
if err != nil {
return
}
//if the request is dir and DirectoryIndex is false then
if finfo.IsDir() && !DirectoryIndex {
middleware.Exception("403", rw, r, "403 Forbidden")
return
}
http.ServeFile(w, r, file)
w.started = true
return
}
}
if p.enableFilter {
if l, ok := p.filters["AfterStatic"]; ok {
for _, filterR := range l {
if filterR.ValidRouter(r.URL.Path) {
filterR.filterFunc(context)
//.........这里部分代码省略.........
开发者ID:rose312,项目名称:beego,代码行数:101,代码来源:router.go
示例5: ServeHTTP
// AutoRoute
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
if _, ok := err.(middleware.HTTPException); ok {
// catch intented errors, only for HTTP 4XX and 5XX
} else {
if RunMode == "dev" {
if !RecoverPanic {
panic(err)
} else {
var stack string
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
stack = stack + fmt.Sprintln(file, line)
}
middleware.ShowErr(err, rw, r, stack)
}
} else {
if ErrorsShow {
handler := p.getErrorHandler(fmt.Sprint(err))
handler(rw, r)
} else {
if !RecoverPanic {
panic(err)
} else {
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
}
}
}
}
}
}
}()
starttime := time.Now()
requestPath := r.URL.Path
var runrouter *controllerInfo
var findrouter bool
params := make(map[string]string)
w := &responseWriter{writer: rw}
w.Header().Set("Server", BeegoServerName)
context := &beecontext.Context{
ResponseWriter: w,
Request: r,
Input: beecontext.NewInput(r),
Output: beecontext.NewOutput(w),
}
context.Output.Context = context
context.Output.EnableGzip = EnableGzip
do_filter := func(pos int) (started bool) {
if p.enableFilter {
if l, ok := p.filters[pos]; ok {
for _, filterR := range l {
if ok, p := filterR.ValidRouter(r.URL.Path); ok {
context.Input.Params = p
filterR.filterFunc(context)
if w.started {
return true
}
}
}
}
}
return false
}
if context.Input.IsWebsocket() {
context.ResponseWriter = rw
context.Output = beecontext.NewOutput(rw)
}
if !utils.InSlice(strings.ToLower(r.Method), HTTPMETHOD) {
http.Error(w, "Method Not Allowed", 405)
goto Admin
}
if do_filter(BeforeRouter) {
goto Admin
}
//static file server
for prefix, staticDir := range StaticDir {
if r.URL.Path == "/favicon.ico" {
file := staticDir + r.URL.Path
//.........这里部分代码省略.........
开发者ID:peilongwu,项目名称:beego,代码行数:101,代码来源:router.go
注:本文中的github.com/astaxie/beego/context.NewOutput函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论