parseConnectionString parses the given connection string and returns a ConnectionDetails.
(connStr string)
| 111 | |
| 112 | // parseConnectionString parses the given connection string and returns a ConnectionDetails. |
| 113 | func parseConnectionString(connStr string) (*ConnectionDetails, error) { |
| 114 | details := &ConnectionDetails{} |
| 115 | pairs := connectionRegex.FindAllStringSubmatch(connStr, -1) |
| 116 | |
| 117 | if pairs == nil { |
| 118 | return nil, fmt.Errorf("no valid key-value pairs found in connection string") |
| 119 | } |
| 120 | |
| 121 | for _, pair := range pairs { |
| 122 | key := pair[1] |
| 123 | value := pair[2] |
| 124 | switch key { |
| 125 | case "dbname": |
| 126 | details.DBName = value |
| 127 | case "host": |
| 128 | details.Host = value |
| 129 | case "port": |
| 130 | details.Port = value |
| 131 | case "user": |
| 132 | details.User = value |
| 133 | case "password": |
| 134 | details.Password = value |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Handle default values |
| 139 | if details.DBName == "" { |
| 140 | details.DBName = "postgres" |
| 141 | } |
| 142 | if details.Port == "" { |
| 143 | details.Port = "5432" |
| 144 | } |
| 145 | |
| 146 | return details, nil |
| 147 | } |
| 148 | |
| 149 | // ToConnectionInfo Format SubscriptionConfig into a ConnectionInfo |
| 150 | func (config *SubscriptionConfig) ToConnectionInfo() string { |
no outgoing calls
no test coverage detected