short

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlwaysTrue

func AlwaysTrue(_ *ShortID) bool

AlwaysTrue always returns true. Used for GenerateID and GenerateShortID.

Types

type RedisKey

type RedisKey uint64

RedisKey is used to be able to specify keys at RedisKeyf (as magic constant)

const (
	// RedisKeyCountGlobal -> gme::short::{id}::count:g
	RedisKeyCountGlobal RedisKey = iota

	// RedisKeyCount60 -> gme::short::{id}::count:60
	RedisKeyCount60
)

type ShortID

type ShortID string

ShortID -> ID of a ShortURL object of type string

func GenerateID

func GenerateID(length int, accept func(id *ShortID) bool, try uint64) ShortID

GenerateID generates a string of length {length} using the characters from availableCharacters. This generated string is checked against the {accept} function and, if this function returns true, it will return the generated string. Otherwise, the process is tried a total of 5 more times until the {accept} function returns true, or the attempts are exhausted. After that an empty string is returned.

func GenerateShortID

func GenerateShortID(accept func(id *ShortID) bool) ShortID

GenerateShortID generates a 5 - 10 long string and checks it against the {accept} function. More information: GenerateID()

func (*ShortID) BsonFilter

func (id *ShortID) BsonFilter() bson.M

BsonFilter returns a bson map (bson.M) with the search option: "id": ShortID

func (*ShortID) Bytes

func (id *ShortID) Bytes() []byte

Bytes converts the ShortID to a byte array (splice)

func (*ShortID) IsEmpty

func (id *ShortID) IsEmpty() bool

func (*ShortID) IsValid

func (id *ShortID) IsValid() bool

func (*ShortID) RedisKey

func (id *ShortID) RedisKey() string

RedisKey returns gme::short::{id}

func (*ShortID) RedisKeyf

func (id *ShortID) RedisKeyf(keys ...interface{}) string

RedisKeyf returns gme::short::{id}::{keys}

func (*ShortID) String

func (id *ShortID) String() string

String converts the ShortID to a string

type ShortURL

type ShortURL struct {
	ID             ShortID    `json:"id" bson:"id"`
	FullURL        string     `json:"full_url" bson:"full_url"`
	CreationDate   time.Time  `json:"creation_date" bson:"creation_date"`
	ExpirationDate *time.Time `json:"expiration_date" bson:"expiration_date"`
	Secret         string     `json:"secret" bson:"secret"`
}

ShortURL -> Structure for shortened urls

func (*ShortURL) BsonUpdate

func (u *ShortURL) BsonUpdate() bson.M

BsonUpdate returns a bson map (bson.M) with the field "$set": ShortURL

func (*ShortURL) GetRedirectURL

func (u *ShortURL) GetRedirectURL() (url string)

func (*ShortURL) IsExpired

func (u *ShortURL) IsExpired() bool

func (*ShortURL) IsLocked

func (u *ShortURL) IsLocked() bool

func (*ShortURL) IsTemporary

func (u *ShortURL) IsTemporary() bool

func (*ShortURL) String

func (u *ShortURL) String() string

type Stats

type Stats struct {
	// Calls -> Global Calls
	Calls uint64

	// Calls60 -> Calls in 60 minutes
	Calls60 uint64
}

Stats -> struct that holds the stats of a ShortURL

Jump to

Keyboard shortcuts

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