Code commentary

This commit is contained in:
Ahsanul Haque
2014-12-13 11:05:43 +06:00
committed by spf13
parent 4745f1fd64
commit e1e66f7b4e
2 changed files with 13 additions and 6 deletions

View File

@ -31,12 +31,16 @@ var initializers []func()
// Set this to true to enable it
var EnablePrefixMatching bool = false
//OnInitialize takes a series of func() arguments and appends them to a slice of func().
func OnInitialize(y ...func()) {
for _, x := range y {
initializers = append(initializers, x)
}
}
//Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans,
//Maps and Slices, Gt will compare their lengths. Ints are compared directly while strings are first parsed as
//ints and then compared.
func Gt(a interface{}, b interface{}) bool {
var left, right int64
av := reflect.ValueOf(a)
@ -64,6 +68,7 @@ func Gt(a interface{}, b interface{}) bool {
return left > right
}
//Eq takes two types and checks whether they are equal. Supported types are int and string. Unsupported types will panic.
func Eq(a interface{}, b interface{}) bool {
av := reflect.ValueOf(a)
bv := reflect.ValueOf(b)
@ -79,6 +84,7 @@ func Eq(a interface{}, b interface{}) bool {
return false
}
//rpad adds padding to the right of a string
func rpad(s string, padding int) string {
template := fmt.Sprintf("%%-%ds", padding)
return fmt.Sprintf(template, s)