util

package
v0.0.0-...-712f093 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2015 License: GPL-2.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// Set of characters to use for generating random strings
	Alphabet     = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	Numerals     = "1234567890"
	Alphanumeric = Alphabet + Numerals
	Ascii        = Alphanumeric + "~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:`"
)

Variables

View Source
var MinMaxError = errors.New("Min cannot be greater than max.")

Functions

func AlphaString

func AlphaString(n int) (string, error)

AlphaString returns a random alphanumeric string n characters long.

func AlphaStringRange

func AlphaStringRange(min, max int) (string, error)

AlphaRange returns a random alphanumeric string at least min and no more than max characters long.

func ChoiceInt

func ChoiceInt(choices []int) (int, error)

ChoiceInt returns a random selection from an array of integers.

func ChoiceString

func ChoiceString(choices []string) (string, error)

ChoiceString returns a random selection from an array of strings.

func Convert

func Convert(src interface{}, dest interface{}) error

func Exist

func Exist(path string) bool

func FolderSize

func FolderSize(folder string, excludes_suffixes []string) int64

func HasSuffix

func HasSuffix(fn, suffix string) bool

func IntRange

func IntRange(min, max int) (int, error)

IntRange returns a random integer in the range from min to max.

func Namespace

func Namespace(uri string) (string, error)

func NamespaceKey

func NamespaceKey(uri string) (string, string)

func NumberInt

func NumberInt(v interface{}) (int, error)

func PathFolders

func PathFolders(path string) []string

func QrcodeKey

func QrcodeKey(uri string, size int) string

func ResizeKey

func ResizeKey(uri string, resize string) string

func SignString

func SignString(secret, message string) string

func String

func String(n int, charset string) (string, error)

String returns a random string n characters long, composed of entities from charset.

func StringRange

func StringRange(min, max int, charset string) (string, error)

StringRange returns a random string at least min and no more than max characters long, composed of entitites from charset.

Types

type AtomicInt64

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

func NewAtomicInt64

func NewAtomicInt64(init int64) *AtomicInt64

func (*AtomicInt64) Caculate

func (ai *AtomicInt64) Caculate(delta int64) int64

func (*AtomicInt64) Value

func (ai *AtomicInt64) Value() int64

type Background

type Background struct {
	sync.WaitGroup
}

func (*Background) Work

func (b *Background) Work(fn func())

type Choice

type Choice struct {
	Weight int
	Item   interface{}
}

A Choice contains a generic item and a weight controlling the frequency with which it will be selected.

func WeightedChoice

func WeightedChoice(choices []Choice) (Choice, error)

WeightedChoice used weighted random selection to return one of the supplied choices. Weights of 0 are never selected. All other weight values are relative. E.g. if you have two choices both weighted 3, they will be returned equally often; and each will be returned 3 times as often as a choice weighted 1.

type Email

type Email struct {
	*Match
}

func ValidEmail

func ValidEmail() Email

func (Email) DefaultMessage

func (e Email) DefaultMessage() string

func (Email) Key

func (e Email) Key() string

func (Email) Value

func (e Email) Value() interface{}

type Length

type Length struct {
	N int
}

Requires an array or string to be exactly a given length.

func ValidLength

func ValidLength(n int) *Length

func (*Length) DefaultMessage

func (s *Length) DefaultMessage() string

func (*Length) IsSatisfied

func (s *Length) IsSatisfied(obj interface{}) bool

func (*Length) Key

func (l *Length) Key() string

func (*Length) Value

func (l *Length) Value() interface{}

type Match

type Match struct {
	Regexp *regexp.Regexp
	// contains filtered or unexported fields
}

Requires a string to match a given regex.

func ValidMatch

func ValidMatch(str string) *Match

func (*Match) DefaultMessage

func (m *Match) DefaultMessage() string

func (*Match) IsSatisfied

func (m *Match) IsSatisfied(obj interface{}) bool

func (*Match) Key

func (m *Match) Key() string

func (*Match) Value

func (m *Match) Value() interface{}

type Max

type Max struct {
	Max int
}

func ValidMax

func ValidMax(max int) *Max

func (*Max) DefaultMessage

func (m *Max) DefaultMessage() string

func (*Max) IsSatisfied

func (m *Max) IsSatisfied(obj interface{}) bool

func (*Max) Key

func (m *Max) Key() string

func (*Max) Value

func (m *Max) Value() interface{}

type MaxSize

type MaxSize struct {
	Max int
}

Requires an array or string to be at most a given length.

func ValidMaxSize

func ValidMaxSize(max int) *MaxSize

func (*MaxSize) DefaultMessage

func (m *MaxSize) DefaultMessage() string

func (*MaxSize) IsSatisfied

func (m *MaxSize) IsSatisfied(obj interface{}) bool

func (*MaxSize) Key

func (m *MaxSize) Key() string

func (*MaxSize) Value

func (m *MaxSize) Value() interface{}

type Min

type Min struct {
	Min int
}

func ValidMin

func ValidMin(min int) *Min

func (*Min) DefaultMessage

func (m *Min) DefaultMessage() string

func (*Min) IsSatisfied

func (m *Min) IsSatisfied(obj interface{}) bool

func (*Min) Key

func (m *Min) Key() string

func (*Min) Value

func (m *Min) Value() interface{}

type MinSize

type MinSize struct {
	Min int
}

Requires an array or string to be at least a given length.

func ValidMinSize

func ValidMinSize(min int) *MinSize

func (*MinSize) DefaultMessage

func (m *MinSize) DefaultMessage() string

func (*MinSize) IsSatisfied

func (m *MinSize) IsSatisfied(obj interface{}) bool

func (*MinSize) Key

func (m *MinSize) Key() string

func (*MinSize) Value

func (m *MinSize) Value() interface{}

type Rect

type Rect struct {
	Width  int
	Height int
}

func ParseRect

func ParseRect(val string, delimeter string) (*Rect, error)

type Required

type Required struct{}

func ValidRequired

func ValidRequired() *Required

func (*Required) DefaultMessage

func (r *Required) DefaultMessage() string

func (*Required) IsSatisfied

func (r *Required) IsSatisfied(obj interface{}) bool

func (*Required) Key

func (r *Required) Key() string

func (*Required) Value

func (r *Required) Value() interface{}

type Signature

type Signature struct {
	Secret string
}

func (Signature) Sign

func (sig Signature) Sign(message string) string

func (Signature) Verify

func (sig Signature) Verify(message, signature string) bool

type Validator

type Validator interface {
	Key() string
	Value() interface{}
	IsSatisfied(interface{}) bool
	DefaultMessage() string
}

func NewValidator

func NewValidator(key string, value interface{}) (Validator, error)

Jump to

Keyboard shortcuts

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