database/elasticsearch/elasticsearch.go
func (db *Database) getURL() {

	// If not set use defaults
	if len(strings.TrimSpace(db.Index)) == 0 {
		db.Index = defaultIndex
	}
	if len(strings.TrimSpace(db.Type)) == 0 {
		db.Type = defaultType
	}
	if len(strings.TrimSpace(db.Host)) == 0 {
		db.Host = defaultHost
	}
	if len(strings.TrimSpace(db.Port)) == 0 {
		db.Port = defaultPort
	}

	// If user set URL param use it
	if len(strings.TrimSpace(db.URL)) == 0 {
		db.URL = defaultURL
	}

	// If running in docker use `elasticsearch`
	if _, exists := os.LookupEnv("MALICE_IN_DOCKER"); exists {
		log.WithField("elasticsearch", db.URL).Debug("running malice in docker")
		// TODO: change MALICE_ELASTICSEARCH to MALICE_ELASTICSEARCH_HOST
		db.URL = utils.Getopt("MALICE_ELASTICSEARCH_URL", fmt.Sprintf("http://%s:%s", "elasticsearch", db.Port))
		return
	}

	db.URL = utils.Getopts(db.URL, "MALICE_ELASTICSEARCH_URL", fmt.Sprintf("http://%s:%s", db.Host, db.Port))
}
func (db *Database) getURL() {

	// If not set use defaults
	if len(strings.TrimSpace(db.Index)) == 0 {
		db.Index = defaultIndex
	}
	if len(strings.TrimSpace(db.Type)) == 0 {
		db.Type = defaultType
	}
	if len(strings.TrimSpace(db.Host)) == 0 {
		db.Host = defaultHost
	}
	if len(strings.TrimSpace(db.Port)) == 0 {
		db.Port = defaultPort
	}

	// If user set URL param use it
	if len(strings.TrimSpace(db.URL)) == 0 {
		db.URL = defaultURL
	}

	// If running in docker use `elasticsearch`
	if _, exists := os.LookupEnv("MALICE_IN_DOCKER"); exists {
		log.WithField("elasticsearch", db.URL).Debug("running malice in docker")
		// TODO: change MALICE_ELASTICSEARCH to MALICE_ELASTICSEARCH_HOST
		db.URL = utils.Getopt("MALICE_ELASTICSEARCH_URL", fmt.Sprintf("http://%s:%s", "elasticsearch", db.Port))
		return
	}

	db.URL = utils.Getopts(db.URL, "MALICE_ELASTICSEARCH_URL", fmt.Sprintf("http://%s:%s", db.Host, db.Port))
}
// getURL with the following order of precedence
// - user input (cli)
// - user ENV
// - sane defaults