Add url
This commit is contained in:
parent
6f670fe92b
commit
a415d888f1
6
main.go
6
main.go
@ -30,7 +30,8 @@ package main
|
||||
// import "git.sangeeth.dev/gobyexample/xml"
|
||||
// import "git.sangeeth.dev/gobyexample/time"
|
||||
// import "git.sangeeth.dev/gobyexample/rand"
|
||||
import "git.sangeeth.dev/gobyexample/numberparsing"
|
||||
// import "git.sangeeth.dev/gobyexample/numberparsing"
|
||||
import "git.sangeeth.dev/gobyexample/url"
|
||||
|
||||
func main() {
|
||||
// runes.Runes()
|
||||
@ -63,5 +64,6 @@ func main() {
|
||||
// xml.Xml()
|
||||
// time.Time()
|
||||
// rand.Rand()
|
||||
numberparsing.NumberParsing()
|
||||
// numberparsing.NumberParsing()
|
||||
url.Url()
|
||||
}
|
||||
|
35
url/url.go
Normal file
35
url/url.go
Normal file
@ -0,0 +1,35 @@
|
||||
package url
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
var p = fmt.Println
|
||||
|
||||
func Url() {
|
||||
parsed, err := url.Parse("app://jon:password@example.org:333/path/to/secret?ref=appstore#confidential")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
p("Scheme:", parsed.Scheme)
|
||||
p("Host with Port:", parsed.Host)
|
||||
|
||||
host, port, _ := net.SplitHostPort(parsed.Host)
|
||||
p("Host only:", host)
|
||||
p("Port only:", port)
|
||||
|
||||
username := parsed.User.Username()
|
||||
password, _ := parsed.User.Password()
|
||||
p("Username:", username)
|
||||
p("Password:", password)
|
||||
|
||||
p("Path:", parsed.Path)
|
||||
p("Raw query:", parsed.RawQuery)
|
||||
p("Fragment:", parsed.Fragment)
|
||||
|
||||
params := parsed.Query()
|
||||
p("Query param 'ref':", params["ref"][0])
|
||||
}
|
Loading…
Reference in New Issue
Block a user