3

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!

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
jj1111
  • 607
  • 2
  • 10
  • 20
  • 2
    What is it exactly you expect to see? `echo.Context` has a lot of methods you can call to get whatever information you want. – JimB Feb 10 '17 at 16:40
  • 1
    Here is a link to echo's [context.go](https://github.com/labstack/echo/blob/master/context.go) for your convenience. Also, if I had to guess, the most interesting methods might be Request() and Response() which retrieve the HTTP Request and Response objects respecively. – daplho Feb 10 '17 at 20:53
  • 1
    Or a link to the nicer formatted godoc: [`echo.Context`](https://godoc.org/github.com/labstack/echo#Context) – JimB Feb 10 '17 at 21:33

2 Answers2

2

use log package.

log.Printf("CONTEXT %+v", ctx)
Shubham Chadokar
  • 2,520
  • 1
  • 24
  • 45
Victra
  • 21
  • 3
0
  • 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.

whitespace
  • 789
  • 6
  • 13