Go Package net/url: Difference between revisions
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
=Overview= | =Overview= | ||
=URL Parsing= | =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> |
Revision as of 22:43, 15 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)
}