-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
28 lines (24 loc) · 917 Bytes
/
config.go
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
package mongoes
import (
"github.com/pkg/errors"
)
func GetConfig(configPath string, esOptions *ESOptions, mgoOptions *MgoOptions) error {
if len(configPath) == 0 {
return errors.New("Please provide config file")
}
// Read the json config
var config map[string]interface{}
err := ReadJSONFromFile(configPath, &config)
if err != nil {
return errors.Wrap(err, "Unable to parse config file")
}
mgoOptions.MgoDbname = GetStringJSON(config, "mongodb.database")
mgoOptions.MgoCollname = GetStringJSON(config, "mongodb.collection")
mgoOptions.MgoURI = GetStringJSON(config, "mongodb.uri")
mgoOptions.MgoQuery = GetObjectJSON(config, "query")
esOptions.EsIndex = GetStringJSON(config, "elasticsearch.index")
esOptions.EsType = GetStringJSON(config, "elasticsearch.type")
esOptions.EsURI = GetStringJSON(config, "elasticsearch.uri")
esOptions.EsMapping = GetObjectJSON(config, "mapping")
return nil
}