Support multiple service tags for identifying the db
This commit is contained in:
parent
cea80c545a
commit
1a87365c7d
2
main.go
2
main.go
|
@ -24,7 +24,7 @@ func main() {
|
|||
log.Infof("genesis-index starting up")
|
||||
|
||||
var d *db.DB
|
||||
if dsn, err := ParseVcap(os.Getenv("VCAP_SERVICES"), "postgres", "uri"); err == nil {
|
||||
if dsn, err := ParseVcap(os.Getenv("VCAP_SERVICES"), []string{"postgres", "postgresql"}, "uri"); err == nil {
|
||||
d, err = Database("postgres", fmt.Sprintf("%s?sslmode=disable", dsn))
|
||||
if err != nil {
|
||||
log.Infof("Unable to connect to database: %s", err)
|
||||
|
|
11
vcap.go
11
vcap.go
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
func ParseVcap(src, tag, subkey string) (string, error) {
|
||||
func ParseVcap(src string, tags []string, subkey string) (string, error) {
|
||||
|
||||
var services map[string][]struct {
|
||||
Credentials map[string]interface{} `json:"credentials"`
|
||||
|
@ -25,10 +25,13 @@ func ParseVcap(src, tag, subkey string) (string, error) {
|
|||
for _, l := range services {
|
||||
for _, service := range l {
|
||||
tagged := false
|
||||
TAGS:
|
||||
for _, actual := range service.Tags {
|
||||
if tag == actual {
|
||||
tagged = true
|
||||
break
|
||||
for _, tag := range tags {
|
||||
if tag == actual {
|
||||
tagged = true
|
||||
break TAGS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue