pobj

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 5 Imported by: 2

README

GoDoc

pobj

Object library

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterActions

func RegisterActions(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

Types

type Object

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

func Register

func Register(name string, obj any) *Object

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

func Root

func Root() *Object

func (*Object) Child

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

func (*Object) New

func (o *Object) New() any

func (*Object) Static

func (o *Object) Static(name string) *StaticMethod

func (*Object) String

func (o *Object) String() string

type ObjectActions

type ObjectActions struct {
	Fetch *StaticMethod // Fetch action receives "id" and returns an instance (factory)
	List  *StaticMethod // List action returns a list of object
}

ObjectActions defines generic factories for usage in API calls

type StaticMethod

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

func Static

func Static(method any) *StaticMethod

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

func (*StaticMethod) Call

func (s *StaticMethod) Call(ctx context.Context) (any, error)

func (*StaticMethod) CallArg

func (s *StaticMethod) CallArg(ctx context.Context, arg any) (any, error)

Jump to

Keyboard shortcuts

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