trim

package
v0.0.0-...-b5a4b96 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2016 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package trim implements methods and structures to convert users' URLs. Also it controls their consistency in the database.

Index

Constants

View Source
const (
	// Alphabet is a sorted set of basis numeral system chars.
	Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
)

Variables

View Source
var (
	// ErrEmptyCallback is error about empty empty callback usage.
	ErrEmptyCallback = errors.New("empty callback request")
)

Functions

func Decode

func Decode(x string) (int64, error)

Decode converts a Alphabet-base number to decimal one.

func Encode

func Encode(x int64) string

Encode converts a decimal number to Alphabet-base numeral system.

func IsShort

func IsShort(link string) (string, bool)

IsShort checks link can be short URL.

Types

type CallBack

type CallBack struct {
	URL    string `bson:"u"`
	Method string `bson:"m"`
	Name   string `bson:"name"`
	Value  string `bson:"value"`
}

CallBack is callback info.

func (*CallBack) String

func (cb *CallBack) String() string

String returns main callback info.

type ChangeResult

type ChangeResult struct {
	Cu  *CustomURL
	Err string
}

ChangeResult is result of CustomURL pack change.

func Import

func Import(ctx context.Context, links map[string]*ReqParams) ([]ChangeResult, error)

Import imports short URLs.

func MultiLengthen

func MultiLengthen(ctx context.Context, links []string) ([]ChangeResult, error)

MultiLengthen returns short URLs info for slice of links.

type CustomURL

type CustomURL struct {
	ID        int64      `bson:"_id"`
	Disabled  bool       `bson:"off"`
	Group     string     `bson:"group"`
	Tag       string     `bson:"tag"`
	Original  string     `bson:"orig"`
	User      string     `bson:"u"`
	TTL       *time.Time `bson:"ttl"`
	NotDirect bool       `bson:"ndr"`
	Spam      float64    `bson:"spam"`
	Created   time.Time  `bson:"ts"`
	Modified  time.Time  `bson:"mod"`
	Cb        CallBack   `bson:"cb"`
	API       bool       `bson:"api"`
}

CustomURL stores info about user's URL.

func Export

func Export(ctx context.Context, filter Filter) ([]*CustomURL, [3]int, error)

Export exports URLs data.

func Lengthen

func Lengthen(ctx context.Context, short string) (*CustomURL, error)

Lengthen converts a short link to original one. It uses own database session if it's needed or it gets data from the cache.

func Shorten

func Shorten(ctx context.Context, params []*ReqParams) ([]*CustomURL, error)

Shorten returns new short links.

func (*CustomURL) Callback

func (cu *CustomURL) Callback() (*http.Request, error)

Callback returns a prepared body request Reader as bytes.Buffer pointer.

func (*CustomURL) String

func (cu *CustomURL) String() string

String returns short string URL without domain prefix.

type Filter

type Filter struct {
	Group    string
	Tag      string
	Period   [2]*time.Time
	Active   bool
	Page     int
	PageSize int
}

Filter is a data filter to export URLs info.

type ReqParams

type ReqParams struct {
	Original  string
	Tag       string
	Group     string
	NotDirect bool
	IsAPI     bool
	TTL       *time.Time
	Cb        CallBack
}

ReqParams is request parameters required for new short URL creation.

func (*ReqParams) String

func (rp *ReqParams) String() string

String returns request info.

func (*ReqParams) Valid

func (rp *ReqParams) Valid() error

Valid checks ReqParams values.

Jump to

Keyboard shortcuts

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