| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package client |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "fmt" |
||
| 5 | "time" |
||
| 6 | ) |
||
| 7 | |||
| 8 | const ( |
||
| 9 | clientVersion = "v0.0.1" |
||
| 10 | |||
| 11 | defaultBaseURL = "https://minfraud.maxmind.com/minfraud" |
||
| 12 | defaultTimeout = 20 * time.Second |
||
| 13 | ) |
||
| 14 | |||
| 15 | var defaultUserAgent = fmt.Sprintf("minfraund-api-go/%s", clientVersion) |
||
| 16 | |||
| 17 | // Option contains optional setting of Client. |
||
| 18 | type Option struct { |
||
| 19 | BaseURL string |
||
| 20 | UserAgent string |
||
| 21 | Timeout time.Duration |
||
| 22 | Debug bool |
||
| 23 | Retry bool |
||
| 24 | LogFn func(msg string, opts ...interface{}) |
||
| 25 | } |
||
| 26 | |||
| 27 | func (o Option) LogInfo(msg string, opts ...interface{}) { |
||
| 28 | if o.LogFn == nil { |
||
| 29 | return |
||
| 30 | } |
||
| 31 | o.LogFn(msg, opts...) |
||
| 32 | } |
||
| 33 | |||
| 34 | func (o Option) getBaseURL() string { |
||
| 35 | if o.BaseURL != "" { |
||
| 36 | return o.BaseURL |
||
| 37 | } |
||
| 38 | return defaultBaseURL |
||
| 39 | } |
||
| 40 | |||
| 41 | func (o Option) getUserAgent() string { |
||
| 42 | if o.UserAgent != "" { |
||
| 43 | return o.UserAgent |
||
| 44 | } |
||
| 45 | return defaultUserAgent |
||
| 46 | } |
||
| 47 | |||
| 48 | func (o Option) getTimeout() time.Duration { |
||
| 49 | if o.Timeout > 0 { |
||
| 50 | return o.Timeout |
||
| 51 | } |
||
| 52 | return defaultTimeout |
||
| 53 | } |
||
| 54 |