urlprs added.
This commit is contained in:
parent
5b80bca4fb
commit
647d875555
3 changed files with 51 additions and 0 deletions
|
@ -16,6 +16,7 @@ import(
|
||||||
"github.com/k1574/goblin/date"
|
"github.com/k1574/goblin/date"
|
||||||
"github.com/k1574/goblin/uniq"
|
"github.com/k1574/goblin/uniq"
|
||||||
"github.com/k1574/goblin/quote"
|
"github.com/k1574/goblin/quote"
|
||||||
|
"github.com/k1574/goblin/urlprs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -38,6 +39,7 @@ func main() {
|
||||||
"date" : date.Run,
|
"date" : date.Run,
|
||||||
"uniq" : uniq.Run,
|
"uniq" : uniq.Run,
|
||||||
"quote" : quote.Run,
|
"quote" : quote.Run,
|
||||||
|
"urlprs" : urlprs.Run,
|
||||||
}
|
}
|
||||||
|
|
||||||
if binBase := path.Base(os.Args[0]) ; binBase != "goblin" {
|
if binBase := path.Base(os.Args[0]) ; binBase != "goblin" {
|
||||||
|
|
BIN
urlprs/urlprs
Executable file
BIN
urlprs/urlprs
Executable file
Binary file not shown.
49
urlprs/urlprs.go
Normal file
49
urlprs/urlprs.go
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue