-
Notifications
You must be signed in to change notification settings - Fork 77
/
netlify_client.go
67 lines (55 loc) · 1.84 KB
/
netlify_client.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
package porcelain
import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/netlify/open-api/go/plumbing"
"github.com/netlify/open-api/go/porcelain/http"
)
const DefaultSyncFileLimit = 500
const DefaultConcurrentUploadLimit = 10
const DefaultRetryAttempts = 3
// Default netlify HTTP client.
var Default = NewHTTPClient(nil)
// NewHTTPClient creates a new netlify HTTP client.
func NewHTTPClient(formats strfmt.Registry) *Netlify {
cfg := plumbing.DefaultTransportConfig()
transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
return New(transport, formats)
}
// NewRetryableHTTPClient creates a new netlify HTTP client with a number of attempts for rate limits.
func NewRetryableHTTPClient(formats strfmt.Registry, attempts int) *Netlify {
cfg := plumbing.DefaultTransportConfig()
transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
return NewRetryable(transport, formats, attempts)
}
// NewRetryable creates a new netlify client with a number of attempts for rate limits.
func NewRetryable(transport runtime.ClientTransport, formats strfmt.Registry, attempts int) *Netlify {
tr := http.NewRetryableTransport(transport, attempts)
return New(tr, formats)
}
// New creates a new netlify client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Netlify {
n := plumbing.New(transport, formats)
return &Netlify{
Netlify: n,
syncFileLimit: DefaultSyncFileLimit,
uploadLimit: DefaultConcurrentUploadLimit,
}
}
// Netlify is a client for netlify
type Netlify struct {
*plumbing.Netlify
syncFileLimit int
uploadLimit int
}
func (n *Netlify) SetSyncFileLimit(limit int) {
if limit > 0 {
n.syncFileLimit = limit
}
}
func (n *Netlify) SetConcurrentUploadLimit(limit int) {
if limit > 0 {
n.uploadLimit = limit
}
}