structil

package module
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 6 Imported by: 2

README

structil PkgGoDev

Workflow Status Go Report Card Codecov MIT License

struct + util = structil, for runtime and dynamic environment in Go.

Why?

I'd like to ...

  • conveniently handle and decode the known or unknown formatted JSON/YAML
  • conveniently dive into the specific field in nested struct
  • simply verify if a field with the specified name and type exists in object
  • etc

with Go reflection package experimentally.

*** JSON and YAML format is known or unknown ***


JSON →→→→→→→→→→→→→→→→↓        →→ (known format)   struct  →→→→→→→→→→→↓→→→ (use struct directly)
                     ↓        ↑                                      ↓
                     ↓→→ map →→→ (unknown format) "DynamicStruct" →→→→→→ "Getter", "Finder"
                     ↑
YAML →→→→→→→→→→→→→→→→↑
                     ↑
(and other formats) →↑

Please see my medium post as well.

Sample Usecase

Try printing the struct definition from the unknown formatted JSON decoding.

package main

import (
	"fmt"

	"github.com/goldeneggg/structil/dynamicstruct/decoder"
)

func main() {
	unknownJSON := []byte(`
{
	"string_field":"かきくけこ",
	"int_field":45678,
	"bool_field":false,
	"object_field":{
		"id":12,
		"name":"the name",
		"nested_object_field": {
			"address": "Tokyo",
			"is_manager": true
		}
	},
	"array_string_field":[
		"array_str_1",
		"array_str_2"
	],
	"array_struct_field":[
		{
			"kkk":"kkk1",
			"vvvv":"vvv1"
		},
		{
			"kkk":"kkk2",
			"vvvv":"vvv2"
		}
	],
	"null_field":null
}
`)

  // create `Decoder` from JSON
  dec, err := decoder.FromJSON(unknownJSON)
  if err != nil {
    panic(err)
  }

  // - If `nest` is true, nested object attributes will be also decoded to struct recursively
  // - If `nest` is false, nested object attributes will be decoded to `map[string]interface{}`
  nest := true

  // - If `useTag` is true, JSON Struct tags are defined
  useTag := true

  // create `DynamicStruct` from `Decoder`
  ds, err := dec.DynamicStruct(nest, useTag)
  if err != nil {
    panic(err)
  }

  // print struct definition from `DynamicStruct`
  fmt.Println(ds.Definition())
}

This program will print a Go struct definition string as follows.

// - Type name is "DynamicStruct" (raname is available)
// - Field names are automatically camelized from input json attribute names
// - Fields are ordered by field name
type DynamicStruct struct {
        ArrayStringField []string `json:"array_string_field"`
        ArrayStructField []struct {
                Kkk string `json:"kkk"`
                Vvvv string `json:"vvvv"`
        } `json:"array_struct_field"`
        BoolField bool `json:"bool_field"`
        IntField float64 `json:"int_field"`
        NullField interface {} `json:"null_field"`
        ObjectField struct {
                Id float64 `json:"id"`
                Name string `json:"name"`
                NestedObjectField struct {
                        Address string `json:"address"`
                        IsManager bool `json:"is_manager"`
                } `json:"nested_object_field"`
        } `json:"object_field"`
        StringField string `json:"string_field"`
}

And see example code.

More Examples

From JSON to Getter

We can convert from the unknown formatted JSON to Getter via DynamicStruct with decoder.JSONToGetter function.

See example code.

What is Getter?

We can access a struct using field name string, like (typed) map with structil.NewGetter function.

g, err := structil.NewGetter(structOrStructPointerVariable)

// get num of struct fields
g.NumField()

// names of struct fields
g.Names()

// return true if struct has a "fName" field
g.Has(fName)

// get "fName" field value of the original struct as string 
g.String(fName)

// return true if "fName" field value of the original struct is float64
g.IsFloat64(fName)

// convert from struct to map[string]interface{}
g.ToMap()

// get as `Getter` if "fName" field is a (nested) struct
gNest, ok := g.GetGetter(fName)
gNest.NumField()
gNest.Names()

See example code

Getter.MapGet method

