...

Package structs

import "simonwaldherr.de/go/golibs/structs"
Overview
Index
Examples

Overview ▾

func Reflect

func Reflect(sstruct interface{}) map[string]interface{}

Example

Code:

var lips LIPS
x := structs.Reflect(lips)

keys := []string{}
for k := range x {
    keys = append(keys, k)
}

sort.Strings(keys)
for _, k := range keys {
    fmt.Printf("key: %v, value: %v\n", k, x[k])
}

Output:

key: ARKTX, value: string
key: EANNR, value: string
key: LFIMG, value: string
key: LGORT, value: string
key: MATKL, value: string
key: MATNR, value: string
key: POSNR, value: string
key: VBELN, value: string
key: VKBUR, value: string
key: VRKME, value: string

func ReflectHelper

func ReflectHelper(v reflect.Value, t reflect.Type, depth int, handler func(string, string, interface{}, int)) map[string]interface{}

Example

Code:

var lips LIPS
v := reflect.ValueOf(lips)
t := reflect.TypeOf(lips)

structs.ReflectHelper(v, t, 0, func(name string, vtype string, value interface{}, depth int) {
    fmt.Printf("%v - %v - %v - %v\n", name, vtype, value, depth)
})

Output:

VBELN - string -  - 0
POSNR - string -  - 0
MATNR - string -  - 0
MATKL - string -  - 0
ARKTX - string -  - 0
EANNR - string -  - 0
LGORT - string -  - 0
LFIMG - string -  - 0
VRKME - string -  - 0
VKBUR - string -  - 0