-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mattevans/client-opts
feat(client): new client signature now takes opts
- Loading branch information
Showing
7 changed files
with
103 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package postmark | ||
|
||
import "net/http" | ||
|
||
// Option to set an optional client value. | ||
type Option func(o *Options) | ||
|
||
// Options for our client. | ||
type Options struct { | ||
Client *http.Client | ||
BackendURL string | ||
UserAgent string | ||
} | ||
|
||
// NewOptions returns a new Options with defaults and supplied overrides. | ||
func NewOptions(opts ...Option) *Options { | ||
out := Options{ | ||
Client: http.DefaultClient, | ||
BackendURL: backendURL, | ||
UserAgent: userAgent, | ||
} | ||
|
||
for _, o := range opts { | ||
o(&out) | ||
} | ||
|
||
return &out | ||
} | ||
|
||
// WithClient allows you to set a custom http client. | ||
func WithClient(v *http.Client) Option { | ||
return func(o *Options) { | ||
o.Client = v | ||
} | ||
} | ||
|
||
// WithBackendURL allows you to set a custom backend URL. | ||
func WithBackendURL(v string) Option { | ||
return func(o *Options) { | ||
o.BackendURL = v | ||
} | ||
} | ||
|
||
// WithUserAgent allows you to set a custom user agent. | ||
func WithUserAgent(v string) Option { | ||
return func(o *Options) { | ||
o.UserAgent = v | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters