 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lookup ¶
Example ¶
package main
import (
	"fmt"
	"go.llib.dev/frameless/port/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"
}
func RegisterType ¶
Types ¶
type MappingFunc ¶ added in v0.238.0
type MappingFunc[ENT, ID any] func(*ENT) *ID
MappingFunc is a function that allows the id lookup on an entity type. The returned id pointer will be used to Lookup its value, or to set new value to this ID pointer. Its functions will panic if func is provided, but it returns a nil pointer, as it is considered as implementation error.
Example implementation:
extid.MappingFunc[Foo, FooID](func(v Foo) *FooID { return &v.ID })
default: extid.Lookup, extid.Set, which will use either the `ext:"id"` tag, or the `ENT.ID()` & `ENT.SetID()` methods.
func (MappingFunc[ENT, ID]) Lookup ¶ added in v0.238.0
func (fn MappingFunc[ENT, ID]) Lookup(ent ENT) (ID, bool)
func (MappingFunc[ENT, ID]) Set ¶ added in v0.238.0
func (fn MappingFunc[ENT, ID]) Set(ent *ENT, id ID) error
 Click to show internal directories. 
   Click to hide internal directories.