Getter.MapGet method provides the Map collection function for slice of struct

See example code

From JSON to DynamicStruct

We can convert from the unknown formatted JSON to DynamicStruct with Decoder (from decoder.FromJSON function) and Decoder.DynamicStruct method.

See example code.

What is DynamicStruct?

We can create the dynamic and runtime struct.

See example code

Finder

We can access usefully nested struct fields using field name string.

See example code

With config file? use FinderKeys

We can create a Finder from the configuration file that have some finding target keys. We support some file formats of configuration file such as yaml, json, toml and more.

See example code

Thanks for the awesome configuration management library spf13/viper.

Benchmark

See this file

It's the latest benchmark result that is executed on GitHub Actions runner instance.

Documentation

Index

Examples

Constants

View Source
const VERSION = "0.9.1"

VERSION says my version number

Variables

This section is empty.

Functions

This section is empty.

Types

type Finder

type Finder struct {
	// contains filtered or unexported fields
}

Finder is the struct that builds the nested struct finder. All methods are NOT goroutine safe yet (TODO:)

Example
type Group struct {
	Name string
	Boss string
}

type Company struct {
	Name    string
	Address string
	Period  int
	*Group
}

type School struct {
	Name          string
	GraduatedYear int
}

type Person struct {
	Name string
	Age  int
	*Company
	*School
}

i := &Person{
	Name: "Joe Davis",
	Age:  45,
	Company: &Company{
		Name:    "XXX Cars inc.",
		Address: "New York",
		Period:  20,
		Group: &Group{
			Name: "YYY Group Holdings",
			Boss: "Donald",
		},
	},
	School: &School{
		Name:          "ABC College",
		GraduatedYear: 1995,
	},
}

// 2nd argument is the separator string for nested field names separating
finder, err := NewFinderWithSep(i, ">")
// Note:
// If "NewFinder(i)" is called instead of "NewFinderWithSep", default separator "." is automatically used.
// finder, err := NewFinder(i)

if err != nil {
	panic(err)
}

// Finder provides method chain mechanism
m, err := finder.
	// Find(...string) returns a Finder that fields in NESTED struct are looked up by field name arguments.
	Find("School").
	// Into(...string) returns a Finder that NESTED struct fields are looked up by field name arguments.
	// This example looks up `person.Company.Address` field.
	Into("Company").Find("Address").
	// If multi arguments are assigned for Into method, then execute multi level nesting.
	// This example looks up `person.Company.Group.Name` and `person.Company.Group.Boss` fields.
	Into("Company", "Group").Find("Name", "Boss").
	// ToMap converts from found struct fields to map.
	ToMap()
if err != nil {
	panic(err)
}

fmt.Printf("%#v", m)
Output:

map[string]interface {}{"Company>Address":"New York", "Company>Group>Boss":"Donald", "Company>Group>Name":"YYY Group Holdings", "School":structil.School{Name:"ABC College", GraduatedYear:1995}}

func NewFinder

func NewFinder(i interface{}) (*Finder, error)

NewFinder returns a concrete Finder that uses and obtains from i. i must be a struct or struct pointer.

func NewFinderWithGetter

func NewFinderWithGetter(g *Getter) (*Finder, error)

NewFinderWithGetter returns a concrete Finder that uses and obtains from g. g must be a Getter

func NewFinderWithGetterAndSep

func NewFinderWithGetterAndSep(g *Getter, sep string) (*Finder, error)

NewFinderWithGetterAndSep returns a concrete Finder that uses and obtains from g using the separator string. g must be a Getter

func NewFinderWithSep

func NewFinderWithSep(i interface{}, sep string) (*Finder, error)

NewFinderWithSep returns a concrete Finder that uses and obtains from i using the separator string. i must be a struct or struct pointer.

func (*Finder) Error

func (f *Finder) Error() string

Error returns error string.

func (*Finder) Find

func (f *Finder) Find(names ...string) *Finder

Find returns a Finder that fields in struct are looked up and held named names.

func (*Finder) FindTop added in v0.2.0

func (f *Finder) FindTop(names ...string) *Finder

