-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodeSamples.yaml
89 lines (89 loc) · 13.7 KB
/
codeSamples.yaml
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
overlay: 1.0.0
info:
title: CodeSamples overlay for go target
version: 0.0.0
actions:
- target: $["paths"]["/v1/keys.verifyKey"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "verifyKey"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := components.V1KeysVerifyKeyRequest{\n APIID: unkeygo.String(\"api_1234\"),\n Key: \"sk_1234\",\n Authorization: &components.Authorization{\n Permissions: &components.Permissions{},\n },\n }\n \n ctx := context.Background()\n res, err := s.VerifyKey(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/keys.deleteKey"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "deleteKey"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.DeleteKeyRequestBody{\n KeyID: \"key_1234\",\n }\n \n ctx := context.Background()\n res, err := s.DeleteKey(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/keys.updateRemaining"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "updateRemaining"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.UpdateRemainingRequestBody{\n KeyID: \"key_123\",\n Op: operations.OpSet,\n Value: unkeygo.Int64(1),\n }\n \n ctx := context.Background()\n res, err := s.UpdateRemaining(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/apis.getApi"]["get"]
update:
"x-codeSamples":
- "lang": "go"
"label": "getApi"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.GetAPIRequest{\n APIID: \"api_1234\",\n }\n \n ctx := context.Background()\n res, err := s.GetAPI(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/ratelimits.limit"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "limit"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.LimitRequestBody{\n Namespace: unkeygo.String(\"email.outbound\"),\n Identifier: \"user_123\",\n Limit: 10,\n Duration: 60000,\n Cost: unkeygo.Int64(2),\n Resources: []operations.Resources{\n operations.Resources{\n Type: \"project\",\n ID: \"p_123\",\n Name: unkeygo.String(\"dub\"),\n },\n },\n }\n \n ctx := context.Background()\n res, err := s.Limit(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/apis.createApi"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "createApi"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.CreateAPIRequestBody{\n Name: \"my-api\",\n }\n \n ctx := context.Background()\n res, err := s.CreateAPI(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/liveness"]["get"]
update:
"x-codeSamples":
- "lang": "go"
"label": "liveness"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n\n \n ctx := context.Background()\n res, err := s.V1Liveness(ctx)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/keys.getKey"]["get"]
update:
"x-codeSamples":
- "lang": "go"
"label": "getKey"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.GetKeyRequest{\n KeyID: \"key_1234\",\n }\n \n ctx := context.Background()\n res, err := s.GetKey(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/keys.createKey"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "createKey"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.CreateKeyRequestBody{\n APIID: \"api_123\",\n Name: unkeygo.String(\"my key\"),\n OwnerID: unkeygo.String(\"team_123\"),\n Meta: map[string]any{\n \"billingTier\": \"PRO\",\n \"trialEnds\": \"2023-06-16T17:16:37.161Z\",\n },\n Roles: []string{\n \"admin\",\n \"finance\",\n },\n Expires: unkeygo.Int64(1623869797161),\n Remaining: unkeygo.Int64(1000),\n Refill: &operations.Refill{\n Interval: operations.IntervalDaily,\n Amount: 100,\n },\n Ratelimit: &operations.Ratelimit{\n Type: operations.TypeFast.ToPointer(),\n Limit: 10,\n RefillRate: 1,\n RefillInterval: 60,\n },\n Enabled: unkeygo.Bool(false),\n }\n \n ctx := context.Background()\n res, err := s.CreateKey(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/keys.updateKey"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "updateKey"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.UpdateKeyRequestBody{\n KeyID: \"key_123\",\n Name: unkeygo.String(\"Customer X\"),\n OwnerID: unkeygo.String(\"user_123\"),\n Meta: map[string]any{\n \"roles\": []any{\n \"admin\",\n \"user\",\n },\n \"stripeCustomerId\": \"cus_1234\",\n },\n Expires: unkeygo.Float64(0),\n Ratelimit: &operations.UpdateKeyRatelimit{\n Type: operations.UpdateKeyTypeFast,\n Limit: 10,\n RefillRate: 1,\n RefillInterval: 60,\n },\n Remaining: unkeygo.Float64(1000),\n Refill: &operations.UpdateKeyRefill{\n Interval: operations.UpdateKeyIntervalDaily,\n Amount: 100,\n },\n Enabled: unkeygo.Bool(true),\n }\n \n ctx := context.Background()\n res, err := s.UpdateKey(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/keys.getVerifications"]["get"]
update:
"x-codeSamples":
- "lang": "go"
"label": "getVerifications"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.GetVerificationsRequest{\n KeyID: unkeygo.String(\"key_1234\"),\n OwnerID: unkeygo.String(\"chronark\"),\n Start: unkeygo.Int64(1620000000000),\n End: unkeygo.Int64(1620000000000),\n Granularity: operations.GranularityDay.ToPointer(),\n }\n \n ctx := context.Background()\n res, err := s.GetVerifications(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/apis.deleteApi"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "deleteApi"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.DeleteAPIRequestBody{\n APIID: \"api_1234\",\n }\n \n ctx := context.Background()\n res, err := s.DeleteAPI(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/migrations.createKeys"]["post"]
update:
"x-codeSamples":
- "lang": "go"
"label": "createKeys"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := []operations.RequestBody{\n operations.RequestBody{\n APIID: \"api_123\",\n Name: unkeygo.String(\"my key\"),\n Hash: operations.Hash{\n Value: \"<value>\",\n Variant: operations.VariantSha256Base64,\n },\n Start: unkeygo.String(\"unkey_32kq\"),\n OwnerID: unkeygo.String(\"team_123\"),\n Meta: map[string]any{\n \"billingTier\": \"PRO\",\n \"trialEnds\": \"2023-06-16T17:16:37.161Z\",\n },\n Roles: []string{\n \"admin\",\n \"finance\",\n },\n Expires: unkeygo.Int64(1623869797161),\n Remaining: unkeygo.Int64(1000),\n Refill: &operations.V1MigrationsCreateKeysRefill{\n Interval: operations.V1MigrationsCreateKeysIntervalDaily,\n Amount: 100,\n },\n Ratelimit: &operations.V1MigrationsCreateKeysRatelimit{\n Type: operations.V1MigrationsCreateKeysTypeFast.ToPointer(),\n Limit: 10,\n RefillRate: 1,\n RefillInterval: 60,\n },\n Enabled: unkeygo.Bool(false),\n },\n }\n \n ctx := context.Background()\n res, err := s.V1MigrationsCreateKeys(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"
- target: $["paths"]["/v1/apis.listKeys"]["get"]
update:
"x-codeSamples":
- "lang": "go"
"label": "listKeys"
"source": "package main\n\nimport(\n\t\"github.com/unkeyed/unkey-go/models/components\"\n\tunkeygo \"github.com/unkeyed/unkey-go\"\n\t\"github.com/unkeyed/unkey-go/models/operations\"\n\t\"context\"\n\t\"log\"\n)\n\nfunc main() {\n s := unkeygo.New(\n unkeygo.WithSecurity(\"<YOUR_BEARER_TOKEN_HERE>\"),\n )\n\n request := operations.ListKeysRequest{\n APIID: \"api_1234\",\n Limit: unkeygo.Int64(100),\n }\n \n ctx := context.Background()\n res, err := s.ListKeys(ctx, request)\n if err != nil {\n log.Fatal(err)\n }\n if res != nil {\n // handle response\n }\n}"