Skip to content

Commit 13fb232

Browse files
committed
perf: fix conflict
1 parent 97404e8 commit 13fb232

12 files changed

Lines changed: 3638 additions & 438 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ proto_go_dir=./protobuf-go
7777
protobuf_py_dir=./protobuf-py/protobuf
7878

7979
.PHONY: proto
80-
proto: proto-go proto-java proto-rust
80+
proto: proto-go proto-java proto-rust proto-py
8181

8282
.PHONY: proto-go
8383
proto-go:

cmd/impl/jms_chat.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package impl
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67

@@ -47,3 +48,35 @@ func (j *JMServer) GetAccountChat(ctx context.Context, req *pb.Empty) (*pb.Accou
4748
status.Ok = true
4849
return &pb.AccountDetailResponse{Status: &status, Payload: st}, nil
4950
}
51+
52+
func (j *JMServer) CallAPI(ctx context.Context, req *pb.HTTPRequest) (*pb.HTTPResponse, error) {
53+
method := req.GetMethod()
54+
reqUrl := req.GetPath()
55+
query := req.GetQuery()
56+
body := req.GetBody()
57+
header := req.GetHeader()
58+
apiClient := j.apiClient.Copy()
59+
var (
60+
status pb.Status
61+
)
62+
for k, v := range header {
63+
apiClient.SetHeader(k, v)
64+
}
65+
var bodyObj any
66+
if len(body) > 0 {
67+
if err := json.NewDecoder(bytes.NewBuffer(body)).Decode(&bodyObj); err != nil {
68+
logger.Errorf("Decode body failed: %v", err)
69+
status.Err = err.Error()
70+
return &pb.HTTPResponse{Status: &status}, err
71+
}
72+
}
73+
var resJson bytes.Buffer
74+
_, err := apiClient.Call(method, reqUrl, bodyObj, &resJson, query)
75+
if err != nil {
76+
logger.Errorf("Call: %v", err)
77+
status.Err = err.Error()
78+
return &pb.HTTPResponse{Status: &status}, err
79+
}
80+
status.Ok = true
81+
return &pb.HTTPResponse{Status: &status, Body: resJson.Bytes()}, nil
82+
}

0 commit comments

Comments
 (0)