-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfactory.go
More file actions
46 lines (37 loc) · 970 Bytes
/
factory.go
File metadata and controls
46 lines (37 loc) · 970 Bytes
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
package arc
import (
"strings"
"time"
"github.com/pkg/errors"
"github.com/tokenized/config"
)
type Config struct {
ConnectTimeout config.Duration `defautl:"10s" json:"connection_timeout"`
RequestTimeout config.Duration `defautl:"30s" json:"request_timeout"`
}
func (c Config) Copy() Config {
return Config{
ConnectTimeout: c.ConnectTimeout,
RequestTimeout: c.RequestTimeout,
}
}
func DefaultConfig() Config {
return Config{
ConnectTimeout: config.NewDuration(time.Second * 10),
RequestTimeout: config.NewDuration(time.Second * 30),
}
}
type Factory struct {
config Config
}
func NewFactory(config Config) *Factory {
return &Factory{
config: config,
}
}
func (f *Factory) NewClient(url, authToken, callBackURL string) (Client, error) {
if strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "http://") {
return NewHTTPClient(url, authToken, callBackURL, f.config), nil
}
return nil, errors.New("Unsupported URL protocol")
}