hashlink

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const (

	// HLPrefix is hash link prefix.
	HLPrefix = hl + separator
)

Variables

This section is empty.

Functions

func GetHashLink(resource, metadata string) string

GetHashLink will create hashlink from resource hash and metadata.

func GetHashLinkFromResourceHash

func GetHashLinkFromResourceHash(resource string) string

GetHashLinkFromResourceHash will create hashlink from resource hash.

func GetResourceHashFromHashLink(hashLink string) (string, error)

GetResourceHashFromHashLink will return resource hash.

func ToString added in v1.0.0

func ToString(hl ...*url.URL) string

ToString parses the given hashlink(s) and returns a human-readable form.

Types

type Decoder

type Decoder func(encodedContent string) ([]byte, error)

Decoder defines decoding function.

type Encoder

type Encoder func(content []byte) string

Encoder defines encoding function.

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

HashLink implements hashlink related functionality.

func New

func New(opts ...Option) *HashLink

New creates HashLink.

func (hl *HashLink) CreateHashLink(content []byte, links []string) (string, error)

CreateHashLink will create hashlink for the supplied content and links.

func (hl *HashLink) CreateMetadataFromLinks(links []string) (string, error)

CreateMetadataFromLinks will create metadata for the supplied links.

func (*HashLink) CreateResourceHash

func (hl *HashLink) CreateResourceHash(content []byte) (string, error)

CreateResourceHash will create resource hash for the supplied content.

func (*HashLink) GetLinksFromMetadata

func (hl *HashLink) GetLinksFromMetadata(enc string) ([]string, error)

GetLinksFromMetadata will create links from metadata.

func (hl *HashLink) ParseHashLink(hashLink string) (*Info, error)

ParseHashLink will parse hash link into resource hash and metadata.

type Info

type Info struct {
	ResourceHash string
	Links        []string
}

Info contains hashlink information: resource hash and links.

type Option

type Option func(opts *HashLink)

Option is a hashlink instance option.

func WithDecoder

func WithDecoder(dec Decoder) Option

WithDecoder option is for specifying custom decoder.

func WithEncoder

func WithEncoder(enc Encoder) Option

WithEncoder option is for specifying custom encoder.

func WithMultihashCode

func WithMultihashCode(mhCode uint) Option

WithMultihashCode option is for specifying custom multihash code.

Jump to

Keyboard shortcuts

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