3

How to retrieve headers data value from client API using Go language?

I'm using beego framework (beego.me)

and here is sample result to retrieve data from body

func (u *UserController) Post() {
    var user models.User
    json.Unmarshal(u.Ctx.Input.RequestBody, &user)
    uid := models.AddUser(user)
    u.Data["json"] = map[string]string{"uid": uid}
    u.ServeJSON()
}
1
  • please provide more specifics of what you are trying to do - code example etc Commented Dec 2, 2016 at 10:36

1 Answer 1

5

According to the docs, you can do this:

log.Println(u.Ctx.Input.Header("X-My-Header"))

All headers at once can be obtained from an *http.Request:

log.Println(u.Ctx.Request.Header)
Sign up to request clarification or add additional context in comments.

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.