link

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: CC-BY-SA-4.0 Imports: 8 Imported by: 0

Documentation

Overview

Package link provides link management services.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConflict   = errors.New("conflict")
	ErrNotFound   = errors.New("not found")
	ErrBadRequest = errors.New("bad request")
	ErrInternal   = errors.New("internal error")
)

Functions

This section is empty.

Types

type Key

type Key string

Key is the shortened key of a Link URL.

func Shorten

func Shorten(lnk Link) (Key, error)

Shorten shortens the Link URL and generates a new Key if the Key is empty. Otherwise, it returns the same Key. It returns an error if the Link is invalid.

func (Key) Empty

func (key Key) Empty() bool

Empty reports whether the Key is empty.

func (Key) String

func (key Key) String() string

String returns the key without leading or trailing spaces.

func (Key) Validate

func (key Key) Validate() error

Validate validates the Key.

type Link struct {
	// URL is the original URL of the link.
	URL string
	// Key is the shortened key of the URL.
	Key Key
}

Link represents a link.

func (Link) Validate

func (lnk Link) Validate() error

Validate validates the Link.

type Shortener

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

Shortener shortens and resolves Link values from an in-memory storage. It's safe for concurrent use from multiple goroutines.

func (*Shortener) Resolve

func (s *Shortener) Resolve(_ context.Context, key Key) (Link, error)

Resolve resolves the Key to its original Link.

func (*Shortener) Shorten

func (s *Shortener) Shorten(_ context.Context, lnk Link) (Key, error)

Shorten shortens the Link URL and may update the Key if the key is empty. If the link is valid, it stores it in an in-memory storage.

Directories

Path Synopsis
cmd
linkd command
kit
hio
Package hio (HTTP Input and Output) provides helpers for HTTP request and response handling.
Package hio (HTTP Input and Output) provides helpers for HTTP request and response handling.
hlog
Package hlog (HTTP log) provides HTTP request and response logging.
Package hlog (HTTP log) provides HTTP request and response logging.
traceid
Package traceid provides trace ID related functionality.
Package traceid provides trace ID related functionality.
Package rest provides link services with a REST API over HTTP.
Package rest provides link services with a REST API over HTTP.

Jump to

Keyboard shortcuts

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