-
Notifications
You must be signed in to change notification settings - Fork 1
/
storage.go
46 lines (39 loc) · 1.02 KB
/
storage.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
package main
import (
"fmt"
uuid "github.com/nu7hatch/gouuid"
"time"
)
type Entity struct {
Id string `json:"id"`
Created time.Time `json:"created"`
Payload interface{} `json:"payload"`
}
func createEntity(payload interface{}) (Entity, error) {
uuidV4, err := uuid.NewV4()
if err != nil {
return Entity{}, fmt.Errorf("could not create new ID for entity: %w", err)
}
return Entity{
Id: uuidV4.String(),
Created: time.Now(),
Payload: payload,
}, nil
}
type Storage interface {
Add(serviceName string, payload interface{}) (Entity, error)
List(serviceName string) ([]Entity, error)
Get(serviceName, id string) (Entity, error)
Delete(serviceName, id string) error
}
func CreateStorageByType(storageType string, serviceNames []string) (Storage, error) {
switch storageType {
case "mem":
return CreateMemStorage(serviceNames), nil
case "s3":
return CreateS3Storage(serviceNames)
case "firestore":
return CreateFirestoreStorage()
}
return nil, fmt.Errorf("unknown storage type %q", storageType)
}