Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serde options refactor #506

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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 pkg/sr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Client struct {
}

// NewClient returns a new schema registry client.
func NewClient(opts ...Opt) (*Client, error) {
func NewClient(opts ...ClientOpt) (*Client, error) {
cl := &Client{
urls: []string{"http://localhost:8081"},
httpcl: &http.Client{Timeout: 5 * time.Second},
Expand Down
32 changes: 16 additions & 16 deletions pkg/sr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ import (
)

type (
// Opt is an option to configure a client.
Opt interface{ apply(*Client) }
opt struct{ fn func(*Client) }
// ClientOpt is an option to configure a client.
ClientOpt interface{ apply(*Client) }
clientOpt struct{ fn func(*Client) }
)

func (o opt) apply(cl *Client) { o.fn(cl) }
func (o clientOpt) apply(cl *Client) { o.fn(cl) }

// HTTPClient sets the http client that the schema registry client uses,
// overriding the default client that speaks plaintext with a timeout of 5s.
func HTTPClient(httpcl *http.Client) Opt {
return opt{func(cl *Client) { cl.httpcl = httpcl }}
func HTTPClient(httpcl *http.Client) ClientOpt {
return clientOpt{func(cl *Client) { cl.httpcl = httpcl }}
}

// UserAgent sets the User-Agent to use in requests, overriding the default
// "franz-go".
func UserAgent(ua string) Opt {
return opt{func(cl *Client) { cl.ua = ua }}
func UserAgent(ua string) ClientOpt {
return clientOpt{func(cl *Client) { cl.ua = ua }}
}

// URLs sets the URLs that the client speaks to, overriding the default
// http://localhost:8081. This option automatically prefixes any URL that is
// missing an http:// or https:// prefix with http://.
func URLs(urls ...string) Opt {
return opt{func(cl *Client) {
func URLs(urls ...string) ClientOpt {
return clientOpt{func(cl *Client) {
for i, u := range urls {
if strings.HasPrefix(u, "http://") || strings.HasPrefix(u, "https://") {
continue
Expand All @@ -45,8 +45,8 @@ func URLs(urls ...string) Opt {
}

// DialTLSConfig sets a tls.Config to use in the default http client.
func DialTLSConfig(c *tls.Config) Opt {
return opt{func(cl *Client) {
func DialTLSConfig(c *tls.Config) ClientOpt {
return clientOpt{func(cl *Client) {
cl.httpcl = &http.Client{
Timeout: 5 * time.Second,
Transport: &http.Transport{
Expand All @@ -71,13 +71,13 @@ func DialTLSConfig(c *tls.Config) Opt {
// getting or creating schemas. This can help collapse duplicate schemas into
// one, but can also be done with a configuration parameter on the schema
// registry itself.
func Normalize() Opt {
return opt{func(cl *Client) { cl.normalize = true }}
func Normalize() ClientOpt {
return clientOpt{func(cl *Client) { cl.normalize = true }}
}

// BasicAuth sets basic authorization to use for every request.
func BasicAuth(user, pass string) Opt {
return opt{func(cl *Client) {
func BasicAuth(user, pass string) ClientOpt {
return clientOpt{func(cl *Client) {
cl.basicAuth = &struct {
user string
pass string
Expand Down
Loading