forked from compose/transporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrename.go
More file actions
34 lines (29 loc) · 635 Bytes
/
Copy pathrename.go
File metadata and controls
34 lines (29 loc) · 635 Bytes
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
package rename
import (
"github.com/compose/transporter/function"
"github.com/compose/transporter/message"
)
var (
_ function.Function = &rename{}
)
func init() {
function.Add(
"rename",
func() function.Function {
return &rename{}
},
)
}
// rename swaps out the field names based on the provided config
type rename struct {
SwapMap map[string]string `json:"field_map"`
}
func (r *rename) Apply(msg message.Msg) (message.Msg, error) {
for oldName, newName := range r.SwapMap {
if val, ok := msg.Data().AsMap()[oldName]; ok {
msg.Data().Set(newName, val)
msg.Data().Delete(oldName)
}
}
return msg, nil
}