Build a Connection String programmatically from connstring.ConnString

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Won't Do
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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:

      And there are more in Enterprise and Atlas Operators as well.

            Assignee:
            Matt Dale
            Reporter:
            Rodrigo Valin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: