MCPcopy Create free account
hub / github.com/AdRoll/baker / NewExternalMatch

Function NewExternalMatch

filter/external_match.go:111–146  ·  view source on GitHub ↗
(cfg baker.FilterParams)

Source from the content-addressed store, hash-verified

109}
110
111func NewExternalMatch(cfg baker.FilterParams) (baker.Filter, error) {
112 dcfg := cfg.DecodedConfig.(*ExternalMatchConfig)
113 if err := dcfg.fillDefaults(); err != nil {
114 return nil, fmt.Errorf("ExternalMatch: invalid configuration: %v", err)
115 }
116
117 var found bool
118 if dcfg.fidx, found = cfg.FieldByName(dcfg.FieldName); !found {
119 return nil, fmt.Errorf("ExternalMatch: invalid configuration: no such field %v", dcfg.FieldName)
120 }
121
122 f := &ExternalMatch{cfg: dcfg, quit: make(chan struct{})}
123 if err := f.updateValues(); err != nil {
124 return nil, fmt.Errorf("ExternalMatch: failed loading values: %v", err)
125 }
126
127 if dcfg.RefreshEvery != 0 {
128 go func() {
129 tick := time.NewTicker(dcfg.RefreshEvery)
130 for {
131 select {
132 // Terminate this goroutine. For now, this is only useful in
133 // tests, to avoid race conditions at test cleanup.
134 case <-f.quit:
135 return
136 case <-tick.C:
137 if err := f.updateValues(); err != nil {
138 log.WithError(err).Error("ExternalMatch: failed reloading values")
139 }
140 }
141 }
142 }()
143 }
144
145 return f, nil
146}
147
148// valuesFromCSV reads the CSV-formatted reader r and returns the set of values
149// in the 0-based column index..

Callers 2

testExternalMatchFilesFunction · 0.85

Calls 3

updateValuesMethod · 0.95
fillDefaultsMethod · 0.45
ErrorMethod · 0.45

Tested by 2

testExternalMatchFilesFunction · 0.68