Documentation
¶
Overview ¶
Package splitter provides functions for splitting various pieces of a Uniform Resource Identifier (URI). This package is used by the grw package.
https://godoc.org/github.com/spatialcurrent/go-reader-writer/grw
Usage ¶
You can import splitter as a package into your own Go project.
import ( "github.com/spatialcurrent/go-reader-writer/pkg/splitter" )
Reference ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SplitAuthority ¶
SplitAuthority splits an authority string into userinfo, host, and port.
Example (Host) ¶
userinfo, host, port := SplitAuthority("foo.bar") fmt.Printf("userinfo=%q host=%q port=%q\n", userinfo, host, port)
Output: userinfo="" host="foo.bar" port=""
Example (HostPort) ¶
userinfo, host, port := SplitAuthority("foo.bar:80") fmt.Printf("userinfo=%q host=%q port=%q\n", userinfo, host, port)
Output: userinfo="" host="foo.bar" port="80"
Example (HostPortUser) ¶
userinfo, host, port := SplitAuthority("joe@foo.bar:80") fmt.Printf("userinfo=%q host=%q port=%q\n", userinfo, host, port)
Output: userinfo="joe" host="foo.bar" port="80"
Example (HostPortUserPassword) ¶
userinfo, host, port := SplitAuthority("joe:joey@foo.bar:80") fmt.Printf("userinfo=%q host=%q port=%q\n", userinfo, host, port)
Output: userinfo="joe:joey" host="foo.bar" port="80"
func SplitURI ¶ added in v0.0.3
SplitURI splits a uri string into a scheme and remainder. If no scheme is specified, then returns "" as the scheme and the original string.
Example (FTP) ¶
scheme, remainder := SplitURI("ftp://foo.bar") fmt.Printf("scheme=%q remainder=%q\n", scheme, remainder)
Output: scheme="ftp" remainder="foo.bar"
Example (File) ¶
scheme, remainder := SplitURI("file:///path/to/file") fmt.Printf("scheme=%q remainder=%q\n", scheme, remainder)
Output: scheme="file" remainder="/path/to/file"
Example (HTTPS) ¶
scheme, remainder := SplitURI("https://foo.bar") fmt.Printf("scheme=%q remainder=%q\n", scheme, remainder)
Output: scheme="https" remainder="foo.bar"
Example (None) ¶
scheme, remainder := SplitURI("foo.bar") fmt.Printf("scheme=%q remainder=%q\n", scheme, remainder)
Output: scheme="" remainder="foo.bar"
func SplitUserInfo ¶
SplitUserInfo splits a user info string into a user and password. User and password are unescaped using PathUnescape found in "net/url". Returns the user, password, and error, if any. The input user info string could match one of the following.
- user
- user:
- user:password
Example (None) ¶
user, password, err := SplitUserInfo("") if err != nil { panic(err) } fmt.Printf("user=%q password=%q\n", user, password)
Output: user="" password=""
Example (User) ¶
user, password, err := SplitUserInfo("foo") if err != nil { panic(err) } fmt.Printf("user=%q password=%q\n", user, password)
Output: user="foo" password=""
Example (UserColon) ¶
user, password, err := SplitUserInfo("foo:") if err != nil { panic(err) } fmt.Printf("user=%q password=%q\n", user, password)
Output: user="foo" password=""
Example (UserPassword) ¶
user, password, err := SplitUserInfo("foo:bar") if err != nil { panic(err) } fmt.Printf("user=%q password=%q\n", user, password)
Output: user="foo" password="bar"
Types ¶
This section is empty.