4

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!

3
  • 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. Commented Feb 10, 2017 at 16:40
  • 1
    Here is a link to echo's 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. Commented Feb 10, 2017 at 20:53
  • 1
    Or a link to the nicer formatted godoc: echo.Context Commented Feb 10, 2017 at 21:33

2 Answers 2

2

use log package.

log.Printf("CONTEXT %+v", ctx)
Sign up to request clarification or add additional context in comments.

1 Comment

Add a playground link to explain it by example.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.