diff --git a/goblin.go b/goblin.go index 42f9b70..160b7c2 100644 --- a/goblin.go +++ b/goblin.go @@ -16,6 +16,7 @@ import( "github.com/k1574/goblin/date" "github.com/k1574/goblin/uniq" "github.com/k1574/goblin/quote" + "github.com/k1574/goblin/urlprs" ) func main() { @@ -38,6 +39,7 @@ func main() { "date" : date.Run, "uniq" : uniq.Run, "quote" : quote.Run, + "urlprs" : urlprs.Run, } if binBase := path.Base(os.Args[0]) ; binBase != "goblin" { diff --git a/urlprs/urlprs b/urlprs/urlprs new file mode 100755 index 0000000..df4e20f Binary files /dev/null and b/urlprs/urlprs differ diff --git a/urlprs/urlprs.go b/urlprs/urlprs.go new file mode 100644 index 0000000..93cefb1 --- /dev/null +++ b/urlprs/urlprs.go @@ -0,0 +1,49 @@ +package urlprs + +import ( + "fmt" + "net" + "net/url" +) + +var nilStr = "_" + +func printNil(s string) { + if len(s) != 0 { + fmt.Println(s) + } else { + fmt.Println(nilStr) + } +} +func Run(args []string) int { + nilStr = "_" + + s := args[1] + + u, err := url.Parse(s) + if err != nil { + return 1 + } + + printNil(u.Scheme) + printNil(u.User.Username()) + p, _ := u.User.Password() + printNil(p) + if host, port, err := net.SplitHostPort(u.Host) ; err!=nil { + printNil(u.Host) + fmt.Println(nilStr) + } else { + printNil(host) + printNil(port) + } + printNil(u.Path) + printNil(u.Fragment) + printNil(u.RawQuery) + + /*fmt.Println(u.RawQuery) + m, _ := url.ParseQuery(u.RawQuery) + fmt.Println(m) + fmt.Println(m["k"][0])*/ + return 0 +} +