pobj

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 6 Imported by: 2

README

GoDoc

pobj

Object library

Fetch argument

In v0.1, the first argument for Fetch was required to be a struct accepting a Id string value, however it is now possible for the Fetch method to take in a simple string argument.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownType   = errors.New("pobj: unknown object type")
	ErrMissingAction = errors.New("pobj: no such action exists")
)

Functions

func ById added in v0.1.0

func ById[T any](ctx context.Context, id string) (*T, error)

func Call deprecated added in v0.2.0

func Call[T any](s *typutil.Callable, ctx context.Context, arg ...any) (T, error)

Call calls the provided method and converts the result to the specified type

Deprecated: use typutil.Call instead

func RegisterActions

func RegisterActions[T any](name string, actions *ObjectActions)

RegisterActions is used for static REST methods such as get (factory) and list. Methods such as update and delete require an object.

func RegisterStatic

func RegisterStatic(name string, fn any)

RegisterStatic adds a static method to an object

func Static deprecated

func Static(method any) *typutil.Callable

Static returns a typutil.Callable object for a func that accepts a context.Context and/or a struct object that is its arguments.

Deprecated: use typutil.Func instead

Types

type Object

type Object struct {
	Action *ObjectActions
	// contains filtered or unexported fields
}

func Get added in v0.1.0

func Get(name string) *Object

Get returns the Object matching the given name, or nil if no such object exists

func GetByType added in v0.1.0

func GetByType[T any]() *Object

GetByType returns the Object matching the type given on the command line

func Register

func Register[T any](name string) *Object

Register adds the given object to the registry of name-instanciable objects

func Root

func Root() *Object

Root returns the root object holder

func (*Object) ById added in v0.1.1

func (o *Object) ById(ctx context.Context, id string) (any, error)

func (*Object) Child

func (o *Object) Child(name string) *Object

func (*Object) New

func (o *Object) New() any

New returns a new instance of the given object

func (*Object) Static

func (o *Object) Static(name string) *typutil.Callable

Static returns the given static method

func (*Object) String

func (o *Object) String() string

type ObjectActions

type ObjectActions struct {
	Fetch  *typutil.Callable // Fetch action receives "id" and returns an instance (factory)
	List   *typutil.Callable // List action returns a list of object
	Clear  *typutil.Callable // Clear action deletes all objects and returns nothing
	Create *typutil.Callable // Create action creates a new object and returns it
}

ObjectActions defines generic factories for usage in API calls

Jump to

Keyboard shortcuts

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