Example #1
0
func (config Config) Sqlite3() (Sqlite3, error) {
	var sqlite Sqlite3

	if err := json.Unmarshal(config.Components["sqlite3"], &sqlite); err != nil {
		logs.Warning("%s: %s", err.Error(), "missing or wrong 'sqlite3' configuration, ignoring")
	}

	if sqlite.Path == "" {
		logs.Warning("missing sqlite3 'path' configuration, assuming default value: 'db.sqlite'")
		sqlite.Path = "db.sqlite"
	}

	return sqlite, nil
}
Example #2
0
func (config Config) Dialect() (string, error) {
	client, ok := config.Settings["database"].(string)
	if ok && client != "" {
		return client, nil
	}
	logs.Warning("missing 'database' configuration, assuming default value: 'sqlite3'")
	return "sqlite3", nil
}
Example #3
0
func (config Config) CustomServer(name, defaultHost string, defaultPort int) (Server, error) {
	var server Server

	if err := json.Unmarshal(config.Components[name], &server); err != nil {
		logs.Warning("%s: %s", err.Error(), "missing or wrong '"+name+"' configuration, ignoring")
	}

	if server.Host == "" {
		server.Host = defaultHost
		logs.Warning("missing " + name + " 'host' configuration, assuming default value: '" + defaultHost + "'")
	}

	if server.Port == 0 {
		server.Port = defaultPort
		logs.Warning("missing "+name+" 'port' configuration, assuming default value: %d", defaultPort)
	}

	return server, nil
}
Example #4
0
func (config Config) Elasticsearch() (Elasticsearch, error) {
	var elastic Elasticsearch

	err := json.Unmarshal(config.Components["elasticsearch"], &elastic)
	if err != nil {
		logs.Warning("%s: %s", err.Error(), "missing or wrong 'elasticsearch' configuration, ignoring")
	}

	if elastic.Host == "" {
		elastic.Host = "elasticsearch"
		logs.Warning("missing elasticsearch 'host' configuration, assuming default value: 'elasticsearch'")
	}

	if elastic.Port == 0 {
		elastic.Port = 9200
		logs.Warning("missing elasticsearch 'port' configuration, assuming default value: 9200")
	}

	return elastic, nil
}
Example #5
0
func (config Config) Postgres() (Postgres, error) {
	var postgres Postgres

	err := json.Unmarshal(config.Components["postgres"], &postgres)
	if err != nil {
		logs.Warning("%s: %s", err.Error(), "missing or wrong 'postgres' configuration, ignoring")
	}

	if postgres.DB == "" {
		postgres.DB = "postgres"
		logs.Warning("missing postgres 'db' configuration, assuming default value: 'postgres'")
	}
	if postgres.Host == "" {
		postgres.Host = "postgres"
		logs.Warning("missing postgres 'host' configuration, assuming default value: 'postgres'")
	}
	if postgres.Port == 0 {
		postgres.Port = 5432
		logs.Warning("missing postgres 'port' configuration, assuming default value: 5432")
	}
	if postgres.User == "" {
		postgres.User = "******"
		logs.Warning("missing postgres 'user' configuration, assuming default value: 'postgres'")
	}

	if postgres.Password == "" {
		logs.Warning("missing postgres 'password' configuration, assuming no password is needed")
	}

	return postgres, nil
}