Go Package net/url: Difference between revisions
Jump to navigation
Jump to search
(4 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
=Overview= | =Overview= | ||
=URL Parsing= | |||
<syntaxhighlight lang='go'> | |||
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) | |||
</syntaxhighlight> | |||
=<tt>url.QueryEscape()</tt>= | |||
<font color=darkkhaki>Same effect with fmt.Printf("%s", http)</code>. |
Latest revision as of 20:52, 25 July 2024
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).