getEndpointURL - construct a new endpoint.
(endpoint string, secure bool)
| 107 | |
| 108 | // getEndpointURL - construct a new endpoint. |
| 109 | func getEndpointURL(endpoint string, secure bool) (*url.URL, error) { |
| 110 | // If secure is false, use 'http' scheme. |
| 111 | scheme := "https" |
| 112 | if !secure { |
| 113 | scheme = "http" |
| 114 | } |
| 115 | |
| 116 | // Construct a secured endpoint URL. |
| 117 | endpointURLStr := scheme + "://" + endpoint |
| 118 | endpointURL, err := url.Parse(endpointURLStr) |
| 119 | if err != nil { |
| 120 | return nil, err |
| 121 | } |
| 122 | |
| 123 | // Validate incoming endpoint URL. |
| 124 | if err := isValidEndpointURL(*endpointURL); err != nil { |
| 125 | return nil, err |
| 126 | } |
| 127 | return endpointURL, nil |
| 128 | } |
| 129 | |
| 130 | // closeResponse close non nil response with any response Body. |
| 131 | // convenient wrapper to drain any remaining data on response body. |