extid

package
v0.147.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lookup

func Lookup[ID any](ent any) (id ID, ok bool)
Example
package main

import (
	"fmt"

	"github.com/adamluzsi/frameless/ports/crud/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 RegisterType added in v0.127.0

func RegisterType[Entity, ID any](
	Get func(Entity) ID,
	Set func(*Entity, ID),
) any

func Set

func Set[ID any](ptr any, id ID) error
Example
package main

import (
	"fmt"

	"github.com/adamluzsi/frameless/ports/crud/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.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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