-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmetadata.go
44 lines (38 loc) · 942 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
43
44
package elastic
import (
"fmt"
"github.com/kubemq-io/kubemq-targets/types"
)
var methodsMap = map[string]string{
"get": "get",
"set": "set",
"delete": "delete",
"index.exists": "index.exists",
"index.create": "index.create",
"index.delete": "index.delete",
}
type metadata struct {
method string
index string
id 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{}, fmt.Errorf("error parsing method, %w", err)
}
m.index, err = meta.MustParseString("index")
if err != nil {
return metadata{}, fmt.Errorf("error parsing index value, %w", err)
}
switch m.method {
case "set", "get", "delete":
m.id, err = meta.MustParseString("id")
if err != nil {
return metadata{}, fmt.Errorf("error on parsing id value, %w", err)
}
}
return m, nil
}