Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ proto_go_dir=./protobuf-go
protobuf_py_dir=./protobuf-py/protobuf

.PHONY: proto
proto: proto-go proto-java proto-rust
proto: proto-go proto-java proto-rust proto-py

.PHONY: proto-go
proto-go:
Expand Down
33 changes: 33 additions & 0 deletions cmd/impl/jms_chat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package impl

import (
"bytes"
"context"
"encoding/json"

Expand Down Expand Up @@ -47,3 +48,35 @@ func (j *JMServer) GetAccountChat(ctx context.Context, req *pb.Empty) (*pb.Accou
status.Ok = true
return &pb.AccountDetailResponse{Status: &status, Payload: st}, nil
}

func (j *JMServer) CallAPI(ctx context.Context, req *pb.HTTPRequest) (*pb.HTTPResponse, error) {
method := req.GetMethod()
reqUrl := req.GetPath()
query := req.GetQuery()
body := req.GetBody()
header := req.GetHeader()
apiClient := j.apiClient.Copy()
var (
status pb.Status
)
for k, v := range header {
apiClient.SetHeader(k, v)
}
var bodyObj any
if len(body) > 0 {
if err := json.NewDecoder(bytes.NewBuffer(body)).Decode(&bodyObj); err != nil {
logger.Errorf("Decode body failed: %v", err)
status.Err = err.Error()
return &pb.HTTPResponse{Status: &status}, err
}
}
var resJson bytes.Buffer
_, err := apiClient.Call(method, reqUrl, bodyObj, &resJson, query)
if err != nil {
logger.Errorf("Call: %v", err)
status.Err = err.Error()
return &pb.HTTPResponse{Status: &status}, err
}
status.Ok = true
return &pb.HTTPResponse{Status: &status, Body: resJson.Bytes()}, nil
}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jumpserver-dev/sdk-go v0.0.0-20250925081620-d22b2b8e24d1 h1:6/d5CAJvnHwEiPmY7Pm5XgvIHeHATe/apnx9dmQR1yQ=
github.com/jumpserver-dev/sdk-go v0.0.0-20250925081620-d22b2b8e24d1/go.mod h1:CDNCGOGgeudYS4IKsHOG+ma1rBSbjv8toKtRax2Z0EE=
github.com/jumpserver-dev/sdk-go v0.0.0-20251007162206-113f4e3fdde6 h1:5DZ9IYsnu8E5H0JVwQWP2wRLQioO8X4ScFqvi0itc1E=
github.com/jumpserver-dev/sdk-go v0.0.0-20251007162206-113f4e3fdde6/go.mod h1:CDNCGOGgeudYS4IKsHOG+ma1rBSbjv8toKtRax2Z0EE=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down
Loading