FindTop returns a Finder that top level fields in struct are looked up and held named names. Deprecated: planning to remove this method.

func (*Finder) FromKeys added in v0.2.0

func (f *Finder) FromKeys(fks *FinderKeys) *Finder

FromKeys returns a Finder that looked up by FinderKeys generated from configuration file.

Example (Json)
type Group struct {
	Name string
	Boss string
}

type Company struct {
	Name    string
	Address string
	Period  int
	*Group
}

type School struct {
	Name          string
	GraduatedYear int
}

type Person struct {
	Name string
	Age  int
	*Company
	*School
}

i := &Person{
	Name: "Joe Davis",
	Age:  45,
	Company: &Company{
		Name:    "XXX Cars inc.",
		Address: "New York",
		Period:  20,
		Group: &Group{
			Name: "YYY Group Holdings",
			Boss: "Donald",
		},
	},
	School: &School{
		Name:          "ABC College",
		GraduatedYear: 1995,
	},
}

// testdata/finder_from_conf/ex_json.json as follows:
//
// {
//   "Keys":[
//     {
//       "Company":[
//         {
//           "Group":[
//             "Name",
//             "Boss"
//           ]
//         },
//         "Address",
//         "Period"
//       ]
//     },
//     "Name",
//     "Age"
//   ]
// }
fks, err := NewFinderKeys("testdata/finder_from_conf", "ex_json")
if err != nil {
	panic(err)
}

finder, err := NewFinder(i)
if err != nil {
	panic(err)
}

m, err := finder.FromKeys(fks).ToMap()
if err != nil {
	panic(err)
}

fmt.Printf("%#v", m)
Output:

map[string]interface {}{"Age":45, "Company.Address":"New York", "Company.Group.Boss":"Donald", "Company.Group.Name":"YYY Group Holdings", "Company.Period":20, "Name":"Joe Davis"}
Example (Yml)
type Group struct {
	Name string
	Boss string
}

type Company struct {
	Name    string
	Address string
	Period  int
	*Group
}

type School struct {
	Name          string
	GraduatedYear int
}

type Person struct {
	Name string
	Age  int
	*Company
	*School
}

i := &Person{
	Name: "Joe Davis",
	Age:  45,
	Company: &Company{
		Name:    "XXX Cars inc.",
		Address: "New York",
		Period:  20,
		Group: &Group{
			Name: "YYY Group Holdings",
			Boss: "Donald",
		},
	},
	School: &School{
		Name:          "ABC College",
		GraduatedYear: 1995,
	},
}

// testdata/finder_from_conf/ex_yml.yml as follows:
//
// Keys:
//   - Company:
//     - Group:
//       - Name
//       - Boss
//     - Address
//     - Period
//   - Name
//   - Age

// Get `FinderKeys` object by calling `NewFinderKeys` with config file dir and baseName
// This config file path is "testdata/finder_from_conf/ex_json.json"
fks, err := NewFinderKeys("testdata/finder_from_conf", "ex_yml")
if err != nil {
	panic(err)
}

finder, err := NewFinder(i)
if err != nil {
	panic(err)
}

// And build `Finder` object using `FromKeys` method with `FinderKeys` object
// This returns the same result as follows:
//
// finder = finder.Find("Name", "Age").
//   Into("Company").Find("Address", "Period").
//   Into("Company", "Group").Find("Name", "Boss")
m, err := finder.FromKeys(fks).ToMap()
if err != nil {
	panic(err)
}

fmt.Printf("%#v", m)
Output:

map[string]interface {}{"Age":45, "Company.Address":"New York", "Company.Group.Boss":"Donald", "Company.Group.Name":"YYY Group Holdings", "Company.Period":20, "Name":"Joe Davis"}

func (*Finder) GetNameSeparator

func (f *Finder) GetNameSeparator() string

GetNameSeparator returns the separator string for nested struct name separating. Default is "." (dot).

func (*Finder) HasError

func (f *Finder) HasError() bool

HasError tests whether this Finder have any errors.

func (*Finder) Into

func (f *Finder) Into(names ...string) *Finder

