MCPcopy Index your code
hub / github.com/bytebase/bytebase / NormalizeExternalURL

Function NormalizeExternalURL

backend/common/util.go:122–146  ·  view source on GitHub ↗

NormalizeExternalURL will format the external url.

(url string)

Source from the content-addressed store, hash-verified

120
121// NormalizeExternalURL will format the external url.
122func NormalizeExternalURL(url string) (string, error) {
123 r := strings.TrimSpace(url)
124 r = strings.TrimSuffix(r, "/")
125 if !HasPrefixes(r, "http://", "https://") {
126 return "", errors.Errorf("%s must start with http:// or https://", url)
127 }
128 parts := strings.Split(r, ":")
129 if len(parts) > 3 {
130 return "", errors.Errorf("%s malformed", url)
131 }
132 if len(parts) == 3 {
133 port, err := strconv.Atoi(parts[2])
134 if err != nil {
135 return "", errors.Errorf("%s has non integer port", url)
136 }
137 // The external URL is used as the redirectURL in the get token process of OAuth, and the
138 // RedirectURL needs to be consistent with the RedirectURL in the get code process.
139 // The frontend gets it through window.location.origin in the get code
140 // process, so port 80/443 need to be cropped.
141 if port == 80 || port == 443 {
142 r = strings.Join(parts[0:2], ":")
143 }
144 }
145 return r, nil
146}
147
148// ValidatePhone validates the phone number.
149func ValidatePhone(phone string) error {

Callers 3

UpdateSettingMethod · 0.92
startFunction · 0.92
TestNormalizeExternalURLFunction · 0.85

Calls 3

HasPrefixesFunction · 0.85
ErrorfMethod · 0.80
JoinMethod · 0.80

Tested by 1

TestNormalizeExternalURLFunction · 0.68