utils

package
v0.0.0-...-d4f462a Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package utils contains general purpose functions and helpers used in many packages.

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfRange = errors.New("Out of range")

Functions

func IsAlphaNumeric

func IsAlphaNumeric(s string) bool

IsAlphaNumeric returns true if a string consists of characters a-zA-Z0-9_

func Round

func Round(val float64, roundOn float64, places int) float64

Round rounds a value. RoundOn is usually .5.

func Translit

func Translit(str []rune) []rune

Translit replaces characters in a string using a conversion table, e.g. ™ => tm; © => c; @ => at; € => euro Magento compatible

func TranslitURL

func TranslitURL(str []rune) []rune

TranslitURL same as Translit() but removes after conversion any non 0-9A-Za-z characters and replaces them with a dash. Magento compatible. This function is responsible for the slug generation for product/category/cms URLs.

func TranslitURLUnicode

func TranslitURLUnicode(str []rune) []rune

TranslitURLUnicode takes care of unicode characters. @todo

Types

type HealthJobNoop

type HealthJobNoop struct{}

HealthJobNoop default Job for the health.EventReceiver

func (HealthJobNoop) Event

func (HealthJobNoop) Event(eventName string)

func (HealthJobNoop) EventErr

func (HealthJobNoop) EventErr(eventName string, err error) error

func (HealthJobNoop) EventErrKv

func (HealthJobNoop) EventErrKv(eventName string, err error, kvs map[string]string) error

func (HealthJobNoop) EventKv

func (HealthJobNoop) EventKv(eventName string, kvs map[string]string)

func (HealthJobNoop) Timing

func (HealthJobNoop) Timing(eventName string, nanoseconds int64)

func (HealthJobNoop) TimingKv

func (HealthJobNoop) TimingKv(eventName string, nanoseconds int64, kvs map[string]string)

type Int64Slice

type Int64Slice []int64

Int64Slice contains Map/Filter/Reduce/Sort/Unique/etc method receivers for []int64. @todo think about the necessary gen functions +gen slice:"Where,Count,GroupBy[int64]"

func (Int64Slice) All

func (l Int64Slice) All(f func(int64) bool) bool

All returns true if all of the int64s in the slice satisfy the predicate f.

func (Int64Slice) Any

func (l Int64Slice) Any(f func(int64) bool) bool

Any returns true if one of the int64s in the slice satisfies the predicate f.

func (*Int64Slice) Append

func (l *Int64Slice) Append(s ...int64) Int64Slice

Append adds s (variadic) to the Int64Slice

func (*Int64Slice) Delete

func (l *Int64Slice) Delete(i int) error

Delete removes index i from slice

func (Int64Slice) Include

func (l Int64Slice) Include(t int64) bool

Include returns true if the target int64 t is in the slice.

func (Int64Slice) Index

func (l Int64Slice) Index(t int64) int

Index returns -1 if not found or the current index for target t.

func (Int64Slice) Len

func (l Int64Slice) Len() int

Len returns the length

func (Int64Slice) Less

func (l Int64Slice) Less(i, j int) bool

Less compares two slice values

func (*Int64Slice) Map

func (l *Int64Slice) Map(f func(int64) int64) Int64Slice

Map changes itself containing the results of applying the function f to each int64 in itself.

func (*Int64Slice) Reduce

func (l *Int64Slice) Reduce(f func(int64) bool) Int64Slice

Reduce reduces itself containing all int64s in the slice that satisfy the predicate f.

func (Int64Slice) Reverse

func (l Int64Slice) Reverse() Int64Slice

Reverse is a convenience method.

func (Int64Slice) Sort

func (l Int64Slice) Sort() Int64Slice

Sort is a convenience method.

func (Int64Slice) Sum

func (l Int64Slice) Sum() int64

Sum returns the sum

func (Int64Slice) Swap

func (l Int64Slice) Swap(i, j int)

Swap changes the position

func (Int64Slice) ToInt64

func (l Int64Slice) ToInt64() []int64

ToInt64 converts to type int64 slice.

func (*Int64Slice) Unique

func (l *Int64Slice) Unique() Int64Slice

Unique removes duplicate entries.

func (*Int64Slice) Update

func (l *Int64Slice) Update(i int, s int64) error

Update sets the int64 s on index i. If index is not found returns an ErrOutOfRange.

type SortDirection

type SortDirection uint8
const (
	SortAsc SortDirection = 1 << iota
	SortDesc
)

func (SortDirection) String

func (i SortDirection) String() string

type StringSlice

type StringSlice []string

StringSlice contains Map/Filter/Reduce/Sort/Unique/etc method receivers for []string.

func (StringSlice) All

func (l StringSlice) All(f func(string) bool) bool

All returns true if all of the strings in the slice satisfy the predicate f.

func (StringSlice) Any

func (l StringSlice) Any(f func(string) bool) bool

Any returns true if one of the strings in the slice satisfies the predicate f.

func (*StringSlice) Append

func (l *StringSlice) Append(s ...string) StringSlice

Append adds s (variadic) to the StringSlice

func (*StringSlice) Delete

func (l *StringSlice) Delete(i int) error

Delete removes index i from slice

func (StringSlice) Filter

func (l StringSlice) Filter(f func(string) bool) StringSlice

Filter filters all strings in the slice that satisfy the predicate f and returns a new slice

func (StringSlice) Include

func (l StringSlice) Include(t string) bool

Include returns true if the target string t is in the slice.

func (StringSlice) Index

func (l StringSlice) Index(t string) int

Index returns -1 if not found or the current index for target t.

func (StringSlice) Join

func (l StringSlice) Join(sep string) string

Join joins the slice using a separator

func (StringSlice) Len

func (l StringSlice) Len() int

Len returns the length

func (StringSlice) Less

func (l StringSlice) Less(i, j int) bool

Less compares two slice values

func (*StringSlice) Map

func (l *StringSlice) Map(f func(string) string) StringSlice

Map changes itself containing the results of applying the function f to each string in itself.

func (*StringSlice) Reduce

func (l *StringSlice) Reduce(f func(string) bool) StringSlice

Reduce reduces itself containing all strings in the slice that satisfy the predicate f.

func (*StringSlice) ReduceContains

func (l *StringSlice) ReduceContains(in ...string) StringSlice

ReduceContains reduces itself if the parts of the in slice are contained within itself.

func (*StringSlice) Shuffle

func (l *StringSlice) Shuffle() StringSlice

Shuffle destroys the order

func (StringSlice) Sort

func (l StringSlice) Sort() StringSlice

Sort is a convenience method.

func (*StringSlice) Split

func (l *StringSlice) Split(s, sep string) StringSlice

Split uses string s and a separator and appends the parts to the slice.

func (*StringSlice) SplitStringer8

func (l *StringSlice) SplitStringer8(n string, ps ...uint8) StringSlice

SplitStringer uses a name and position indexes to split the name and appends the parts to the slice. Cracking the names and indexes which the stringer command generates.

func (StringSlice) Swap

func (l StringSlice) Swap(i, j int)

Swap changes the position

func (StringSlice) ToString

func (l StringSlice) ToString() []string

ToString converts to string slice.

func (*StringSlice) Unique

func (l *StringSlice) Unique() StringSlice

Unique removes duplicate entries and discards "" empty strings.

func (*StringSlice) Update

func (l *StringSlice) Update(i int, s string) error

Update sets the string s on index i. If index is not found returns an ErrOutOfRange.

Directories

Path Synopsis
Package log contains NullLogger, StdLogger and the Logger interface.
Package log contains NullLogger, StdLogger and the Logger interface.

Jump to

Keyboard shortcuts

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