MCPcopy Index your code
hub / github.com/ddev/ddev / ParseURL

Function ParseURL

pkg/nodeps/utils.go:178–207  ·  view source on GitHub ↗

ParseURL parses a URL and returns the scheme, URL without port, and port If the URL doesn't have an explicit port, returns the default port for the scheme

(rawURL string)

Source from the content-addressed store, hash-verified

176// ParseURL parses a URL and returns the scheme, URL without port, and port
177// If the URL doesn't have an explicit port, returns the default port for the scheme
178func ParseURL(rawURL string) (scheme string, urlWithoutPort string, port string) {
179 if rawURL == "" {
180 return "", "", ""
181 }
182
183 parsedURL, err := url.Parse(rawURL)
184 if err != nil {
185 return "", "", ""
186 }
187
188 // Check if the URL has a valid scheme
189 scheme = parsedURL.Scheme
190 if scheme != "http" && scheme != "https" {
191 return "", "", ""
192 }
193
194 // Get URL without port
195 urlWithoutPort = fmt.Sprintf("%s://%s", parsedURL.Scheme, parsedURL.Hostname())
196
197 // Get port
198 if parsedURL.Port() != "" {
199 port = parsedURL.Port()
200 } else if parsedURL.Scheme == "https" {
201 port = "443"
202 } else {
203 port = "80"
204 }
205
206 return scheme, urlWithoutPort, port
207}
208
209// IsEnvTrue returns true if the given environment variable
210// has a value accepted by strconv.ParseBool.

Callers 3

TestEnvironmentVariablesFunction · 0.92
DockerEnvMethod · 0.92
TestParseURLFunction · 0.92

Calls

no outgoing calls

Tested by 2

TestEnvironmentVariablesFunction · 0.74
TestParseURLFunction · 0.74