-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
126 lines (102 loc) · 3.19 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"context"
"fmt"
"log"
"os"
"time"
convoy "github.com/frain-dev/convoy-go/v2"
)
const (
URL = "http://localhost:5005/api/v1"
projectID = "01HS1672A88250D57J8SZV4P3A"
endpointID = "01HCB4CWTVAVWWJDJEASHGXPA6"
apiKey = "CO.tsmEVYn1muY1pU9t.wOB1pNEP92gnjlV7BUYz944TK9dRyYRvEzp9AR6jLy0r9Dk8WIqZ0JUhJuNq0IRm"
kUsername = "k-username"
kPassword = "k-password"
awsKey = "aws-key"
awsSecret = "aws-secret"
)
func main() {
logger := convoy.NewLogger(os.Stdout, convoy.DebugLevel)
ctx := context.Background()
c := convoy.New(URL, apiKey, projectID,
convoy.OptionLogger(logger),
)
//fmt.Println("Create Endpoint...")
//createEndpoint(ctx, c)
//fmt.Println("Pausing Endpoint...")
//pauseEndpoint(ctx, c)
//fmt.Println("Retrieving all endpoints")
//retrieveAllEndpoints(ctx, c)
//fmt.Println("Retrieveing all events")
//retrieveAllEvents(ctx, c)
fmt.Println("creating portal link")
createPortalLink(ctx, c)
}
func createEvent(ctx context.Context, c *convoy.Client) {
event, err := c.Events.Create(ctx, &convoy.CreateEventRequest{
EndpointID: endpointID,
EventType: "test.customer.event",
Data: []byte(`{"event_type": "test.event", "data": { "Hello": "World", "Test": "Data" }}`),
})
if err != nil {
log.Fatal("failed to create endpoint event \n", err)
return
}
log.Printf("\nEndpoint event created - %+v\n", event)
log.Printf("\nEndpoint event data - %+v\n", string(event.Data))
}
func createEndpoint(ctx context.Context, c *convoy.Client) {
tr := true
endpoint, err := c.Endpoints.Create(ctx, &convoy.CreateEndpointRequest{
Name: "Endpoint Go SDK",
URL: "https://webhook.site/4a5f8928-73fc-40e2-921c-e037afa9ea09",
Description: "Some description",
OwnerID: "my_owner_id",
AdvancedSignatures: &tr,
HttpTimeout: "10s",
}, nil)
if err != nil {
log.Fatal("failed to create endpoint \n", err)
}
log.Printf("\nEndpoint created - %+v\n", endpoint)
}
func pauseEndpoint(ctx context.Context, c *convoy.Client) {
endpoint, err := c.Endpoints.Pause(ctx, endpointID)
if err != nil {
log.Fatal("failed to pause endpoint \n", err)
}
log.Printf("\nEndpoint paused - %+v\n", endpoint)
}
func retrieveAllEndpoints(ctx context.Context, c *convoy.Client) {
endpoints, err := c.Endpoints.All(ctx, nil)
if err != nil {
log.Fatal("failed to retrieve endpoints \n", err)
}
log.Printf("\nEndpoints retrieved - %+v\n", endpoints)
}
func retrieveAllEvents(ctx context.Context, c *convoy.Client) {
query := &convoy.EventParams{
StartDate: time.Now().Add(time.Duration(-24) * time.Hour),
EndDate: time.Now(),
}
events, err := c.Events.All(ctx, query)
if err != nil {
log.Fatal("failed to retrieve events \n", err)
}
log.Printf("\nEvents retrieved - %+v\n", events)
}
func createPortalLink(ctx context.Context, c *convoy.Client) {
query := &convoy.CreatePortalLinkRequest{
Name: "Endpoint GO SDK",
Endpoints: nil,
OwnerID: "frain-dev",
CanManageEndpoint: true,
}
portalLink, err := c.PortalLinks.Create(ctx, query)
if err != nil {
log.Fatal("failed to create portal links \n", err)
}
log.Printf("\nPortal Link created - %+v\n", portalLink)
}