Skip to content

Commit a04a1a0

Browse files
committed
modify the location of option
1 parent dbc4efc commit a04a1a0

File tree

16 files changed

+301
-299
lines changed

16 files changed

+301
-299
lines changed

api/metadata/metadata.pb.go

Lines changed: 83 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/metadata/metadata_grpc.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/metadata/metadata_http.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/protoc-gen-go-http/http.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
)
1616

1717
const (
18-
contextPackage = protogen.GoImportPath("context")
19-
transportHTTPPackage = protogen.GoImportPath("github.com/go-kratos/kratos/v2/transport/http")
20-
bindingPackage = protogen.GoImportPath("github.com/go-kratos/kratos/v2/transport/http/binding")
21-
formEncodeOptionPackage = protogen.GoImportPath("github.com/go-kratos/kratos/v2/encoding/form/option")
18+
contextPackage = protogen.GoImportPath("context")
19+
transportHTTPPackage = protogen.GoImportPath("github.com/go-kratos/kratos/v2/transport/http")
20+
bindingPackage = protogen.GoImportPath("github.com/go-kratos/kratos/v2/transport/http/binding")
21+
formPackage = protogen.GoImportPath("github.com/go-kratos/kratos/v2/encoding/form")
2222
)
2323

2424
var methodSets = make(map[string]int)
@@ -55,7 +55,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
5555
g.P("// is compatible with the kratos package it is being compiled against.")
5656
g.P("var _ = new(", contextPackage.Ident("Context"), ")")
5757
g.P("var _ = ", bindingPackage.Ident("EncodeURL"))
58-
g.P("var _ = ", formEncodeOptionPackage.Ident("Encode"))
58+
g.P("var _ = ", formPackage.Ident("Encode"))
5959
g.P("const _ = ", transportHTTPPackage.Ident("SupportPackageIsVersion1"))
6060
g.P()
6161

cmd/protoc-gen-go-http/httpTemplate.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func New{{.ServiceType}}HTTPClient (client *http.Client) {{.ServiceType}}HTTPCli
7070
func (c *{{$svrType}}HTTPClientImpl) {{.Name}}(ctx context.Context, in *{{.Request}}, opts ...http.CallOption) (*{{.Reply}}, error) {
7171
var out {{.Reply}}
7272
pattern := "{{.Path}}"
73-
path := binding.EncodeURL(pattern, in, {{not .HasBody}}, option.Encode().UseProtoTextAsKey({{.UseProtoTextEncodeURL}}))
73+
path := binding.EncodeURL(pattern, in, {{not .HasBody}}, form.Encode().UseProtoTextAsKey({{.UseProtoTextEncodeURL}}))
7474
opts = append(opts, http.Operation(Operation{{$svrType}}{{.OriginalName}}))
7575
opts = append(opts, http.PathTemplate(pattern))
7676
{{if .HasBody -}}

encoding/form/option/encode.go renamed to encoding/form/encodeoption.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package option
1+
package form
22

33
// EncodeOption is the encoding options.
44
type EncodeOption struct {

encoding/form/option/encode_test.go renamed to encoding/form/encodeoption_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package option
1+
package form
22

33
import "testing"
44

encoding/form/form_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"google.golang.org/protobuf/types/known/wrapperspb"
1313

1414
"github.com/go-kratos/kratos/v2/encoding"
15-
"github.com/go-kratos/kratos/v2/encoding/form/option"
1615
bdtest "github.com/go-kratos/kratos/v2/internal/testdata/binding"
1716
"github.com/go-kratos/kratos/v2/internal/testdata/complex"
1817
ectest "github.com/go-kratos/kratos/v2/internal/testdata/encoding"
@@ -271,7 +270,7 @@ func TestEncodeFieldMask(t *testing.T) {
271270
if v != "updateMask=foo,bar" {
272271
t.Errorf("got %s", v)
273272
}
274-
v = EncodeFieldMask(req.ProtoReflect(), option.Encode().UseProtoTextAsKey(true))
273+
v = EncodeFieldMask(req.ProtoReflect(), Encode().UseProtoTextAsKey(true))
275274
if v != "update_mask=foo,bar" {
276275
t.Errorf("got %s", v)
277276
}
@@ -289,7 +288,7 @@ func TestOptional(t *testing.T) {
289288
t.Fatalf("got %s", query.Encode())
290289
}
291290

292-
query, _ = EncodeValues(req, option.Encode().UseProtoTextAsKey(true))
291+
query, _ = EncodeValues(req, Encode().UseProtoTextAsKey(true))
293292
if query.Encode() != "name=foo&opt_int32=100&sub.naming=bar" {
294293
t.Fatalf("got %s", query.Encode())
295294
}

encoding/form/proto_encode.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import (
1111
"google.golang.org/protobuf/proto"
1212
"google.golang.org/protobuf/reflect/protoreflect"
1313
"google.golang.org/protobuf/types/known/fieldmaskpb"
14-
15-
"github.com/go-kratos/kratos/v2/encoding/form/option"
1614
)
1715

1816
// EncodeValues encode a message into url values.
19-
func EncodeValues(msg any, opts ...*option.EncodeOption) (url.Values, error) {
17+
func EncodeValues(msg any, opts ...*EncodeOption) (url.Values, error) {
2018
if msg == nil || (reflect.ValueOf(msg).Kind() == reflect.Ptr && reflect.ValueOf(msg).IsNil()) {
2119
return url.Values{}, nil
2220
}
@@ -31,8 +29,8 @@ func EncodeValues(msg any, opts ...*option.EncodeOption) (url.Values, error) {
3129
return encoder.Encode(msg)
3230
}
3331

34-
func encodeByField(u url.Values, path string, m protoreflect.Message, opts ...*option.EncodeOption) (finalErr error) {
35-
opt := option.MergeEncodeOptions(opts...)
32+
func encodeByField(u url.Values, path string, m protoreflect.Message, opts ...*EncodeOption) (finalErr error) {
33+
opt := MergeEncodeOptions(opts...)
3634
m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
3735
var (
3836
key string
@@ -180,8 +178,8 @@ func encodeMessage(msgDescriptor protoreflect.MessageDescriptor, value protorefl
180178
}
181179

182180
// EncodeFieldMask return field mask name=paths
183-
func EncodeFieldMask(m protoreflect.Message, opts ...*option.EncodeOption) (query string) {
184-
opt := option.MergeEncodeOptions(opts...)
181+
func EncodeFieldMask(m protoreflect.Message, opts ...*EncodeOption) (query string) {
182+
opt := MergeEncodeOptions(opts...)
185183
m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
186184
if fd.Kind() == protoreflect.MessageKind {
187185
if msg := fd.Message(); msg.FullName() == fieldMaskFullName {

0 commit comments

Comments
 (0)