Into returns a Finder that nested struct fields are looked up and held named names.

func (*Finder) Reset

func (f *Finder) Reset() *Finder

Reset resets the current build Finder.

func (*Finder) ToMap

func (f *Finder) ToMap() (map[string]interface{}, error)

ToMap returns a map converted from struct. Map keys are lookup field names by "Into" method and "Find". Map values are lookup field values by "Into" method and "Find".

type FinderKeys added in v0.2.0

type FinderKeys struct {
	// contains filtered or unexported fields
}

FinderKeys is the struct that have keys for Finder.

func NewFinderKeys added in v0.3.1

func NewFinderKeys(dir string, baseName string) (*FinderKeys, error)

NewFinderKeys returns a FinderKeys object that is created from configuration file indicated by dir and name file.

func (*FinderKeys) Keys added in v0.2.0

func (fks *FinderKeys) Keys() []string

Keys returns keys

func (*FinderKeys) Len added in v0.2.0

func (fks *FinderKeys) Len() int

Len returns length of FinderKeys

type Getter

type Getter struct {
	// contains filtered or unexported fields
}

Getter is the struct that wraps the basic Getter method.

Example
type Company struct {
	Name    string
	Address string
	Period  int
}

type Person struct {
	Name string
	Age  int
	*Company
}

i := &Person{
	Name: "Tony",
	Age:  25,
	Company: &Company{
		Name:    "Tiger inc.",
		Address: "Tokyo",
		Period:  3,
	},
}

// i must be a struct or struct pointer
getter, err := NewGetter(i)
if err != nil {
	panic(err)
}

name, _ := getter.String("Name")    // get as string
age, _ := getter.Int("Age")         // get as int
company, _ := getter.Get("Company") // get as interface{}

fmt.Printf(
	"num of fields=%d\nfield names=%v\n'Name'=%s\n'Age'=%d\n'Company'=%+v",
	getter.NumField(), // get num of fields
	getter.Names(),    // get field names
	name,
	age,
	company,
)
Output:

num of fields=3
field names=[Name Age Company]
'Name'=Tony
'Age'=25
'Company'={Name:Tiger inc. Address:Tokyo Period:3}

func NewGetter

func NewGetter(i interface{}) (*Getter, error)

NewGetter returns a concrete Getter that uses and obtains from i. i must be a struct or struct pointer.

func (*Getter) Bool

func (g *Getter) Bool(name string) (bool, bool)

Bool returns the byte of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not bool.

func (*Getter) Byte

func (g *Getter) Byte(name string) (byte, bool)

Byte returns the byte of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not byte.

func (*Getter) Bytes

func (g *Getter) Bytes(name string) ([]byte, bool)

Bytes returns the []byte of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not []byte.

func (*Getter) Complex128 added in v0.4.0

func (g *Getter) Complex128(name string) (complex128, bool)

Complex128 returns the complex128 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not complex128.

func (*Getter) Complex64 added in v0.4.0

func (g *Getter) Complex64(name string) (complex64, bool)

Complex64 returns the complex64 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not complex64.

func (*Getter) Float32 added in v0.4.0

func (g *Getter) Float32(name string) (float32, bool)

Float32 returns the float32 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not float32.

func (*Getter) Float64

func (g *Getter) Float64(name string) (float64, bool)

Float64 returns the float64 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not float64.

func (*Getter) Get

func (g *Getter) Get(name string) (interface{}, bool)

Get returns the interface of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field.

func (*Getter) GetGetter added in v0.8.0

func (g *Getter) GetGetter(name string) (*Getter, bool)

GetGetter returns the Getter of interface of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not struct or struct pointer.

func (*Getter) GetType

func (g *Getter) GetType(name string) (reflect.Type, bool)

GetType returns the reflect.Type object of the original struct field named "name". 2nd return value will be false if the original struct does not have a "name" field.

func (*Getter) GetValue

func (g *Getter) GetValue(name string) (reflect.Value, bool)

GetValue returns the reflect.Value object of the original struct field named "name". 2nd return value will be false if the original struct does not have a "name" field.

