-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (57 loc) · 2.04 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
package main
import (
"context"
"fmt"
"github.com/semmidev/fundrive"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"time"
)
func main() {
// create a db connection
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", "root", "", "localhost", "3307", "fundrive")
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
fundrive.PanicIfNeeded(err)
// create a fundrive service
fundriveService, err := fundrive.New(
fundrive.WithDB(db),
fundrive.WithServiceAccountFilePath("service-account.json"),
fundrive.WithEncryptionKey("12345678901234567890123456789012"),
)
fundrive.PanicIfNeeded(err)
err = fundriveService.OAuthService.SaveToken(context.Background(), &fundrive.SaveTokenRequest{
UserID: "user-dev-2",
Email: "user-dev-2@gmail.com",
Token: fundrive.NewOauth2Token("access-token-example", "refresh-token-example", time.Now()),
})
fundrive.PanicIfNeeded(err)
token, err := fundriveService.OAuthService.GetToken(context.Background(), &fundrive.GetTokenRequest{
UserID: "user-dev-2",
Email: "user-dev-2@gmail.com",
})
fundrive.PanicIfNeeded(err)
fmt.Println(token.AccessToken == "access-token-example")
fmt.Println(token.RefreshToken == "refresh-token-example")
err = fundriveService.OAuthService.SaveToken(context.Background(), &fundrive.SaveTokenRequest{
UserID: "user-dev-2",
Email: "user-dev-3@gmail.com",
Token: fundrive.NewOauth2Token("access-token-example-2", "refresh-token-example-2", time.Now()),
})
fundrive.PanicIfNeeded(err)
token, err = fundriveService.OAuthService.GetToken(context.Background(), &fundrive.GetTokenRequest{
UserID: "user-dev-2",
Email: "user-dev-3@gmail.com",
})
fundrive.PanicIfNeeded(err)
fmt.Println(token.AccessToken == "access-token-example-2")
fmt.Println(token.RefreshToken == "refresh-token-example-2")
ListStorageInfo, err := fundriveService.ListStorageInfo(context.Background(), &fundrive.ListStorageInfoRequest{
UserID: "user-dev-2",
})
if err != nil {
return
}
for _, storageInfo := range ListStorageInfo {
fmt.Println(storageInfo)
}
}