forked from WilfredAlmeida/unkey-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
117 lines (93 loc) · 3 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
package main
import (
"fmt"
"os"
"github.com/WilfredAlmeida/unkey-go/features"
"github.com/joho/godotenv"
)
func main() {
// var isKeyValid, _ = features.VerifyRequest("key_3ZZ7faUrkfv1YAhffAcnKW74")
// fmt.Println("Is key valid:", isKeyValid)
// key := features.CreateKeyRequest{
// APIId: "api_ThrZA83W5BeUE3xm8onQ45",
// Prefix: "xyz",
// ByteLength: 16,
// OwnerId: "wilfred",
// Meta: features.Meta{
// "hello": "world",
// },
// Expires: 1696951966471,
// RateLimit: features.CreateKeyRateLimit{
// Type: "fast",
// Limit: 10,
// RefillRate: 1,
// RefillInterval: 1000,
// },
// }
// authToken := "unkey_3ZeRMoXP9NFgsSxjnNtjSGLF"
// response, err := features.CreateKey(key, authToken)
// if err != nil {
// fmt.Println("Error:", err)
// return
// }
// fmt.Println("Key: ", response.Key)
// fmt.Println("Key ID: ", response.KeyId)
// response, err := features.DeleteKey("key_VNZez78oQTwyB6ggSaGtTF", authToken)
// if err != nil {
// fmt.Println("Error:", err)
// return
// }
// fmt.Println("Response: ", response)
// response, err := features.KeyVerify("key_3ZZSawUTYL1DdsgCycdp7Xdu")
// if err != nil {
// fmt.Println("Error:", err)
// return
// }
// fmt.Printf("Response.ratelimit: %+v\n", response.Ratelimit)
err := godotenv.Load("./.env")
if err != nil {
fmt.Println("Error loading .env file")
fmt.Println(err)
}
// response, err := features.APIGet(os.Getenv("API_ID"),os.Getenv("AUTH_TOKEN"))
// if err != nil {
// fmt.Println("Error:", err)
// return
// }
// fmt.Printf("Response: %+v\n", response)
// response, err := features.APIListKeys(os.Getenv("API_ID"), os.Getenv("AUTH_TOKEN"))
// if err != nil {
// fmt.Println("Error:", err)
// return
// }
// fmt.Printf("Response: %+v\n", response)
keyUpdateReq := features.KeyUpdateRequest{
KeyId: "key_5KCLmfb2HY5czAfmEFNP3h",
Name: features.NullableField[string]{Defined: false, Value: new(string)},
OwnerId: features.NullableField[string]{Defined: false, Value: nil},
Meta: features.NullableField[map[string]interface{}]{Defined: false, Value: new(map[string]interface{})},
Expires: features.NullableField[int64]{Defined: false, Value: new(int64)},
Ratelimit: features.NullableField[features.RateLimitSchema]{Defined: false, Value: nil},
Remaining: features.NullableField[int64]{Defined: false, Value: new(int64)},
}
// Set the value for Name
keyUpdateReq.Name.Defined = true
*keyUpdateReq.Name.Value = "John Doe"
// Set the value for Meta
keyUpdateReq.Meta.Defined = true
metaData := map[string]interface{}{
"field1": "value1",
"field2": 42,
}
*keyUpdateReq.Meta.Value = metaData
// Set the value for Expires
// *keyUpdateReq.Expires.Value = 123456789
// Set the value for Remaining
// *keyUpdateReq.Remaining.Value = 100
response, err := features.KeyUpdate("xyz_3ZMvC1CMJ9AwVgob6aG1NaPd",keyUpdateReq, os.Getenv("AUTH_TOKEN"))
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("Response: %+v\n", response)
}