structs

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reflect

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

import (
	"fmt"
	"simonwaldherr.de/go/golibs/structs"
	"sort"
)

type LIPS struct {
	VBELN string
	POSNR string
	MATNR string
	MATKL string
	ARKTX string
	EANNR string
	LGORT string
	LFIMG string
	VRKME string
	VKBUR string
}

func main() {
	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
package main

import (
	"fmt"
	"reflect"
	"simonwaldherr.de/go/golibs/structs"
)

type LIPS struct {
	VBELN string
	POSNR string
	MATNR string
	MATKL string
	ARKTX string
	EANNR string
	LGORT string
	LFIMG string
	VRKME string
	VKBUR string
}

func main() {
	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

Types

This section is empty.

Jump to

Keyboard shortcuts

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