-
Notifications
You must be signed in to change notification settings - Fork 142
/
svix.go
84 lines (77 loc) 路 1.71 KB
/
svix.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
80
81
82
83
84
package svix
import (
"fmt"
"net/http"
"net/url"
"time"
"github.com/svix/svix-libs/go/internal/openapi"
"github.com/svix/svix-libs/go/internal/version"
)
type (
SvixOptions struct {
Debug bool
// Overrides the base URL (protocol + hostname) used for all requests sent by this Svix client. (Useful for testing)
ServerUrl *url.URL
HTTPClient *http.Client
}
Svix struct {
Authentication *Authentication
Application *Application
Endpoint *Endpoint
EventType *EventType
Integration *Integration
Message *Message
MessageAttempt *MessageAttempt
}
)
var defaultHTTPClient = &http.Client{
Timeout: 60 * time.Second,
}
func String(s string) *string {
return &s
}
func Int32(i int32) *int32 {
return &i
}
func New(token string, options *SvixOptions) *Svix {
conf := openapi.NewConfiguration()
conf.Scheme = "https"
conf.Host = "api.svix.com"
conf.HTTPClient = defaultHTTPClient
if options != nil {
conf.Debug = options.Debug
if options.ServerUrl != nil {
conf.Scheme = options.ServerUrl.Scheme
conf.Host = options.ServerUrl.Host
}
if options.HTTPClient != nil {
conf.HTTPClient = options.HTTPClient
}
}
conf.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token))
conf.UserAgent = fmt.Sprintf("svix-libs/%s/go", version.Version)
apiClient := openapi.NewAPIClient(conf)
return &Svix{
Authentication: &Authentication{
api: apiClient,
},
Application: &Application{
api: apiClient,
},
Endpoint: &Endpoint{
api: apiClient,
},
EventType: &EventType{
api: apiClient,
},
Message: &Message{
api: apiClient,
},
Integration: &Integration{
api: apiClient,
},
MessageAttempt: &MessageAttempt{
api: apiClient,
},
}
}