Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2226

Build a Connection String programmatically from connstring.ConnString

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Won't Do
    • Icon: Unknown 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:

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

      Attachments

        Activity

          People

            matt.dale@mongodb.com Matt Dale
            rodrigo.valin@mongodb.com Rodrigo Valin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: