Skip to content

Commit f353c83

Browse files
committed
modify func name
1 parent c3964ae commit f353c83

File tree

15 files changed

+56
-38
lines changed

15 files changed

+56
-38
lines changed

api/metadata/metadata.pb.go

Lines changed: 1 addition & 1 deletion
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: 13 additions & 4 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: 2 additions & 2 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path
219219
Path: path,
220220
Method: method,
221221
HasVars: len(vars) > 0,
222-
UseProtoTextNameAsKey: *isUseProtoTextNameAsKey,
222+
UseProtoTextEncodeURL: *isUseProtoTextEncodeURL,
223223
}
224224
}
225225

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().UseTextNameAsKey({{.UseProtoTextNameAsKey}}))
73+
path := binding.EncodeURL(pattern, in, {{not .HasBody}}, option.Encode().UseProtoTextAsKey({{.UseProtoTextEncodeURL}}))
7474
opts = append(opts, http.Operation(Operation{{$svrType}}{{.OriginalName}}))
7575
opts = append(opts, http.PathTemplate(pattern))
7676
{{if .HasBody -}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var (
1212
showVersion = flag.Bool("version", false, "print the version and exit")
1313
omitempty = flag.Bool("omitempty", true, "omit if google.api is empty")
1414
omitemptyPrefix = flag.String("omitempty_prefix", "", "omit if google.api is empty")
15-
isUseProtoTextNameAsKey = flag.Bool("prototext_as_formkey", false, "use proto text name as params form key")
15+
isUseProtoTextEncodeURL = flag.Bool("prototext_encodeurl", false, "use proto text name as params form key")
1616
)
1717

1818
func main() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type methodDesc struct {
3333
HasBody bool
3434
Body string
3535
ResponseBody string
36-
UseProtoTextNameAsKey bool
36+
UseProtoTextEncodeURL bool
3737
}
3838

3939
func (s *serviceDesc) execute() string {

encoding/form/form_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func TestEncodeFieldMask(t *testing.T) {
207207
if v != "updateMask=foo,bar" {
208208
t.Errorf("got %s", v)
209209
}
210-
v = EncodeFieldMask(req.ProtoReflect(), option.Encode().UseTextNameAsKey(true))
210+
v = EncodeFieldMask(req.ProtoReflect(), option.Encode().UseProtoTextAsKey(true))
211211
if v != "update_mask=foo,bar" {
212212
t.Errorf("got %s", v)
213213
}
@@ -225,7 +225,7 @@ func TestOptional(t *testing.T) {
225225
t.Fatalf("got %s", query.Encode())
226226
}
227227

228-
query, _ = EncodeValues(req, option.Encode().UseTextNameAsKey(true))
228+
query, _ = EncodeValues(req, option.Encode().UseProtoTextAsKey(true))
229229
if query.Encode() != "name=foo&opt_int32=100&sub.naming=bar" {
230230
t.Fatalf("got %s", query.Encode())
231231
}

encoding/form/option/encode.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package option
22

33
// EncodeOption is the encoding options.
44
type EncodeOption struct {
5-
ForceTextNameAsKey bool // forces to use proto field text name.
5+
ForceProtoTextAsKey bool // forces to use proto field text name.
66
}
77

88
// Encode creates a new EncodeOption instance.
99
func Encode() *EncodeOption {
1010
return &EncodeOption{}
1111
}
1212

13-
// UseTextNameAsKey forces to use proto field text name as key.
14-
func (opt *EncodeOption) UseTextNameAsKey(isUse bool) *EncodeOption {
15-
opt.ForceTextNameAsKey = isUse
13+
// UseProtoTextAsKey forces to use proto field text name as key.
14+
func (opt *EncodeOption) UseProtoTextAsKey(isUse bool) *EncodeOption {
15+
opt.ForceProtoTextAsKey = isUse
1616
return opt
1717
}
1818

@@ -24,8 +24,8 @@ func MergeEncodeOptions(opts ...*EncodeOption) *EncodeOption {
2424
continue
2525
}
2626

27-
if o.ForceTextNameAsKey {
28-
opt.ForceTextNameAsKey = true
27+
if o.ForceProtoTextAsKey {
28+
opt.ForceProtoTextAsKey = true
2929
}
3030
}
3131
return opt

encoding/form/option/encode_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package option
22

33
import "testing"
44

5-
func TestEncodeOption_UseTextNameAsKey(t *testing.T) {
6-
e := Encode().UseTextNameAsKey(true)
7-
if e.ForceTextNameAsKey != true {
5+
func TestEncodeOption_UseProtoTextAsKey(t *testing.T) {
6+
e := Encode().UseProtoTextAsKey(true)
7+
if e.ForceProtoTextAsKey != true {
88
t.Error("expect true")
99
}
10-
e = Encode().UseTextNameAsKey(false)
11-
if e.ForceTextNameAsKey != false {
10+
e = Encode().UseProtoTextAsKey(false)
11+
if e.ForceProtoTextAsKey != false {
1212
t.Error("expect false")
1313
}
1414
}
@@ -18,23 +18,23 @@ func TestMergeEncodeOptions(t *testing.T) {
1818
if opt == nil {
1919
t.Fatal("expect not nil")
2020
}
21-
if opt.ForceTextNameAsKey {
21+
if opt.ForceProtoTextAsKey {
2222
t.Error("expect false")
2323
}
2424

25-
opt = MergeEncodeOptions(Encode().UseTextNameAsKey(true))
25+
opt = MergeEncodeOptions(Encode().UseProtoTextAsKey(true))
2626
if opt == nil {
2727
t.Fatal("expect not nil")
2828
}
29-
if !opt.ForceTextNameAsKey {
29+
if !opt.ForceProtoTextAsKey {
3030
t.Error("expect true")
3131
}
3232

33-
opt = MergeEncodeOptions(&EncodeOption{}, Encode().UseTextNameAsKey(true))
33+
opt = MergeEncodeOptions(&EncodeOption{}, Encode().UseProtoTextAsKey(true))
3434
if opt == nil {
3535
t.Fatal("expect not nil")
3636
}
37-
if !opt.ForceTextNameAsKey {
37+
if !opt.ForceProtoTextAsKey {
3838
t.Error("expect true")
3939
}
4040
}

0 commit comments

Comments
 (0)