-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
71 lines (59 loc) · 2.05 KB
/
client.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
// AUTO-GENERATED CODE - DO NOT EDIT
// See instructions under /codegen/README.md
// GENERATED ON 2023-07-31 09:25:17
// Package _glacier provides AWS client management functions for the glacier
// AWS service.
//
// The Client() is a wrapper on glacier.NewFromConfig(), which creates & caches
// the client.
//
// The Delete() clears the cached client.
//
package _glacier
import (
"sync"
"github.com/TouchBistro/aws-ccp-go/providers"
"github.com/aws/aws-sdk-go-v2/service/glacier"
)
var cmap sync.Map
// Client builds or returns the singleton glacier client for the supplied provider
// If functional options are supplied, they are passed as-is to the underlying NewFromConfig(...)
// for the corresponding client
func Client(provider providers.CredsProvider, optFns ...func(*glacier.Options)) (*glacier.Client, error) {
if provider == nil {
return nil, providers.ErrNilProvider
}
if _, ok := cmap.Load(provider.Key()); !ok {
client := glacier.NewFromConfig(provider.Config(), optFns...)
cmap.Store(provider.Key(), client)
}
client, _ := cmap.Load(provider.Key())
return client.(*glacier.Client), nil
}
// Must wraps the _glacier.Client( ) function & panics if a non-nil error is returned.
func Must(provider providers.CredsProvider, optFns ...func(*glacier.Options)) *glacier.Client {
client, err := Client(provider, optFns...)
if err != nil {
panic(err)
}
return client
}
// Delete removes the cached glacier client for the supplied provider; This foreces the subsequent
// calls to Client() for the same provider to recreate & return a new instnce.
func Delete(provider providers.CredsProvider) error {
if provider == nil {
return providers.ErrNilProvider
}
if _, ok := cmap.Load(provider.Key()); ok {
cmap.Delete(provider.Key())
}
return nil
}
// Refresh discards the cached glacier client if it exists, builds & returns a new singleton instance
func Refresh(provider providers.CredsProvider, optFns ...func(*glacier.Options)) (*glacier.Client, error) {
err := Delete(provider)
if err != nil {
return nil, err
}
return Client(provider, optFns...)
}