utils

package
v0.0.0-...-06d4dd4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2013 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Helpers, convenience functions and stuff missing in the standard packages.

Index

Constants

View Source
const LoopbackIP = "127.0.0.1"

Variables

This section is empty.

Functions

func AddUrlParam

func AddUrlParam(url, name, value string) string

func AppendEmptySliceField

func AppendEmptySliceField(slice reflect.Value) reflect.Value

func CombineDirs

func CombineDirs(baseDirs []string, searchDirs []string) []string

func CompareCaseInsensitive

func CompareCaseInsensitive(a, b string) bool

func ConvertTimeString

func ConvertTimeString(value, formatIn, formatOut string) (result string, err error)

func DayBeginningTime

func DayBeginningTime(someTimeOfTheDay time.Time) time.Time

func DayTimeRange

func DayTimeRange(someTimeOfTheDay time.Time) (from, until time.Time)

func DeleteEmptySliceElements

func DeleteEmptySliceElements(slice interface{}) interface{}

func DeleteEmptySliceElementsVal

func DeleteEmptySliceElementsVal(sliceVal reflect.Value) reflect.Value

func DirExists

func DirExists(dirname string) bool

func EscapeJSON

func EscapeJSON(jsonString string) string

func FileExists

func FileExists(filename string) bool

func FileModifiedTime

func FileModifiedTime(filename string) (time.Time, error)

func FindFile

func FindFile(searchDirs []string, filename string) (filePath string, found bool)

func FindFile2

func FindFile2(baseDirs []string, searchDirs []string, filename string) (filePath string, found bool)

func FindFile2ModifiedTime

func FindFile2ModifiedTime(baseDirs []string, searchDirs []string, filename string) (filePath string, found bool, modifiedTime time.Time)

func HasImageFileExt

func HasImageFileExt(filename string) bool

func IntRange

func IntRange(start int, end int) <-chan int

func IntRangeStep

func IntRangeStep(start int, end int, step int) <-chan int

func IsImageURL

func IsImageURL(url string) bool

func JoinAbs

func JoinAbs(elem ...string) (string, error)

func JoinNonEmptyStrings

func JoinNonEmptyStrings(sep string, strings ...string) string

func MD5

func MD5(data string) string

func NewLineToHTML

func NewLineToHTML(text string) (html string)

func OwnIP

func OwnIP() string

OwnIP returns the primary IP address of the system or an empty string.

func PrettifyJSON

func PrettifyJSON(compactJSON []byte) string

func ReadURL

func ReadURL(url string) ([]byte, error)

ReadURL reads all data from an URL, including file:// URLs.

func RemoveMultipleWhiteSpace

func RemoveMultipleWhiteSpace(s string) string

func ReverseStringSlice

func ReverseStringSlice(slice []string)

func Round

func Round(val float64, prec int) float64

func SetSliceLengh

func SetSliceLengh(slice reflect.Value, length int) reflect.Value

Sets the length of a slice by sub-slicing a slice that's too long, or appending empty fields if slice is too short.

func SortInterfaceSlice

func SortInterfaceSlice(slice []interface{}, lessFunc func(a, b interface{}) bool)

func StringForStruct

func StringForStruct(typeName string, attributes ...string) string

Todo something more generic

func StringIn

func StringIn(needle string, heystack []string) bool

func StringSliceUnion

func StringSliceUnion(a, b []string) []string

func StripHTMLTags

func StripHTMLTags(text string) (plainText string)

func TextRowsAndCols

func TextRowsAndCols(text string) (rows, cols int)

func TimeInRange

func TimeInRange(t, from, until time.Time) bool

Types

type IntSet

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

func (IntSet) Add

func (self IntSet) Add(val int)

func (IntSet) Contains

func (self IntSet) Contains(val int) bool

func (IntSet) Delete

func (self IntSet) Delete(val int)

type SortableInterfaceSlice

type SortableInterfaceSlice struct {
	Slice    []interface{}
	LessFunc func(a, b interface{}) bool
}

Implements sort.Interface

func (*SortableInterfaceSlice) Len

func (self *SortableInterfaceSlice) Len() int

func (*SortableInterfaceSlice) Less

func (self *SortableInterfaceSlice) Less(i, j int) bool

func (*SortableInterfaceSlice) Sort

func (self *SortableInterfaceSlice) Sort()

func (*SortableInterfaceSlice) Swap

func (self *SortableInterfaceSlice) Swap(i, j int)

type SortableTimeSlice

type SortableTimeSlice []time.Time

func (SortableTimeSlice) Len

func (self SortableTimeSlice) Len() int

Len is the number of elements in the collection.

func (SortableTimeSlice) Less