func (*Getter) Has

func (g *Getter) Has(name string) bool

Has tests whether the original struct has a field named "name".

func (*Getter) Int

func (g *Getter) Int(name string) (int, bool)

Int returns the int of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not int.

func (*Getter) Int16 added in v0.4.0

func (g *Getter) Int16(name string) (int16, bool)

Int16 returns the int16 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not int16.

func (*Getter) Int32 added in v0.4.0

func (g *Getter) Int32(name string) (int32, bool)

Int32 returns the int32 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not int32.

func (*Getter) Int64

func (g *Getter) Int64(name string) (int64, bool)

Int64 returns the int64 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not int64.

func (*Getter) Int8 added in v0.4.0

func (g *Getter) Int8(name string) (int8, bool)

Int8 returns the int8 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not int8.

func (*Getter) IsArray added in v0.4.0

func (g *Getter) IsArray(name string) bool

IsArray reports whether type of the original struct field named name is slice.

func (*Getter) IsBool

func (g *Getter) IsBool(name string) bool

IsBool reports whether type of the original struct field named name is bool.

func (*Getter) IsByte

func (g *Getter) IsByte(name string) bool

IsByte reports whether type of the original struct field named name is byte.

func (*Getter) IsBytes

func (g *Getter) IsBytes(name string) bool

IsBytes reports whether type of the original struct field named name is []byte.

func (*Getter) IsChan

func (g *Getter) IsChan(name string) bool

IsChan reports whether type of the original struct field named name is chan.

func (*Getter) IsComplex128 added in v0.4.0

func (g *Getter) IsComplex128(name string) bool

IsComplex128 reports whether type of the original struct field named name is []byte.

func (*Getter) IsComplex64 added in v0.4.0

func (g *Getter) IsComplex64(name string) bool

IsComplex64 reports whether type of the original struct field named name is []byte.

func (*Getter) IsFloat32 added in v0.4.0

func (g *Getter) IsFloat32(name string) bool

IsFloat32 reports whether type of the original struct field named name is float32.

func (*Getter) IsFloat64

func (g *Getter) IsFloat64(name string) bool

IsFloat64 reports whether type of the original struct field named name is float64.

func (*Getter) IsFunc

func (g *Getter) IsFunc(name string) bool

IsFunc reports whether type of the original struct field named name is func.

func (*Getter) IsInt

func (g *Getter) IsInt(name string) bool

IsInt reports whether type of the original struct field named name is int.

func (*Getter) IsInt16 added in v0.4.0

func (g *Getter) IsInt16(name string) bool

IsInt16 reports whether type of the original struct field named name is int16.

func (*Getter) IsInt32 added in v0.4.0

func (g *Getter) IsInt32(name string) bool

IsInt32 reports whether type of the original struct field named name is int32.

func (*Getter) IsInt64

func (g *Getter) IsInt64(name string) bool

IsInt64 reports whether type of the original struct field named name is int64.

func (*Getter) IsInt8 added in v0.4.0

func (g *Getter) IsInt8(name string) bool

IsInt8 reports whether type of the original struct field named name is int8.

func (*Getter) IsMap

func (g *Getter) IsMap(name string) bool

IsMap reports whether type of the original struct field named name is map.

func (*Getter) IsSlice

func (g *Getter) IsSlice(name string) bool

IsSlice reports whether type of the original struct field named name is slice.

func (*Getter) IsString

func (g *Getter) IsString(name string) bool

IsString reports whether type of the original struct field named name is string.

func (*Getter) IsStruct

func (g *Getter) IsStruct(name string) bool

IsStruct reports whether type of the original struct field named name is struct.

func (*Getter) IsUint

func (g *Getter) IsUint(name string) bool

IsUint reports whether type of the original struct field named name is uint.

func (*Getter) IsUint16 added in v0.4.0

func (g *Getter) IsUint16(name string) bool

IsUint16 reports whether type of the original struct field named name is uint16.

func (*Getter) IsUint32 added in v0.4.0

func (g *Getter) IsUint32(name string) bool

IsUint32 reports whether type of the original struct field named name is uint32.

