-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.go
91 lines (75 loc) · 2.14 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
// Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT
package main
import (
"context"
"fmt"
"os"
api "github.com/deepgram/deepgram-go-sdk/pkg/api/manage/v1"
client "github.com/deepgram/deepgram-go-sdk/pkg/client/manage"
)
const (
TestAccountName = "[email protected]"
)
func main() {
// init library
client.InitWithDefault()
// context
ctx := context.Background()
//client
dg := client.NewWithDefaults()
mgClient := api.New(dg)
// list projects
respList, err := mgClient.ListProjects(ctx)
if err != nil {
fmt.Printf("ListProjects failed. Err: %v\n", err)
os.Exit(1)
}
var projectID string
for _, item := range respList.Projects {
projectID = item.ProjectID
name := item.Name
fmt.Printf("ListProjects() - Name: %s, ID: %s\n", name, projectID)
break
}
// list members
respGet, err := mgClient.ListMembers(ctx, projectID)
if err != nil {
fmt.Printf("ListMembers failed. Err: %v\n", err)
os.Exit(1)
}
var delmemberID string
for _, item := range respGet.Members {
memberID := item.MemberID
email := item.Email
fmt.Printf("ListMembers() - ID: %s, Scope: %s\n", memberID, email)
if email == TestAccountName {
delmemberID = memberID
}
}
if delmemberID == "" {
fmt.Printf("This example requires a member who already email is %s.\n", TestAccountName)
fmt.Printf("This is required to exercise the RemoveMember function.\n")
fmt.Printf("In the absence of this, this example will exit early.\n")
os.Exit(0)
}
// remove member
respMessage, err := mgClient.RemoveMember(ctx, projectID, delmemberID)
if err != nil {
fmt.Printf("RemoveMember failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("RemoveMember() - Name: %s\n", respMessage.Message)
// list members
respGet, err = mgClient.ListMembers(ctx, projectID)
if err != nil {
fmt.Printf("ListMembers failed. Err: %v\n", err)
os.Exit(1)
}
for _, item := range respGet.Members {
memberID := item.MemberID
email := item.Email
fmt.Printf("ListMembers() - ID: %s, Scope: %s\n", memberID, email)
}
}