/
factual.go
40 lines (33 loc) · 872 Bytes
/
factual.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package factual
import (
"net/http"
"github.com/garyburd/go-oauth/oauth"
"golang.org/x/net/context"
)
type Client struct {
Oauth oauth.Client
BaseUri string
ctx context.Context
}
const defaultUri = "https://api.factual.com"
// NewClient accepts a client ID and client secret and returns
// a factual client. It accepts variable number of functional
// options for configuring the client.
func NewClient(key string, secret string, opts ...Option) Client {
creds := oauth.Credentials{key, secret}
oauthClient := oauth.Client{
Credentials: creds,
SignatureMethod: oauth.HMACSHA1,
}
c := &Client{
Oauth: oauthClient,
BaseUri: defaultUri,
}
for _, opt := range opts {
opt(c)
}
return *c
}
// Option are functional options for configuring a Client
type Option func(c *Client) error
var getClient func(ctx context.Context) *http.Client