generated from milosgajdos/go-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvocode.go
79 lines (66 loc) · 1.5 KB
/
vocode.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package vocode
import (
"os"
"github.com/milosgajdos/go-vocode/client"
)
const (
// BaseURL is Vocode HTTP API base URL.
BaseURL = "https://api.vocode.dev"
// APIV1 V1 version.
APIV1 = "v1"
)
// Client is an Vocode HTTP API client.
type Client struct {
opts Options
}
type Options struct {
APIKey string
UserID string
BaseURL string
Version string
HTTPClient *client.HTTP
}
// Option is functional graph option.
type Option func(*Options)
// NewClient creates a new HTTP API client and returns it.
// By default it reads the secret key from PLAYHT_SECRET_KEY env var
// and user ID from PLAYHT_USER_ID env var and uses
// the default http client for making the HTTP api requests.
func NewClient(opts ...Option) *Client {
options := Options{
APIKey: os.Getenv("VOCODE_API_KEY"),
BaseURL: BaseURL,
Version: APIV1,
HTTPClient: client.NewHTTP(),
}
for _, apply := range opts {
apply(&options)
}
return &Client{
opts: options,
}
}
// WithAPIKey sets the secret key.
func WithAPIKey(apiKey string) Option {
return func(o *Options) {
o.APIKey = apiKey
}
}
// WithBaseURL sets the API base URL.
func WithBaseURL(baseURL string) Option {
return func(o *Options) {
o.BaseURL = baseURL
}
}
// WithVersion sets the API version.
func WithVersion(version string) Option {
return func(o *Options) {
o.Version = version
}
}
// WithHTTPClient sets the HTTP client.
func WithHTTPClient(httpClient *client.HTTP) Option {
return func(o *Options) {
o.HTTPClient = httpClient
}
}