url

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 11 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHash = errors.New("invalid hash")

ErrInvalidHash means that a transaction ID did not include a valid hash.

View Source
var ErrMissingHash = errors.New("missing hash")

ErrMissingHash means that a transaction ID did not include a hash.

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 TxID

type TxID struct {
	// contains filtered or unexported fields
}

TxID is a transaction identifier.

func MustParseTxID

func MustParseTxID(s string) *TxID

MustParseTxID calls ParseTxID and panics if it returns an error.

func ParseTxID

func ParseTxID(s string) (*TxID, error)

ParseTxID parses the string as a URL and parses the URL's user info as a transaction hash.

func (*TxID) Account

func (x *TxID) Account() *URL

Account returns the account URL.

func (*TxID) AsUrl

func (x *TxID) AsUrl() *URL

AsUrl returns a URL with the transaction ID as the user info.

func (*TxID) Compare

func (x *TxID) Compare(y *TxID) int

func (*TxID) Equal

func (x *TxID) Equal(y *TxID) bool

Equal checks if X and Y are the same transaction ID.

func (*TxID) Hash

func (x *TxID) Hash() [32]byte

Hash returns the transaction hash.

func (*TxID) HashSlice added in v1.1.0

func (x *TxID) HashSlice() []byte

HashSlice returns the transaction hash as a slice.

func (*TxID) MarshalJSON

func (x *TxID) MarshalJSON() ([]byte, error)

MarshalJSON marshals the transaction ID to JSON as a string.

func (*TxID) RawString

func (x *TxID) RawString() string

RawString reassembles the URL into a valid URL string without encoding any component.

func (*TxID) ShortString

func (x *TxID) ShortString() string

ShortString returns String without the scheme prefix.

func (*TxID) String

func (x *TxID) String() string

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

func (*TxID) UnmarshalJSON

func (x *TxID) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the transaction ID from JSON as a string.

type URL

type URL struct {
	UserInfo  string
	Authority string
	Path      string
	Query     string
	Fragment  string
	// contains filtered or unexported fields
}

URL is an Accumulate URL.

func MustParse

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) AsTxID

func (u *URL) AsTxID() (*TxID, error)

AsTxID parses the URL's user info as a transaction hash.

func (*URL) Compare

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) 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

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) Hash32

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

Hash32 returns Hash as a [32]byte.

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

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

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

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

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

func (*URL) ParentOf

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) PathEqual

func (u *URL) PathEqual(v string) bool

PathEqual reports whether u.Path and v, normalized and interpreted as UTF-8, are equal under Unicode case-folding.

func (*URL) Port

func (u *URL) Port() string

Port returns the port from the authority component.

func (*URL) PrefixOf

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

PrefixOf returns true if U is a prefix of V.

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 reassembles the URL into a valid URL string without encoding any component.

func (*URL) RootIdentity

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

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) StripExtras

func (u *URL) StripExtras() *URL

StripExtras returns a URL with everything except the authority and path stripped. The receiver is returned if it meets the criteria.

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.

func (*URL) ValidUTF8

func (u *URL) ValidUTF8() bool

ValidUTF8 verifies that all URL components are valid UTF-8 strings.

func (*URL) WithAuthority

func (u *URL) WithAuthority(s string) *URL

WithAuthority creates a copy of the URL with Authority set to the given value.

func (*URL) WithFragment

func (u *URL) WithFragment(s string) *URL

WithFragment creates a copy of the URL with Fragment set to the given value.

func (*URL) WithPath

func (u *URL) WithPath(s string) *URL

WithPath creates a copy of the URL with Path set to the given value.

func (*URL) WithQuery

func (u *URL) WithQuery(s string) *URL

WithQuery creates a copy of the URL with Query set to the given value.

func (*URL) WithTxID

func (u *URL) WithTxID(hash [32]byte) *TxID

WithTxID constructs a transaction ID.

func (*URL) WithUserInfo

func (u *URL) WithUserInfo(s string) *URL

WithUserInfo creates a copy of the URL with UserInfo set to the given value.

type Values

type Values = url.Values

Jump to

Keyboard shortcuts

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