url

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingHost = errors.New("missing host")

ErrMissingHost means that a URL did not include a hostname.

View Source
var ErrWrongScheme = errors.New("wrong scheme")

ErrWrongScheme means that a URL included a scheme other than the Accumulate scheme.

Functions

This section is empty.

Types

type URL

type URL struct {
	UserInfo  string
	Authority string
	Path      string
	Query     string
	Fragment  string
}

URL is an Accumulate URL.

func MustParse added in v0.5.1

func MustParse(s string) *URL

MustParse calls Parse and panics if it returns an error.

func Parse

func Parse(s string) (*URL, error)

Parse parses the string as an Accumulate URL. The scheme may be omitted, in which case `acc://` will be added, but if present it must be `acc`. The hostname must be non-empty. RawPath, ForceQuery, and RawFragment are not preserved.

func (*URL) AccountID

func (u *URL) AccountID() []byte

AccountID constructs an account identifier from the lower case hostname and path. The port is not included. If the path does not begin with `/`, `/` is added between the hostname and the path.

ID = Hash(LowerCase(Sprintf("%s/%s", u.Host(), u.Path)))

func (*URL) AccountID32

func (u *URL) AccountID32() [32]byte

AccountID32 returns AccountID as a [32]byte.

func (*URL) Compare added in v0.5.1

func (u *URL) Compare(v *URL) int

Compare returns an integer comparing two URLs as lower case strings. The result will be 0 if u == v, -1 if u < v, and +1 if u > v.

func (*URL) Copy added in v0.5.1

func (u *URL) Copy() *URL

Copy returns a copy of the url.

func (*URL) Equal

func (u *URL) Equal(v *URL) bool

Equal reports whether u and v, converted to strings and interpreted as UTF-8, are equal under Unicode case-folding.

func (*URL) Hash added in v0.5.1

func (u *URL) Hash() []byte

Hash calculates a hash of the URL starting with AccountID, hashing and concatenating Query unless it is empty, and hashing and concatenating Fragment unless it is empty. If Query and Fragment are both non-empty, with H defined as the SHA-256 hash of the lower case of the operand, the result is H(H(AccountID + H(Query)) + H(Fragment)).

func (*URL) Hostname

func (u *URL) Hostname() string

Hostname returns the hostname from the authority component.

func (*URL) Identity

func (u *URL) Identity() *URL

Identity returns a copy of the URL with the last section cut off the path.

func (*URL) IdentityAccountID

func (u *URL) IdentityAccountID() []byte

IdentityAccountID constructs an account identifier from the lower case hostname. The port is not included.

ID = Hash(LowerCase(u.Host()))

func (*URL) IdentityAccountID32

func (u *URL) IdentityAccountID32() [32]byte

IdentityAccountID32 returns IdentityAccountID as a [32]byte.

func (*URL) IsRootIdentity added in v0.6.0

func (u *URL) IsRootIdentity() bool

IsRootIdentity returns true if the URL is a root identity.

func (*URL) JoinPath

func (u *URL) JoinPath(s ...string) *URL

JoinPath returns a copy of U with additional path elements.

func (*URL) LocalTo added in v0.6.0

func (u *URL) LocalTo(v *URL) bool

LocalTo returns true if U is local to V, that is if they have the same root identity.

func (*URL) MarshalJSON

func (u *URL) MarshalJSON() ([]byte, error)

MarshalJSON marshals the URL to JSON as a string.

func (*URL) Parent added in v0.5.1

func (u *URL) Parent() (*URL, bool)

Parent gets the URL's parent path, or returns the original URL and false.

func (*URL) ParentOf added in v0.6.0

func (u *URL) ParentOf(v *URL) bool

ParentOf returns true if U is the parent of V

func (*URL) Password

func (u *URL) Password() string

Password returns the password from the user info component.

func (*URL) Port

func (u *URL) Port() string

Port returns the port from the authority component.

func (*URL) QueryValues

func (u *URL) QueryValues() Values

QueryValues parses Query and returns the corresponding values. It silently discards malformed value pairs. To check errors use net/url.ParseQuery.

func (*URL) RawString

func (u *URL) RawString() string

RawString concatenates all of the URL parts. Does not percent-encode anything. Primarily used for validation.

func (*URL) RootIdentity added in v0.5.1

func (u *URL) RootIdentity() *URL

RootIdentity returns a copy of the URL with an empty path.

func (*URL) Routing

func (u *URL) Routing() uint64

Routing returns the first 8 bytes of the identity account ID as an integer.

Routing = uint64(u.IdentityAccountID()[:8])

func (*URL) ShortString added in v0.6.0

func (u *URL) ShortString() string

ShortString returns String without the scheme prefix.

func (*URL) String

func (u *URL) String() string

String reassembles the URL into a valid URL string. See net/url.URL.String().

func (*URL) URL

func (u *URL) URL() *url.URL

URL returns a net/url.URL.

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the URL from JSON as a string.

func (*URL) Username

func (u *URL) Username() string

Username returns the username from the user info component.

type Values

type Values = url.Values

Jump to

Keyboard shortcuts

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