Skip to content

Commit a3d3a8b

Browse files
JasperZheng99jasper
authored andcommitted
Merge branch 'master' into feature/mcp-option
2 parents e229d6e + 3f91a79 commit a3d3a8b

6 files changed

Lines changed: 270 additions & 141 deletions

File tree

rest/httpc/requests.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ func buildRequest(ctx context.Context, method, url string, data any) (*http.Requ
8484
var reader io.Reader
8585
jsonVars, hasJsonBody := val[jsonKey]
8686
if hasJsonBody {
87-
if method == http.MethodGet {
87+
switch method {
88+
case http.MethodGet:
8889
return nil, ErrGetWithBody
90+
case http.MethodHead:
91+
return nil, ErrHeadWithBody
8992
}
9093

9194
var buf bytes.Buffer

rest/httpc/requests_test.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,106 @@ func TestDo_WithClientHttpTrace(t *testing.T) {
229229
assert.Nil(t, err)
230230
assert.True(t, enter)
231231
}
232+
233+
func TestBuildRequestWithBody(t *testing.T) {
234+
testBody := struct {
235+
Key string `json:"key"`
236+
Value int `json:"value"`
237+
}{
238+
Key: "foo",
239+
Value: 10,
240+
}
241+
242+
testcases := []struct {
243+
testName string
244+
method string
245+
url string
246+
body any
247+
wantedErr error
248+
}{
249+
{
250+
testName: "GET Request with Body",
251+
method: http.MethodGet,
252+
url: "/ping",
253+
body: testBody,
254+
wantedErr: ErrGetWithBody,
255+
},
256+
{
257+
testName: "GET Request without Body",
258+
method: http.MethodGet,
259+
url: "/ping",
260+
body: nil,
261+
wantedErr: nil,
262+
},
263+
{
264+
testName: "HEAD Request with Body",
265+
method: http.MethodHead,
266+
url: "/ping",
267+
body: testBody,
268+
wantedErr: ErrHeadWithBody,
269+
},
270+
{
271+
testName: "HEAD Request without Body",
272+
method: http.MethodHead,
273+
url: "/ping",
274+
body: nil,
275+
wantedErr: nil,
276+
},
277+
{
278+
testName: "POST Request with Body",
279+
method: http.MethodPost,
280+
url: "/ping",
281+
body: testBody,
282+
wantedErr: nil,
283+
},
284+
{
285+
testName: "PUT Request with Body",
286+
method: http.MethodPut,
287+
url: "/ping",
288+
body: testBody,
289+
wantedErr: nil,
290+
},
291+
{
292+
testName: "PATCH Request with Body",
293+
method: http.MethodPatch,
294+
url: "/ping",
295+
body: testBody,
296+
wantedErr: nil,
297+
},
298+
{
299+
testName: "DELETE Request with Body",
300+
method: http.MethodDelete,
301+
url: "/ping",
302+
body: testBody,
303+
wantedErr: nil,
304+
},
305+
{
306+
testName: "CONNECT Request with Body",
307+
method: http.MethodConnect,
308+
url: "/ping",
309+
body: testBody,
310+
wantedErr: nil,
311+
},
312+
{
313+
testName: "OPTIONS Request with Body",
314+
method: http.MethodOptions,
315+
url: "/ping",
316+
body: testBody,
317+
wantedErr: nil,
318+
},
319+
{
320+
testName: "TRACE Request with Body",
321+
method: http.MethodTrace,
322+
url: "/ping",
323+
body: testBody,
324+
wantedErr: nil,
325+
},
326+
}
327+
328+
for _, tc := range testcases {
329+
t.Run(tc.testName, func(t *testing.T) {
330+
_, err := buildRequest(context.Background(), tc.method, tc.url, tc.body)
331+
assert.Equal(t, tc.wantedErr, err)
332+
})
333+
}
334+
}

rest/httpc/vars.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ const (
1111
colon = ':'
1212
)
1313

14-
// ErrGetWithBody indicates that GET request with body.
15-
var ErrGetWithBody = errors.New("HTTP GET should not have body")
14+
var (
15+
// ErrGetWithBody indicates that GET request with body.
16+
ErrGetWithBody = errors.New("HTTP GET should not have body")
17+
// ErrHeadWithBody indicates that HEAD request with body.
18+
ErrHeadWithBody = errors.New("HTTP HEAD should not have body")
19+
)

tools/goctl/go.mod

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
1717
github.com/zeromicro/antlr v0.0.1
1818
github.com/zeromicro/ddl-parser v1.0.5
19-
github.com/zeromicro/go-zero v1.10.0
19+
github.com/zeromicro/go-zero v1.10.1
2020
golang.org/x/text v0.34.0
2121
google.golang.org/grpc v1.79.3
2222
google.golang.org/protobuf v1.36.11
@@ -25,35 +25,35 @@ require (
2525

2626
require (
2727
filippo.io/edwards25519 v1.1.0 // indirect
28-
github.com/alicebob/miniredis/v2 v2.36.1 // indirect
28+
github.com/alicebob/miniredis/v2 v2.37.0 // indirect
2929
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210521184019-c5ad59b459ec // indirect
3030
github.com/beorn7/perks v1.0.1 // indirect
31-
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
31+
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
3232
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3333
github.com/coreos/go-semver v0.3.1 // indirect
3434
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
3535
github.com/davecgh/go-spew v1.1.1 // indirect
3636
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
37-
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
37+
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
3838
github.com/fatih/color v1.18.0 // indirect
39+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
3940
github.com/go-logr/logr v1.4.3 // indirect
4041
github.com/go-logr/stdr v1.2.2 // indirect
4142
github.com/go-openapi/jsonpointer v0.21.1 // indirect
4243
github.com/go-openapi/jsonreference v0.21.0 // indirect
4344
github.com/go-openapi/swag v0.23.1 // indirect
4445
github.com/gogo/protobuf v1.3.2 // indirect
4546
github.com/golang/protobuf v1.5.4 // indirect
46-
github.com/google/gnostic-models v0.6.8 // indirect
47+
github.com/google/gnostic-models v0.7.0 // indirect
4748
github.com/google/go-cmp v0.7.0 // indirect
48-
github.com/google/gofuzz v1.2.0 // indirect
4949
github.com/google/uuid v1.6.0 // indirect
50-
github.com/grafana/pyroscope-go v1.2.7 // indirect
50+
github.com/grafana/pyroscope-go v1.2.8 // indirect
5151
github.com/grafana/pyroscope-go/godeltaprof v0.1.9 // indirect
52-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
52+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 // indirect
5353
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5454
github.com/jackc/pgpassfile v1.0.0 // indirect
5555
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
56-
github.com/jackc/pgx/v5 v5.7.4 // indirect
56+
github.com/jackc/pgx/v5 v5.8.0 // indirect
5757
github.com/jackc/puddle/v2 v2.2.2 // indirect
5858
github.com/josharian/intern v1.0.0 // indirect
5959
github.com/json-iterator/go v1.1.12 // indirect
@@ -63,57 +63,62 @@ require (
6363
github.com/mattn/go-colorable v0.1.13 // indirect
6464
github.com/mattn/go-isatty v0.0.20 // indirect
6565
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
66-
github.com/modern-go/reflect2 v1.0.2 // indirect
66+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
6767
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6868
github.com/openzipkin/zipkin-go v0.4.3 // indirect
69-
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
69+
github.com/pelletier/go-toml/v2 v2.3.0 // indirect
70+
github.com/pkg/errors v0.9.1 // indirect
7071
github.com/pmezard/go-difflib v1.0.0 // indirect
7172
github.com/prometheus/client_golang v1.23.2 // indirect
7273
github.com/prometheus/client_model v0.6.2 // indirect
7374
github.com/prometheus/common v0.66.1 // indirect
7475
github.com/prometheus/procfs v0.16.1 // indirect
75-
github.com/redis/go-redis/v9 v9.17.3 // indirect
76+
github.com/redis/go-redis/v9 v9.18.0 // indirect
7677
github.com/spaolacci/murmur3 v1.1.0 // indirect
78+
github.com/titanous/json5 v1.0.0 // indirect
79+
github.com/x448/float16 v0.8.4 // indirect
7780
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
7881
github.com/yuin/gopher-lua v1.1.1 // indirect
79-
go.etcd.io/etcd/api/v3 v3.5.15 // indirect
80-
go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
81-
go.etcd.io/etcd/client/v3 v3.5.15 // indirect
82+
go.etcd.io/etcd/api/v3 v3.5.21 // indirect
83+
go.etcd.io/etcd/client/pkg/v3 v3.5.21 // indirect
84+
go.etcd.io/etcd/client/v3 v3.5.21 // indirect
8285
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
83-
go.opentelemetry.io/otel v1.39.0 // indirect
84-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
85-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect
86-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
87-
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 // indirect
88-
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 // indirect
89-
go.opentelemetry.io/otel/metric v1.39.0 // indirect
90-
go.opentelemetry.io/otel/sdk v1.39.0 // indirect
91-
go.opentelemetry.io/otel/trace v1.39.0 // indirect
92-
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
93-
go.uber.org/atomic v1.10.0 // indirect
86+
go.opentelemetry.io/otel v1.40.0 // indirect
87+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 // indirect
88+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.40.0 // indirect
89+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.40.0 // indirect
90+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.40.0 // indirect
91+
go.opentelemetry.io/otel/exporters/zipkin v1.40.0 // indirect
92+
go.opentelemetry.io/otel/metric v1.40.0 // indirect
93+
go.opentelemetry.io/otel/sdk v1.40.0 // indirect
94+
go.opentelemetry.io/otel/trace v1.40.0 // indirect
95+
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
96+
go.uber.org/atomic v1.11.0 // indirect
9497
go.uber.org/automaxprocs v1.6.0 // indirect
9598
go.uber.org/mock v0.6.0 // indirect
9699
go.uber.org/multierr v1.9.0 // indirect
97100
go.uber.org/zap v1.24.0 // indirect
98101
go.yaml.in/yaml/v2 v2.4.2 // indirect
99-
golang.org/x/crypto v0.46.0 // indirect
100-
golang.org/x/net v0.48.0 // indirect
102+
go.yaml.in/yaml/v3 v3.0.4 // indirect
103+
golang.org/x/net v0.50.0 // indirect
101104
golang.org/x/oauth2 v0.34.0 // indirect
102105
golang.org/x/sync v0.19.0 // indirect
103-
golang.org/x/sys v0.39.0 // indirect
104-
golang.org/x/term v0.38.0 // indirect
105-
golang.org/x/time v0.10.0 // indirect
106-
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect
107-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
106+
golang.org/x/sys v0.41.0 // indirect
107+
golang.org/x/term v0.40.0 // indirect
108+
golang.org/x/time v0.14.0 // indirect
109+
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
110+
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
111+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
108112
gopkg.in/inf.v0 v0.9.1 // indirect
109113
gopkg.in/yaml.v3 v3.0.1 // indirect
110-
k8s.io/api v0.29.3 // indirect
111-
k8s.io/apimachinery v0.29.4 // indirect
112-
k8s.io/client-go v0.29.3 // indirect
113-
k8s.io/klog/v2 v2.110.1 // indirect
114-
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
115-
k8s.io/utils v0.0.0-20251222233032-718f0e51e6d2 // indirect
116-
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
117-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
118-
sigs.k8s.io/yaml v1.3.0 // indirect
114+
k8s.io/api v0.34.3 // indirect
115+
k8s.io/apimachinery v0.34.3 // indirect
116+
k8s.io/client-go v0.34.3 // indirect
117+
k8s.io/klog/v2 v2.130.1 // indirect
118+
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
119+
k8s.io/utils v0.0.0-20260319190234-28399d86e0b5 // indirect
120+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
121+
sigs.k8s.io/randfill v1.0.0 // indirect
122+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
123+
sigs.k8s.io/yaml v1.6.0 // indirect
119124
)

0 commit comments

Comments
 (0)