func (self SortableTimeSlice) Less(i, j int) bool

Less returns whether the element with index i should sort before the element with index j.

func (SortableTimeSlice) Swap

func (self SortableTimeSlice) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type StringBuilder

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

func (*StringBuilder) Bool

func (self *StringBuilder) Bool(value bool) *StringBuilder

func (*StringBuilder) Byte

func (self *StringBuilder) Byte(value byte) *StringBuilder

func (*StringBuilder) Bytes

func (self *StringBuilder) Bytes() []byte

func (*StringBuilder) Float

func (self *StringBuilder) Float(value float64) *StringBuilder

func (*StringBuilder) Int

func (self *StringBuilder) Int(value int) *StringBuilder

func (*StringBuilder) Printf

func (self *StringBuilder) Printf(format string, args ...interface{}) *StringBuilder

func (*StringBuilder) String

func (self *StringBuilder) String() string

func (*StringBuilder) Uint

func (self *StringBuilder) Uint(value uint) *StringBuilder

func (*StringBuilder) Write

func (self *StringBuilder) Write(strings ...string) *StringBuilder

func (*StringBuilder) WriteBytes

func (self *StringBuilder) WriteBytes(bytes []byte) *StringBuilder

func (*StringBuilder) WriteTo

func (self *StringBuilder) WriteTo(writer io.Writer) (n int64, err error)

type StringSet

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

func (StringSet) Add

func (self StringSet) Add(val string)

func (StringSet) Contains

func (self StringSet) Contains(val string) bool

func (StringSet) Delete

func (self StringSet) Delete(val string)

type StringWriter

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

func (*StringWriter) Bool

func (self *StringWriter) Bool(value bool) *StringWriter

func (*StringWriter) Byte

func (self *StringWriter) Byte(value byte) *StringWriter

func (*StringWriter) Float

func (self *StringWriter) Float(value float64) *StringWriter

func (*StringWriter) Int

func (self *StringWriter) Int(value int) *StringWriter

func (*StringWriter) Printf

func (self *StringWriter) Printf(format string, args ...interface{}) *StringWriter

func (*StringWriter) Uint

func (self *StringWriter) Uint(value uint) *StringWriter

func (*StringWriter) Write

func (self *StringWriter) Write(strings ...string) *StringWriter

func (*StringWriter) WriteBytes

func (self *StringWriter) WriteBytes(bytes []byte) *StringWriter

type VersionTuple

type VersionTuple []int

func MakeVersionTuple

func MakeVersionTuple(fields ...int) VersionTuple

func ParseVersionTuple

func ParseVersionTuple(s string) (VersionTuple, error)

func (VersionTuple) GreaterEqual

func (self VersionTuple) GreaterEqual(other VersionTuple) bool

func (VersionTuple) String

func (self VersionTuple) String() string

type XMLWriter

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

func NewXMLWriter

func NewXMLWriter(writer io.Writer) *XMLWriter

func (*XMLWriter) Attrib

func (self *XMLWriter) Attrib(name string, value ...interface{}) *XMLWriter

value will be HTML escaped and concaternated

func (*XMLWriter) AttribFlag

func (self *XMLWriter) AttribFlag(name string, flag bool) *XMLWriter

AttribFlag writes a name="name" attribute if flag is true, else nothing will be written.

func (*XMLWriter) AttribIfNotDefault

func (self *XMLWriter) AttribIfNotDefault(name string, value interface{}) *XMLWriter

func (*XMLWriter) CloseTag

func (self *XMLWriter) CloseTag() *XMLWriter

func (*XMLWriter) CloseTagAlways

func (self *XMLWriter) CloseTagAlways() *XMLWriter

Creates an explicit close tag, even if there is no content

func (*XMLWriter) Content

func (self *XMLWriter) Content(s string) *XMLWriter

func (*XMLWriter) EscapeContent

func (self *XMLWriter) EscapeContent(s string) *XMLWriter

func (*XMLWriter) OpenTag

func (self *XMLWriter) OpenTag(tag string) *XMLWriter

func (*XMLWriter) Printf

func (self *XMLWriter) Printf(format string, args ...interface{}) *XMLWriter

func (*XMLWriter) PrintfEscape

func (self *XMLWriter) PrintfEscape(format string, args ...interface{}) *XMLWriter

func (*XMLWriter) Reset

func (self *XMLWriter) Reset()

func (*XMLWriter) Write

func (self *XMLWriter) Write(p []byte) (n int, err error)

implements io.Writer

func (*XMLWriter) WriteXMLDeclaration

func (self *XMLWriter) WriteXMLDeclaration() *XMLWriter

Jump to

Keyboard shortcuts

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