Skip to content

Commit 364664d

Browse files
committed
helpers, options
1 parent fb9808e commit 364664d

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

pkg/client/inputs.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ type Input struct {
3333
Description string `json:"description"`
3434
}
3535

36+
func (i *Input) String() string {
37+
return fmt.Sprintf("%s [%s]", i.Name, i.EndpointURL())
38+
}
39+
40+
// EndpointURL returns default input URL. If CustomDomain is set (all new inputs from 2020 06 01 are getting them),
41+
// then it's this domain with path prefix, otherwise it's the URL based on the input ID
42+
func (i *Input) EndpointURL() string {
43+
if i.CustomDomain != "" {
44+
return "https://" + i.CustomDomain + i.PathPrefix
45+
}
46+
return "https://my.webhookrelay.com/v1/webhooks/" + i.ID
47+
}
48+
3649
// MarshalJSON helper to change time into unix
3750
func (i *Input) MarshalJSON() ([]byte, error) {
3851
type Alias Input

pkg/client/options.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ import (
88
// Option is a functional option for configuring the API client.
99
type Option func(*API) error
1010

11-
// HTTPClient accepts a custom *http.Client for making API calls.
12-
func HTTPClient(client *http.Client) Option {
11+
// WithHTTPClient accepts a custom *http.Client for making API calls.
12+
func WithHTTPClient(client *http.Client) Option {
1313
return func(api *API) error {
1414
api.httpClient = client
1515
return nil
1616
}
1717
}
1818

19-
// Headers allows you to set custom HTTP headers when making API calls (e.g. for
19+
// WithHeaders allows you to set custom HTTP headers when making API calls (e.g. for
2020
// satisfying HTTP proxies, or for debugging).
21-
func Headers(headers http.Header) Option {
21+
func WithHeaders(headers http.Header) Option {
2222
return func(api *API) error {
2323
api.headers = headers
2424
return nil
2525
}
2626
}
2727

28-
// UsingRetryPolicy applies a non-default number of retries and min/max retry delays
28+
// WithRetryPolicy applies a non-default number of retries and min/max retry delays
2929
// This will be used when the client exponentially backs off after errored requests
30-
func UsingRetryPolicy(maxRetries int, minRetryDelaySecs int, maxRetryDelaySecs int) Option {
30+
func WithRetryPolicy(maxRetries int, minRetryDelaySecs int, maxRetryDelaySecs int) Option {
3131
// seconds is very granular for a minimum delay - but this is only in case of failure
3232
return func(api *API) error {
3333
api.retryPolicy = RetryPolicy{
@@ -39,20 +39,20 @@ func UsingRetryPolicy(maxRetries int, minRetryDelaySecs int, maxRetryDelaySecs i
3939
}
4040
}
4141

42-
// UserAgent can be set if you want to send a software name and version for HTTP access logs.
42+
// WithUserAgent can be set if you want to send a software name and version for HTTP access logs.
4343
// It is recommended to set it in order to help future Customer Support diagnostics
4444
// and prevent collateral damage by sharing generic User-Agent string with abusive users.
4545
// E.g. "my-software/1.2.3". By default generic Go User-Agent is used.
46-
func UserAgent(userAgent string) Option {
46+
func WithUserAgent(userAgent string) Option {
4747
return func(api *API) error {
4848
api.UserAgent = userAgent
4949
return nil
5050
}
5151
}
5252

53-
// UsingLogger can be set if you want to get log output from this API instance
53+
// WithLogger can be set if you want to get log output from this API instance
5454
// By default no log output is emitted
55-
func UsingLogger(logger Logger) Option {
55+
func WithLogger(logger Logger) Option {
5656
return func(api *API) error {
5757
api.logger = logger
5858
return nil

0 commit comments

Comments
 (0)