link

package
v1.3.2-0...-4312943 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVersionNotSupport = errors.New("link version is not support")
	ErrInvalidParams     = errors.New("invalid parameters passed")
	ErrNotFound          = errors.New("link not found")
)

Exported errors.

Functions

func Parse

func Parse(url string) (key string, param string)

Parse parses the url and returns the key and param. key: the key of the link record without leading and trailing "/". param: the param passed in the url "/abc.efg/yoyoyo" -> ("abc.efg", "yoyoyo")

func Pop

func Pop(str string, sep string) (left string, remain string)

Pop returns the prefix before the first `sep` and the remaining string.

Types

type Link struct {
	Version int
	Blob    []byte
}

Link defines the link struct

func New

func New(ver int, payload string) (*Link, error)

New returns a new link of ver with payload.

func V0

func V0(url string) Link

V0 returns a v0 link.

func V1

func V1(format string) Link

V1 returns a v1 link.

func V2

func V2(format string) (ln Link, err error)

V2 returns a v2 link.

func (*Link) Description

func (l *Link) Description() (string, error)

Description returns the description string of l.

func (l *Link) GetRedirectLink(param string) (string, error)

GetRedirectLink returns the target redirect link of l.

type Store

type Store interface {
	fmt.Stringer

	GetLink(ctx context.Context, org string, key string) (Link, error)
	GetLinks(ctx context.Context, org string) (map[string]Link, error)
	UpdateLink(ctx context.Context, org string, key string, ln Link) error
	DeleteLink(ctx context.Context, org string, key string) error
}

Store defines the link store interface.

type Version

type Version interface {
	New(payload string) (blob []byte, err error)
	Resolve([]byte, string) (string, error)
	Describe([]byte) (string, error)
}

Version defines the version interface, which is the operator for the blob.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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