Go Package net/url

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

URL Parsing

import (
	"fmt"
	"net/url"
)

s := "https://localhost.apple.com:8099/some/path/?color=blue#something"
l, err := url.Parse(s)
if err != nil {
	panic(err)
}
fmt.Printf("Scheme: %s\n", l.Scheme) // "https"
fmt.Printf("Host: %s\n", l.Host) // "localhost.apple.com:8099"
fmt.Printf("Path: %s\n", l.Path) // "/some/path/"
fmt.Printf("RawQuery: %s\n", l.RawQuery) // "color=blue"
fmt.Printf("Fragment: %s\n", l.Fragment) // "something"
fmt.Printf("User: %s\n", l.User)
fmt.Printf("OmitHost: %t\n", l.OmitHost) // false
fmt.Printf("ForceQuery: %t\n", l.ForceQuery) // false
fmt.Printf("Opaque: %s\n", l.Opaque) 
fmt.Printf("RawFragment: %s\n", l.RawFragment)
fmt.Printf("RawPath: %s\n", l.RawPath)

url.QueryEscape()

Same effect with fmt.Printf("%s", http).