This commit is contained in:
Sangeeth Sudheer 2024-05-02 21:22:35 +05:30
parent 6f670fe92b
commit a415d888f1
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 39 additions and 2 deletions

View File

@ -30,7 +30,8 @@ package main
// import "git.sangeeth.dev/gobyexample/xml" // import "git.sangeeth.dev/gobyexample/xml"
// import "git.sangeeth.dev/gobyexample/time" // import "git.sangeeth.dev/gobyexample/time"
// import "git.sangeeth.dev/gobyexample/rand" // 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() { func main() {
// runes.Runes() // runes.Runes()
@ -63,5 +64,6 @@ func main() {
// xml.Xml() // xml.Xml()
// time.Time() // time.Time()
// rand.Rand() // rand.Rand()
numberparsing.NumberParsing() // numberparsing.NumberParsing()
url.Url()
} }

35
url/url.go Normal file
View 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])
}