github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/sugar/dsn.go (about)

     1  package sugar
     2  
     3  import "net/url"
     4  
     5  // Usage of this package
     6  //
     7  // db, err := ydb.Open(ctx,
     8  //   sugar.DSN("endpoint", "database", false),
     9  // )
    10  
    11  // DSN makes connection string (data source name) by endpoint, database and secure
    12  func DSN(endpoint, database string, secure bool) (s string) {
    13  	qp := url.Values{}
    14  
    15  	dsn := url.URL{
    16  		Scheme:   "grpc",
    17  		Host:     endpoint,
    18  		Path:     database,
    19  		RawQuery: qp.Encode(),
    20  	}
    21  
    22  	if secure {
    23  		dsn.Scheme = "grpcs"
    24  	}
    25  
    26  	return dsn.String()
    27  }