本文整理汇总了Golang中github.com/go-playground/lars.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Users
// Users ...
func Users(c lars.Context) {
ctx := c.(*MyContext)
ctx.AppContext.Log.Println("In Users Function")
c.Response().Write([]byte("Users"))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:9,代码来源:main.go
示例2: Home
// Home ...
func Home(c lars.Context) {
ctx := c.(*MyContext)
var username string
// username = ctx.AppContext.DB.find(user by .....)
ctx.AppContext.Log.Println("Found User")
c.Response().Write([]byte("Welcome Home " + username))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:13,代码来源:main.go
示例3: UserProfile
// UserProfile ...
func UserProfile(c lars.Context) {
ctx := c.(*MyContext)
id := c.Param("id")
var profile string
// profile = ctx.AppContext.DB.find(user profile by .....)
ctx.AppContext.Log.Println("Found User Profile")
c.Response().Write([]byte("Here's your profile " + profile + " user " + id))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:15,代码来源:main.go
示例4: User
// User ...
func User(c lars.Context) {
ctx := c.(*MyContext)
id := c.Param("id")
var username string
// username = ctx.AppContext.DB.find(user by id.....)
ctx.AppContext.Log.Println("Found User")
c.Response().Write([]byte("Welcome " + username + " with id " + id))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:15,代码来源:main.go
示例5: Logger
// Logger ...
func Logger(c lars.Context) {
start := time.Now()
c.Next()
stop := time.Now()
path := c.Request().URL.Path
if path == "" {
path = "/"
}
log.Printf("%s %d %s %s", c.Request().Method, c.Response().Status(), path, stop.Sub(start))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:16,代码来源:main.go
示例6: LoggingAndRecovery
// LoggingAndRecovery handle HTTP request logging + recovery
func LoggingAndRecovery(c lars.Context) {
t1 := time.Now()
defer func() {
if err := recover(); err != nil {
trace := make([]byte, 1<<16)
n := runtime.Stack(trace, true)
log.Printf(" %srecovering from panic: %+v\nStack Trace:\n %s%s", Red, err, trace[:n], Reset)
HandlePanic(c, trace[:n])
return
}
}()
c.Next()
var color string
res := c.Response()
req := c.Request()
code := res.Status()
switch {
case code >= http.StatusInternalServerError:
color = Underscore + Blink + Red
case code >= http.StatusBadRequest:
color = Red
case code >= http.StatusMultipleChoices:
color = Yellow
default:
color = Green
}
t2 := time.Now()
log.Printf("%s %d %s[%s%s%s] %q %v %d\n", color, code, Reset, color, req.Method, Reset, req.URL, t2.Sub(t1), res.Size())
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:38,代码来源:logging_recovery.go
示例7: Gzip
// Gzip returns a middleware which compresses HTTP response using gzip compression
// scheme.
func Gzip(c lars.Context) {
c.Response().Header().Add(lars.Vary, lars.AcceptEncoding)
if strings.Contains(c.Request().Header.Get(lars.AcceptEncoding), lars.Gzip) {
w := writerPool.Get().(*gzip.Writer)
w.Reset(c.Response().Writer())
defer func() {
w.Close()
writerPool.Put(w)
}()
gw := gzipWriter{Writer: w, ResponseWriter: c.Response().Writer()}
c.Response().Header().Set(lars.ContentEncoding, lars.Gzip)
c.Response().SetWriter(gw)
}
c.Next()
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:23,代码来源:gzip.go
示例8: larsHandler
// lars
func larsHandler(c lars.Context) {
if sleepTime > 0 {
time.Sleep(sleepTimeDuration)
}
c.Response().Write(message)
}
开发者ID:cokeboL,项目名称:go-web-framework-benchmark,代码行数:7,代码来源:server.go
示例9: Redirect
// Redirect ...
func Redirect(c lars.Context) {
c.Response().Write([]byte("Redirect"))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:4,代码来源:test.go
示例10: AdminProfile
// AdminProfile ...
func AdminProfile(c lars.Context) {
c.Response().Write([]byte("Admin Profile"))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:4,代码来源:main.go
示例11: HelloWorld
// HelloWorld ...
func HelloWorld(c lars.Context) {
c.Response().Write([]byte("Hello World"))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:4,代码来源:test.go
示例12: Admin
// Admin ...
func Admin(c lars.Context) {
c.Response().Write([]byte("Admin"))
}
开发者ID:muyiwaolurin,项目名称:tri,代码行数:4,代码来源:main.go
示例13: route2a
func route2a(ctx *lars.Context) {
ctx.Response.Write([]byte("Route 2a " + ctx.Param("name")))
}
开发者ID:joeybloggs,项目名称:proof-of-concept,代码行数:3,代码来源:main.go
注:本文中的github.com/go-playground/lars.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论