util

package
v0.0.0-...-73e35a2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2017 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAStructPointer = errors.New("given interface is not a struct pointer")

ErrNotAStructPointer self explanatory

Functions

func FieldType

func FieldType(in interface{}, fieldName string) (reflect.Type, error)

FieldType takes a pointer to a struct and a field name, returns the type of the field in the struct.

func GetStringField

func GetStringField(in interface{}, fieldName string) (string, error)

GetStringField given a struct and a fieldName corresponding to a string value returns the string of the field. If field is not a string, will return string value of field.

func HasField

func HasField(in interface{}, fieldName string) bool

HasField returns true if given a struct that has a field by the name fieldName, returns false otherwise.

func Override

func Override(in interface{}, fieldName string, inval interface{}) error

Override takes a pointer to a struct, a field and a value, and overrides the field of the struct with the value.

func Shift

func Shift(slice []string) (head string, tail []string)

Shift returns the head and tail of a string slice, given an empty list it will return ("", nil).

func ShiftPath

func ShiftPath(p string) (head, tail string)

ShiftPath returns the head and tail of a string of form "a/b/c/d", in this case "a" and "/b/c/d"

func StringToType

func StringToType(value string, tpe reflect.Type) (interface{}, error)

StringToType will given a string and a type try to return a value of the given type derived from the string. not robust, only works for string, bool and int.

func TypeString

func TypeString(in interface{}) string

TypeString returns the name of the type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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