utils

package
v0.0.0-...-9012c6e Latest Latest
Warning

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

Go to latest
Published: May 22, 2012 License: MIT Imports: 17 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 CallMethod

func CallMethod(object interface{}, method string, args ...interface{}) (results []interface{}, err error)

func CallMethod1

func CallMethod1(object interface{}, method string, args ...interface{}) (result interface{}, err error)

func CombineDirs

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

func CompareStringsCaseInsensitive

func CompareStringsCaseInsensitive(a, b string) bool

func ConvertTimeString

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

func CopyExportedStructFields

func CopyExportedStructFields(src, dst interface{}) (copied int)

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(dir string) bool

func EscapeJSON

func EscapeJSON(jsonString string) string

func ExportedStructFields

func ExportedStructFields(s interface{}) map[string]interface{}

func FileExists

func FileExists(dir string) bool

func FileModifiedTime

func FileModifiedTime(filename string) (time int64, err 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 int64)

func FindFlattenedStructField

func FindFlattenedStructField(t reflect.Type, matchFunc MatchStructFieldFunc) *reflect.StructField

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 IsDeepNil

func IsDeepNil(i interface{}) bool

Non nil interfaces can wrap nil values. Comparing the interface to nil, won't return if the wrapped value is nil.

func IsDefaultValue

func IsDefaultValue(value interface{}) bool

func IsExportedName

func IsExportedName(name string) bool

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 NewInstance

func NewInstance(prototype interface{}) interface{}

Creates a new zero valued instance of prototype

func NewLineToHTML

func NewLineToHTML(text string) (html string)

func OwnIP

func OwnIP() string

func PrettifyJSON

func PrettifyJSON(compactJSON []byte) string

func ReadBytesFrom

func ReadBytesFrom(reader io.Reader) ([]byte, error)

func ReadStringFrom

func ReadStringFrom(reader io.Reader) (string, error)

func ReverseStringSlice

func ReverseStringSlice(slice []string)

func SliceDelete

func SliceDelete(slice []interface{}, index int, count int) (result []interface{})

func SliceInsert

func SliceInsert(slice []interface{}, index int, count int, value interface{}) (result []interface{})

func Sort

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

func StringEndsWith

func StringEndsWith(s string, start string) bool

func StringForStruct

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

Todo something more generic

func StringIn

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

func StringStartsWith

func StringStartsWith(s string, start string) bool

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 MatchStructFieldFunc

type MatchStructFieldFunc func(field *reflect.StructField) bool

type Sortable

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

Implements sort.Interface

func (*Sortable) Len

func (self *Sortable) Len() int

func (*Sortable) Less

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

func (*Sortable) Sort

func (self *Sortable) Sort()

func (*Sortable) Swap

func (self *Sortable) 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 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 XMLBuffer

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

func NewXMLBuffer

func NewXMLBuffer() *XMLBuffer

func (*XMLBuffer) String

func (self *XMLBuffer) 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) AttribIfNotDefault

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

func (*XMLWriter) CloseTag

func (self *XMLWriter) CloseTag() *XMLWriter

func (*XMLWriter) Content

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

func (*XMLWriter) EscapeContent

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

func (*XMLWriter) ExtraCloseTag

func (self *XMLWriter) ExtraCloseTag() *XMLWriter

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

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

Jump to

Keyboard shortcuts

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