-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package pipeline | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
|
||
"github.com/ozontech/file.d/cfg" | ||
) | ||
|
||
type MetaData map[string]string | ||
|
||
type MetaRegistry struct { | ||
templates cfg.MetaTemplates | ||
Check failure on line 13 in pipeline/metadata_registry.go
|
||
values map[string]interface{} | ||
} | ||
|
||
func NewMetaRegistry(templates cfg.MetaTemplates) *MetaRegistry { | ||
Check failure on line 17 in pipeline/metadata_registry.go
|
||
meta := MetaRegistry{ | ||
templates: templates, | ||
values: make(map[string]interface{}), | ||
} | ||
return &meta | ||
} | ||
|
||
func (m *MetaRegistry) Set(k string, v interface{}) { | ||
m.values[k] = v | ||
} | ||
|
||
func (m *MetaRegistry) GetMeta() (MetaData, error) { | ||
meta := MetaData{} | ||
for k, v := range m.templates { | ||
tmpl := template.Must(template.New("").Parse(v)) | ||
var tplOutput bytes.Buffer | ||
err := tmpl.Execute(&tplOutput, m.values) | ||
if err != nil { | ||
return meta, err | ||
} else { | ||
meta[k] = tplOutput.String() | ||
} | ||
} | ||
return meta, nil | ||
} |