2017-08-03 08:13:53 -04:00
|
|
|
package main
|
|
|
|
|
2020-01-24 10:15:17 -05:00
|
|
|
import "github.com/gofrs/uuid/v3"
|
2017-08-03 08:13:53 -04:00
|
|
|
|
|
|
|
type storageMem struct {
|
|
|
|
store map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newStorageMem() storage {
|
|
|
|
return &storageMem{
|
|
|
|
store: make(map[string]string),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s storageMem) Create(secret string) (string, error) {
|
2018-10-06 14:08:21 -04:00
|
|
|
id := uuid.Must(uuid.NewV4()).String()
|
2017-08-03 08:13:53 -04:00
|
|
|
s.store[id] = secret
|
|
|
|
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s storageMem) ReadAndDestroy(id string) (string, error) {
|
|
|
|
secret, ok := s.store[id]
|
|
|
|
if !ok {
|
|
|
|
return "", errSecretNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(s.store, id)
|
|
|
|
return secret, nil
|
|
|
|
}
|