Documentation
¶
Overview ¶
run a function for each ...
Index ¶
- func Array(arr interface{}, handler func(int, interface{}, int))
- func Dir(dirname string, recursive bool, ...) error
- func File(dirname string, recursive bool, ...) error
- func JSON(str string, handler func(*string, *int, *interface{}, int)) error
- func Struct(sstruct interface{}, handler func(string, string, interface{}, int))
- func XML(str string, handler func(*string, *int, *interface{}, int)) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func File ¶
func File(dirname string, recursive bool, fnc func(string, string, string, bool, os.FileInfo)) error
File runs a function for each file in a directory
func Struct ¶
Struct runs a function for each element of a struct
Example ¶
package main import ( "fmt" "simonwaldherr.de/go/golibs/foreach" ) type Foobar struct { X int Y int } type Foo struct { Id int Name string Lorem Foobar Ipsum interface{} Query func() } func main() { foreach.Struct(Foo{ Id: 5, Name: "Foobar", Lorem: Foobar{ X: 42, Y: 23, }, Ipsum: float64(2), Query: func() { fmt.Println("---") }, }, func(key string, index string, value interface{}, depth int) { fmt.Printf("name: %v, type: %v, depth: %v\n", key, index, depth) }) }
Output: name: Id, type: int, depth: 0 name: Name, type: string, depth: 0 name: Lorem, type: foreach_test.Foobar, depth: 0 name: X, type: int, depth: 1 name: Y, type: int, depth: 1 name: Ipsum, type: interface {}, depth: 0 name: Query, type: func(), depth: 0
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.