/**
 * Validates and processes the given Url
 * @param    url     The given Url to process
 * @return   Pre-processed Url as string
 */
Validates and processes the given Url
@param    url     The given Url to process
@return   Pre-processed Url as string
/ ** * Validates and processes the given Url * @param url The given Url to process * @return Pre - processed Url as string * /
func CleanUrl(url string) (string, error) {
    if(len(url) < 1) {
        return "", errors.New("Invalid Url.")
    }
    isMatch, err := regexp.MatchString("^(https?://[^/]+)", url)
    if (err != nil || !isMatch) {
        return "", errors.New("Invalid Url format.")
    }
    var query,parameters string
    protocol := url[0:7]
    if strings.Contains(url,"?"){
    query = url[7:strings.Index(url,"?")]
    parameters = url[strings.Index(url,"?"):len(url)]
    } else {
        query = url[7:len(url)]
        parameters =""
    }
    re := regexp.MustCompile("//+")
    query = re.ReplaceAllString(query, "/")
    url = protocol + query + parameters
    return url, nil
}
func CleanUrl ( url string ) ( string , error ) { if ( len ( url ) < 1 ) { return " " , errors . New ( " " ) } isMatch , err := regexp . MatchString ( " " , url ) if ( err != nil || ! isMatch ) { return " " , errors . New ( " " ) } var query , parameters string protocol := url [ 0 : 7 ] if strings . Contains ( url , " " ) { query = url [ 7 : strings . Index ( url , " " ) ] parameters = url [ strings . Index ( url , " " ) : len ( url ) ] } else { query = url [ 7 : len ( url ) ] parameters = " " } re := regexp . MustCompile ( " " ) query = re . ReplaceAllString ( query , " " ) url = protocol + query + parameters return url , nil }
Validates and processes the given Url
@param    url     The given Url to process
@return   Pre-processed Url as string
Validates and processes the given Url @param url The given Url to process @return Pre - processed Url as string
//perform parameter validation //ensure that the urls are absolute //get the http protocol match //remove redundant forward slashes //return process url