Use new sink instances to allow multiple of same sink type

This commit is contained in:
Thomas Roehl
2022-02-22 16:15:25 +01:00
parent 9cfbe10247
commit 18a226183c
9 changed files with 65 additions and 26 deletions

View File

@@ -53,8 +53,8 @@ func (s *NatsSink) connect() error {
return nil
}
func (s *NatsSink) Init(config json.RawMessage) error {
s.name = "NatsSink"
func (s *NatsSink) Init(name string, config json.RawMessage) error {
s.name = fmt.Sprintf("NatsSink(%s)", name)
if len(config) > 0 {
err := json.Unmarshal(config, &s.config)
if err != nil {
@@ -105,3 +105,9 @@ func (s *NatsSink) Close() {
s.client.Close()
}
}
func NewNatsSink(name string, config json.RawMessage) (Sink, error) {
s := new(NatsSink)
s.Init(name, config)
return s, nil
}