Skip to content

Commit 3a0670b

Browse files
committed
fix: minor fixes
1 parent 401ed8e commit 3a0670b

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

main.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,19 @@ func main() {
171171
// ES client instantiation
172172
// ES v7 and v6 clients
173173
util.NewClient()
174-
// map of specific plugins in a sequence
175-
sequencedPlugins := map[string]string{
176-
"rules.so": "", // path
177-
"function.so": "", // path
178-
"querytranslate.so": "", // path
179-
"analytics.so": "", // path
180-
}
174+
// map of specific plugins
175+
sequencedPlugins := []string{"rules.so", "functions.so", "querytranslate.so", "analytics.so"}
176+
sequencedPluginsByPath := make(map[string]string)
177+
181178
var elasticSearchPath string
182179
elasticSearchMiddleware := make([]middleware.Middleware, 0)
183180
err := filepath.Walk(pluginDir, func(path string, info os.FileInfo, err error) error {
184181
if err != nil {
185182
return err
186183
}
187184
if !info.IsDir() && filepath.Ext(info.Name()) == ".so" && info.Name() != "elasticsearch.so" {
188-
_, isExist := sequencedPlugins[info.Name()]
189-
if isExist {
190-
sequencedPlugins[info.Name()] = path
185+
if util.IsExists(info.Name(), sequencedPlugins) {
186+
sequencedPluginsByPath[info.Name()] = path
191187
} else {
192188
mw, err1 := LoadPluginFromFile(router, path)
193189
if err1 != nil {
@@ -202,13 +198,14 @@ func main() {
202198
return nil
203199
})
204200
// load plugins in a sequence
205-
for key, path := range sequencedPlugins {
201+
for _, pluginName := range sequencedPlugins {
202+
path, _ := sequencedPluginsByPath[pluginName]
206203
if path != "" {
207204
mw, err := LoadPluginFromFile(router, path)
208205
if err != nil {
209206
log.Fatal("error loading plugins: ", err)
210207
}
211-
log.Println("==================PLUGIN REGISTERED================", key)
208+
log.Println("==================PLUGIN REGISTERED================", pluginName)
212209
elasticSearchMiddleware = append(elasticSearchMiddleware, mw...)
213210
}
214211
}

util/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ func IndicesFromRequest(r *http.Request) []string {
158158
return indices
159159
}
160160

161+
// IsExists searches for an element in an array
162+
func IsExists(a string, list []string) bool {
163+
for _, b := range list {
164+
if b == a {
165+
return true
166+
}
167+
}
168+
return false
169+
}
170+
161171
// CountComponents returns the numbers of "/" and "vars" present in the route.
162172
func CountComponents(route string) (int, int) {
163173
pattern := `^{.*}$`

0 commit comments

Comments
 (0)