Details
-
New Feature
-
Resolution: Won't Do
-
Unknown
-
None
-
None
-
None
-
None
Description
We would like to be able to programmatically create a Connection String from a struct like connstring.ConnString.
Ideally we could use a builder pattern in order to do:
builder := connstring.Builder().
|
SetScheme(MongoDBSRV).
|
SetHosts([]string{"host:27017"}).
|
SetTLS(true).
|
SetUsername("user")
|
|
|
assert.Equal(t, "mongodb+srv://user@host:27017?ssl=true", builder.Build().ToURI())
|
In the previous example, builder.Build() would return a concrete ConnString that can be called with ToURI() to obtain a valid connection string.
The builder part is just an example, a ConnString object with a function like ToURI() or ToString() is what we really need. How that ConnString is constructed can be done on our side.
Our particular use case (Kubernetes Operators) is that we create Connection Strings in Secret Kubernetes objects that users could mount into their client applications. Currently we do this with a series of error-prone fmt.Sprintf() function calls.
We have two examples in Community Operator using fmt.Sprintf() to build connection strings:
- https://github.com/mongodb/mongodb-kubernetes-operator/blob/cd411b999c4d737644b5e5f9ee21ccaa0498c901/api/v1/mongodbcommunity_types.go#L505
- https://github.com/mongodb/mongodb-kubernetes-operator/blob/cd411b999c4d737644b5e5f9ee21ccaa0498c901/api/v1/mongodbcommunity_types.go#L510
And there are more in Enterprise and Atlas Operators as well.
Attachments
Issue Links
- is related to
-
GODRIVER-428 Format ConnString struct back to string
-
- Closed
-