@@ -25,6 +25,9 @@ const (
2525 Target baker.FieldIndex = 2
2626)
2727
28+ // And their respective names
29+ var fieldNames = []string {"timestamp" , "source" , "target" }
30+
2831var components = baker.Components {
2932 Inputs : input .All ,
3033 Filters : filter .All ,
@@ -33,13 +36,7 @@ var components = baker.Components{
3336 ShardingFuncs : shardingFuncs ,
3437 Validate : validateLogLine ,
3538 FieldByName : fieldByName ,
36- FieldName : fieldName ,
37- }
38-
39- var fields = map [string ]baker.FieldIndex {
40- "timestamp" : Timestamp ,
41- "source" : Source ,
42- "target" : Target ,
39+ FieldNames : fieldNames ,
4340}
4441
4542var shardingFuncs = map [baker.FieldIndex ]baker.ShardingFunc {
@@ -71,16 +68,12 @@ func validateLogLine(baker.Record) (bool, baker.FieldIndex) {
7168 return true , 0
7269}
7370
74- func fieldByName (key string ) (baker.FieldIndex , bool ) {
75- idx , ok := fields [key ]
76- return idx , ok
77- }
78-
79- func fieldName (idx baker.FieldIndex ) string {
80- for k , v := range fields {
81- if v == idx {
82- return k
71+ func fieldByName (name string ) (baker.FieldIndex , bool ) {
72+ for idx , n := range fieldNames {
73+ if n == name {
74+ return baker .FieldIndex (idx ), true
8375 }
8476 }
85- return ""
77+
78+ return 0 , false
8679}
0 commit comments