-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmetadata.go
42 lines (35 loc) · 1003 Bytes
/
metadata.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
package firestore
import (
"fmt"
"github.com/kubemq-io/kubemq-targets/types"
)
var methodsMap = map[string]string{
"documents_all": "documents_all",
"document_key": "document_key",
"delete_document_key": "delete_document_key",
"add": "add",
}
type metadata struct {
method string
key string
item string
}
func parseMetadata(meta types.Metadata) (metadata, error) {
m := metadata{}
var err error
m.method, err = meta.ParseStringMap("method", methodsMap)
if err != nil {
return metadata{}, meta.GetValidMethodTypes(methodsMap)
}
m.key, err = meta.MustParseString("collection")
if err != nil {
return metadata{}, fmt.Errorf("error on parsing collection value, %w", err)
}
if m.method == "document_key" || m.method == "delete_document_key" {
m.item, err = meta.MustParseString("item")
if err != nil {
return metadata{}, fmt.Errorf("item is required for method: %s,error on parsing item value, %w", m.method, err)
}
}
return m, nil
}