• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang lars.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang locales.F函数代码示例发布时间:2022-05-23
下一篇:
Golang validate.Required函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap