Skip to content

Commit

Permalink
add-host-prefix-option
Browse files Browse the repository at this point in the history
Allow to configure the host prefix. This allows to use mongodb and mongodb-srv
  • Loading branch information
joda01 authored Oct 15, 2024
1 parent 0cb4846 commit 7b590a2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion backends/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

type Mongo struct {
HostPrefix string
Host string
Port string
Username string
Expand Down Expand Up @@ -51,6 +52,7 @@ func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.Has
log.SetLevel(logLevel)

var m = Mongo{
HostPrefix: "mongodb",
Host: "localhost",
Port: "27017",
Username: "",
Expand All @@ -68,6 +70,10 @@ func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.Has
m.disableSuperuser = true
}

if prefix, ok := authOpts["mongo_host_prefix"]; ok {
m.HostPrefix = prefix
}

if mongoHost, ok := authOpts["mongo_host"]; ok {
m.Host = mongoHost
}
Expand Down Expand Up @@ -108,7 +114,7 @@ func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.Has
m.insecureSkipVerify = true
}

addr := fmt.Sprintf("mongodb://%s:%s", m.Host, m.Port)
addr := fmt.Sprintf("%s://%s:%s", m.HostPrefix, m.Host, m.Port)

to := 60 * time.Second

Expand Down

0 comments on commit 7b590a2

Please sign in to comment.