英文:
How to make a post request using the gogearbox framework
问题
我目前遇到了困难,因为我不知道如何完成我正在做的项目的Post请求。我正在使用一个叫做gearbox的框架(我想尝试一些新东西)。主要的问题是我不知道如何将json绑定到新变量上。所以有人可以帮我解决这个问题吗?关于信息,我可以发布GitHub包。它是***"github.com/gogearbox/gearbox"***,请帮帮我。
我确实尝试查阅了文档,并尝试了一些不同的函数,但都没有成功,所以如果有人可以帮助我,请告诉我。
英文:
I am currently stuck because I do not know how to complete my Post request for a project I am doing. I am using a framework called gearbox (I wanted to try something new). The main problem is I don't know how to bind the json to the new variable. So can anyone help me with this issue. For the info I can post the GitHub package. It's "github.com/gogearbox/gearbox" , Please help me.
I did try to look up the documentation,and I did try a few different functions but it didn't work so if anyone can help me please.
答案1
得分: 0
你应该提供一些代码,即使它不起作用。这通常是一个很好的起点。这样我们就可以避免尝试你已经测试过的东西。我简要地阅读了文档,并没有测试下面的代码,但你可以尝试查看ParseBody
函数:
type Payload struct{
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
}
requestHandler := func(ctx *fasthttp.RequestCtx) {
var payload *Payload
err := ctx.ParseBody(&payload)
if err!= nil {
ctx.Status(gearbox.StatusInternalServerError).SendString("解析有效载荷时出错!")
}
// 处理有效载荷
}
英文:
You should provide some code even if it doesn't work. It's usually a good starting point. This way we can avoid trying things you already tested out. I've briefly read the doc and didn't test the code below but you may try to look at the ParseBody
function:
type Payload struct{
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
}
requestHandler := func(ctx *fasthttp.RequestCtx) {
var payload *Payload
err := ctx.ParseBody(&payload)
if err!= nil {
ctx.Status(gearbox.StatusInternalServerError).SendString("Something went wrong when parsing your payload!")
}
// do something with your payload
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论