Skip to content

Commit

Permalink
add client option for literal URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
ofpiyush committed Sep 25, 2020
1 parent f7b1717 commit fd98ac9
Show file tree
Hide file tree
Showing 23 changed files with 1,068 additions and 512 deletions.
17 changes: 14 additions & 3 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ type ClientOption func(*ClientOptions)

// ClientOptions encapsulate the configurable parameters on a Twirp client.
type ClientOptions struct {
Interceptors []Interceptor
Hooks *ClientHooks
pathPrefix *string
Interceptors []Interceptor
Hooks *ClientHooks
UseLiteralCaseURLs bool
pathPrefix *string
}

func (opts *ClientOptions) PathPrefix() string {
Expand Down Expand Up @@ -130,3 +131,13 @@ func WithClientPathPrefix(prefix string) ClientOption {
o.pathPrefix = &prefix
}
}

// WithClientLiteralCase sets twirp client to use exact names for service and method names as defined the protobuf file.
// Example: for Service name `haberdasher` and method name `make_hat`, the default URL is `/<prefix>/<package>.Haberdasher/MakeHat`
// using this option will make the client send requests to `/<prefix>/<package>.haberdasher/make_hat` instead.
// This is required when working with spec-compatible servers in other languages.
func WithClientLiteralCase() ClientOption {
return func(o *ClientOptions) {
o.UseLiteralCaseURLs = true
}
}
18 changes: 18 additions & 0 deletions client_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,21 @@ func TestWithClientPathPrefix(t *testing.T) {
t.Errorf("unexpected value after WithClientPathPrefix, have: %q, want: %q", have, want)
}
}

func TestWithClientLiteralCase(t *testing.T) {
opts := &ClientOptions{}

// Default value
if have, want := opts.UseLiteralCaseURLs, false; have != want {
t.Errorf("unexpected default UseLiteral on ClientOptions, have: %t, want: %t", have, want)
return
}

// Set a different prefix
WithClientLiteralCase()(opts)
if have, want := opts.UseLiteralCaseURLs, true; have != want {
t.Errorf("unexpected value after WithClientLiteralCase, have: %t, want: %t", have, want)
return
}

}
100 changes: 70 additions & 30 deletions clientcompat/internal/clientcompat/clientcompat.twirp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 52 additions & 26 deletions example/service.twirp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd98ac9

Please sign in to comment.