func (*Getter) IsUint64

func (g *Getter) IsUint64(name string) bool

IsUint64 reports whether type of the original struct field named name is uint64.

func (*Getter) IsUint8 added in v0.4.0

func (g *Getter) IsUint8(name string) bool

IsUint8 reports whether type of the original struct field named name is uint8.

func (*Getter) IsUintptr added in v0.4.0

func (g *Getter) IsUintptr(name string) bool

IsUintptr reports whether type of the original struct field named name is uintptr.

func (*Getter) IsUnsafePointer added in v0.4.0

func (g *Getter) IsUnsafePointer(name string) bool

IsUnsafePointer reports whether type of the original struct field named name is []byte.

func (*Getter) MapGet

func (g *Getter) MapGet(name string, f func(int, *Getter) (interface{}, error)) ([]interface{}, error)

MapGet returns the interface slice of mapped values of the original struct field named name.

Example
type Company struct {
	Name    string
	Address string
	Period  int
}

type Person struct {
	Name      string
	Age       int
	Companies []*Company
}

i := &Person{
	Name: "Tony",
	Age:  25,
	Companies: []*Company{
		{
			Name:    "Tiger inc.",
			Address: "Tokyo",
			Period:  3,
		},
		{
			Name:    "Dragon inc.",
			Address: "Osaka",
			Period:  4,
		},
	},
}

getter, err := NewGetter(i)
if err != nil {
	panic(err)
}

// Each of "Companies" field are applied map function as follows.
fn := func(i int, g *Getter) (interface{}, error) {
	period, _ := g.Int("Period")
	name, _ := g.String("Name")

	return fmt.Sprintf(
		"You worked for %d years since you joined the company %s",
		period,
		name,
	), nil
}

// 1st argeument must be a field name of array or slice field.
// function assigned 2nd argument is applied each "Companies" element.
intfs, err := getter.MapGet("Companies", fn)
if err != nil {
	panic(err)
}

fmt.Printf("%#v", intfs)
Output:

[]interface {}{"You worked for 3 years since you joined the company Tiger inc.", "You worked for 4 years since you joined the company Dragon inc."}

func (*Getter) Names added in v0.4.3

func (g *Getter) Names() []string

Names returns names of struct field.

func (*Getter) NumField

func (g *Getter) NumField() int

NumField returns num of struct field.

func (*Getter) Slice added in v0.8.0

func (g *Getter) Slice(name string) ([]interface{}, bool)

Slice returns the slice of interface of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not slice of interface.

func (*Getter) String

func (g *Getter) String(name string) (string, bool)

String returns the string of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not string.

func (*Getter) ToMap added in v0.8.0

func (g *Getter) ToMap() map[string]interface{}

ToMap returns a map converted from this Getter.

func (*Getter) Uint

func (g *Getter) Uint(name string) (uint, bool)

Uint returns the uint of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not uint.

func (*Getter) Uint16 added in v0.4.0

func (g *Getter) Uint16(name string) (uint16, bool)

Uint16 returns the uint16 of the original struct field named name.Getter 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not uint16.

func (*Getter) Uint32 added in v0.4.0

func (g *Getter) Uint32(name string) (uint32, bool)

Uint32 returns the uint32 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not uint32.

func (*Getter) Uint64

func (g *Getter) Uint64(name string) (uint64, bool)

Uint64 returns the uint64 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not uint64.

func (*Getter) Uint8 added in v0.4.0

func (g *Getter) Uint8(name string) (uint8, bool)

Uint8 returns the uint8 of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not uint8.

func (*Getter) Uintptr added in v0.4.0

func (g *Getter) Uintptr(name string) (uintptr, bool)

Uintptr returns the uintptr of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not uintptr.

func (*Getter) UnsafePointer added in v0.4.0

func (g *Getter) UnsafePointer(name string) (unsafe.Pointer, bool)

UnsafePointer returns the unsafe.Pointer of the original struct field named name. 2nd return value will be false if the original struct does not have a "name" field. 2nd return value will be false if type of the original struct "name" field is not unsafe.Pointer.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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