value

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 5 Imported by: 5

README

go-value

get value from struct with path

usage

	type object0 struct {
		A string
		B int
	}

	type object1 struct {
		C string
	}

	type object2 struct {
		D string
	}

	type object3 struct {
		object1

		o0 object0
		O0 object0

		O2 []object2
		O3 map[string]string
		O4 map[int]string
	}

	src := object3{
		object1: object1{
			C: "cccc",
		},
		o0: object0{
			A: "aaaa",
			B: -9999,
		},
		O0: object0{
			A: "AAAA",
			B: 999,
		},
		O2: []object2{
			{
				D: "D1",
			},
			{
				D: "D2",
			},
		},
		O3: map[string]string{
			"1": "O3 1",
		},
		O4: map[int]string{
			2: "O4 1",
		},
	}


  value.Get(src,"C") // cccc
  value.Get(src,"O0.A") // aaaa
  value.Get(src,"O2.0.D") // D1
  value.Get(src,"O3.1") // 03 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(v interface{}, name string) (interface{}, error)

func GetWithDefault added in v1.0.1

func GetWithDefault(v interface{}, name string, defaultValue interface{}) interface{}

func MustGet

func MustGet(v interface{}, name string) interface{}

Types

This section is empty.

Jump to

Keyboard shortcuts

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