-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmain.go
66 lines (55 loc) · 1.53 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
// 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"
)
func main() {
// init library
client.Init(client.InitLib{
LogLevel: client.LogLevelTrace, // LogLevelStandard / LogLevelFull / LogLevelTrace
})
// context
ctx := context.Background()
//client
dg := client.NewWithDefaults()
mgClient := api.New(dg)
// list projects
respProject, err := mgClient.ListProjects(ctx)
if err != nil {
fmt.Printf("ListProjects failed. Err: %v\n", err)
os.Exit(1)
}
var projectID string
for _, item := range respProject.Projects {
projectID = item.ProjectID
name := item.Name
fmt.Printf("ListProjects() - Name: %s, ID: %s\n", name, projectID)
break
}
// list balances
respList, err := mgClient.ListBalances(ctx, projectID)
if err != nil {
fmt.Printf("ListBalances failed. Err: %v\n", err)
os.Exit(1)
}
var amount float64
var id string
for _, item := range respList.Balances {
id = item.BalanceID
amount = item.Amount
fmt.Printf("ListBalances() - ID: %s, Amount: %f\n", id, amount)
}
// get first balance
respGet, err := mgClient.GetBalance(ctx, projectID, id)
if err != nil {
fmt.Printf("GetBalance failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("GetBalance() - ID: %s, Amount: %f\n", id, respGet.Amount)
}