splitter

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 3 Imported by: 0

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

https://en.wikipedia.org/wiki/Uniform_Resource_Identifier

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitAuthority

func SplitAuthority(authority string) (string, string, string)

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

func SplitURI(uri string) (string, string)

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

func SplitUserInfo(userinfo string) (string, string, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL