Comments (2)
同一个只能出现在同一个地方,我们不允许同一个参数放在不同的位置,如果form和body里都提供了,取哪个呢?
from go-zero.
同一个只能出现在同一个地方,我们不允许同一个参数放在不同的位置,如果form和body里都提供了,取哪个呢?
两者都存在的情况,一般发生在web服务请求中,
通过判断http报头 Content-Type application/x-www-from-urlencoded 或者 application/json
参考 gin 方式
https://gin-gonic.com/zh-cn/docs/examples/bind-body-into-dirrerent-structs/
将 request body 绑定到不同的结构体中
type formA struct {
Foo string `json:"foo" xml:"foo" binding:"required"`
}
type formB struct {
Bar string `json:"bar" xml:"bar" binding:"required"`
}
func SomeHandler(c *gin.Context) {
objA := formA{}
objB := formB{}
// c.ShouldBind 使用了 c.Request.Body,不可重用。
if errA := c.ShouldBind(&objA); errA == nil {
c.String(http.StatusOK, `the body should be formA`)
// 因为现在 c.Request.Body 是 EOF,所以这里会报错。
} else if errB := c.ShouldBind(&objB); errB == nil {
c.String(http.StatusOK, `the body should be formB`)
} else {
...
}
}
from go-zero.
Related Issues (20)
- Fix code scanning alert - Arbitrary file access during archive extraction ("Zip Slip") HOT 1
- goctl generated duplicate api types. HOT 1
- [ Discuss ] If necessary do strict fields type mapping when generate model from database table fields HOT 2
- goctl is not the latest version in kevinwan/goctl image HOT 2
- The Dockerfile generated by goctl by default uses scratch and does not have the sh executable command. HOT 2
- Gateway NewRequestParser json.NewDecoder map result in loss of numerical precision
- The tokenlimit with redis may work incorrectly due to network latency HOT 4
- gateway how to config cors function
- grpc error management like kratos error generator HOT 3
- Add a flag to whether to generate pb file HOT 1
- API Import generate questions HOT 6
- Need a customized.tpl file which includes all the template Execute variables. HOT 1
- I want to print log to file. But I already want to see it in console. HOT 6
- Any plan to support rocketmq? HOT 2
- Use gateway server.AddRoute(), The limit(MaxConns) of this route does not take effect HOT 3
- how to exec my own middleware before build-in jwt? HOT 1
- A RPC service generated by multiple proto files? HOT 3
- How to make gracefulStop waiting? HOT 4
- 'circuit breaker is open','last resolver error: produced zero addresses' HOT 3
- Suggest to add option to disable parameter validation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-zero.