golang打印echo.Context的值

huangapple go评论80阅读模式
英文:

golang print echo.Context values

问题

我是你的中文翻译助手,以下是翻译好的内容:

我对Go语言还很陌生,正在尝试检查一个方法的参数。我有以下的代码:

func (c *controller) OrderNew(ctx echo.Context) error {

当我尝试使用以下代码:

fmt.println(ctx)
fmt.Printf("%v \n", ctx)

我得到的输出是:

&{0xc4200f21e0 0xc4202302d0 /order [] [] map[] 0x4092860 map[site_key:2] 0xc4200bb6c0}

我意识到*controller是一个指针,返回的值包含地址,但不确定如何进行进一步的调试或检查。我还看到了在ctx上调用的函数,比如:

ctx.Get
ctx.Render

我知道这些是echo.Context中的函数。

如果有任何帮助或澄清,将不胜感激。谢谢!

英文:

I'm brand new to Go and trying to inspect a method argument. I've got the following code

func (c *controller) OrderNew(ctx echo.Context) error {

When I try either:

	fmt.println(ctx)
    fmt.Printf("%v \n", ctx)

I get

&{0xc4200f21e0 0xc4202302d0 /order [] [] map[] 0x4092860 map[site_key:2] 0xc4200bb6c0}

I realize *controller is a pointer and the values returned contain addresses, but not sure how to really debug or inspect further. I also see functions called on cxt like

ctx.Get and ctx.Render

which I realize are functions in echo.Context

Any help/clarification is appreciated. Thanks!

答案1

得分: 2

使用log包。

log.Printf("CONTEXT %+v", ctx)
英文:

use log package.

log.Printf("CONTEXT %+v", ctx)

答案2

得分: 0

  • https://echo.labstack.com/guide/context 是一个查看 echo 的优秀资源。

  • 在离线状态下,有 godoc 功能,可以帮助理解任何已下载到您的计算机上的包。在您的情况下,您可以在命令行上执行 godoc github.com/labstack/echo Context

  • 许多编辑器都有 GOTO 功能,可以在编码时查看库源代码,例如 https://github.com/fatih/vim-go、https://github.com/DisposaBoy/GoSublime。它们允许您导航到定义这些函数和结构的位置。希望有人在那里编写了简明的文档注释。

  • 如果您只想观察代码的执行,可以使用调试工具,例如 delve https://github.com/derekparker/delve

英文:
  • https://echo.labstack.com/guide/context is an excellent source for looking into echo.

  • offline there is godoc functionality, which helps with understanding any package(which is downloaded in your machine). In your case this can be done, godoc github.com/labstack/echo Context on your command line.

  • There are GOTO functionalities many editors that lets you see the library source, while you are coding, https://github.com/fatih/vim-go, https://github.com/DisposaBoy/GoSublime are such examples. What they allow you to do is to navigate these functions and structs to the point where they are defined. Hopefully, someone will have written, a crisp documentary comment there.

  • if all you want is to watch the execution of your code, you can use debugging tools, like delve https://github.com/derekparker/delve.

huangapple
  • 本文由 发表于 2017年2月11日 00:30:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/42164203.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定