成功能处理grpc的版本

This commit is contained in:
eson 2023-11-03 11:06:15 +08:00
parent 5785fea6b8
commit c3cc17f86f
3 changed files with 13 additions and 14 deletions

2
proto

@ -1 +1 @@
Subproject commit 30ec7b35364db92428093fe9776b8aeaad534340
Subproject commit 7eb12644f085aa533887a2474ec7d1796fa77ecf

2
protoc.sh Normal file
View File

@ -0,0 +1,2 @@
#! /bin/bash
go run -gcflags="-N" proto/goutils/proto_build/main.go

View File

@ -1,8 +1,8 @@
package logic
import (
"bytes"
"context"
"encoding/json"
"fusen-gateway/proto/goutils/basic"
"net/http"
@ -30,27 +30,24 @@ var fsProtoJSON = &runtime.JSONPb{
func ResponseHeaderMatcher(ctx context.Context, w http.ResponseWriter, resp proto.Message) error {
headers := w.Header()
key := http.CanonicalHeaderKey("Grpc-Metadata-" + string(basic.M_FusenResponse))
w.WriteHeader(200)
key := http.CanonicalHeaderKey("Grpc-Metadata-" + string(basic.GM_FusenResponse))
if location, ok := headers[key]; ok {
// w.Header().Set("Location", location[0])
// w.WriteHeader(http.StatusFound)
jbuf := []byte(location[0])
gresp := &basic.GatewayResponse{}
err := json.Unmarshal(jbuf, gresp)
if err != nil {
return err
}
gresp.Data = resp
w.WriteHeader(200)
fsHeader := location[0]
var buf = bytes.NewBufferString(fsHeader[:len(fsHeader)-1] + ",")
rdata, err := fsProtoJSON.Marshal(resp)
if err != nil {
return err
}
buf.WriteString(`"data":`)
buf.Write(rdata)
buf.WriteString(`}`)
w.Write(rdata)
w.Write(buf.Bytes())
}
// w.WriteHeader(200)
// w.Write([]byte("error"))
return nil
}