Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve headers HTTP data from client Go Language

Tags:

go

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()
}
like image 454
Muhamad Yulianto Avatar asked Jan 25 '26 05:01

Muhamad Yulianto


1 Answers

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)
like image 52
Ainar-G Avatar answered Jan 27 '26 01:01

Ainar-G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!