222twotwotwo commented on code in PR #153:
URL:
https://github.com/apache/dubbo-go-pixiu-samples/pull/153#discussion_r3252668559
##########
dubbohttpproxy/server/http/server.go:
##########
@@ -36,41 +35,37 @@ func main() {
}
func user(w http.ResponseWriter, r *http.Request) {
- switch r.Method {
- case constant.Post:
- byts, err := io.ReadAll(r.Body)
- if err != nil {
- w.Write([]byte(err.Error()))
- }
- var name string
- var user User
- err = json.Unmarshal(byts, &name)
- if err != nil {
- w.Write([]byte(err.Error()))
- }
- _, ok := cache.Get(name)
- if ok {
- w.Header().Set(constant.HeaderKeyContextType,
constant.HeaderValueJsonUtf8)
- w.Write([]byte("{\"message\":\"data is exist\"}"))
- return
- }
- user.ID = randSeq(5)
- if cache.Add(&user) {
- b, _ := json.Marshal(&user)
- w.Header().Set(constant.HeaderKeyContextType,
constant.HeaderValueJsonUtf8)
- w.Write(b)
- return
- }
- w.Write(nil)
+ if r.Method != constant.Post {
+ w.WriteHeader(http.StatusMethodNotAllowed)
+ return
}
-}
-
-var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
-
-func randSeq(n int) string {
- b := make([]rune, n)
- for i := range b {
- b[i] = letters[rand.Intn(len(letters))]
+ byts, err := io.ReadAll(r.Body)
+ if err != nil {
+ w.WriteHeader(http.StatusBadRequest)
+ w.Write([]byte(err.Error()))
+ return
+ }
+ // Pixiu 的 dgp.filter.dubbo.http 把 generic invocation 的实参数组整体
+ // json.Marshal 后发出,body 形如 ["0001"],所以反序列化目标是 []string。
Review Comment:
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]