extid

package
v0.70.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lookup

func Lookup[ID any](i interface{}) (id ID, ok bool)
Example
package main

import (
	"fmt"

	"github.com/adamluzsi/frameless/extid"
)

type Entity struct {
	ID string `ext:"id"`
}

func main() {
	ent := Entity{}

	_, ok := extid.Lookup[string](ent)
	fmt.Println(`found:`, ok) // false

	ent.ID = `42`
	id, ok := extid.Lookup[string](ent)
	fmt.Println(`found:`, ok)    // true
	fmt.Println(`id value:`, id) // "42"
}
Output:

func LookupStructField

func LookupStructField(ent interface{}) (reflect.StructField, reflect.Value, bool)

func Set

func Set(ptr interface{}, id interface{}) error
Example
package main

import (
	"fmt"

	"github.com/adamluzsi/frameless/extid"
)

type Entity struct {
	ID string `ext:"id"`
}

func main() {
	ent := Entity{}
	id := "id-value"

	if err := extid.Set(&ent, id); err != nil {
		panic(err)
	}

	fmt.Println(`ent.ID == id:`, ent.ID == id) // true
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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