creational

package
v0.8.53 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Construct

func Construct[
	O Object,
	FO Option[O] | optionAlias[O],
](
	obj O,
	opts ...FO,
) (O, error)

func ConstructWithContext

func ConstructWithContext[
	O Object,
	FO OptionWithContext[O] | optionWithContextAlias[O],
](
	ctx context.Context,
	obj O,
	opts ...FO,
) (O, error)

func ConstructWithContextValidate added in v0.3.0

func ConstructWithContextValidate[
	O ObjectValidable,
	FO OptionWithContext[O] | optionWithContextAlias[O],
](
	ctx context.Context,
	obj O,
	opts ...FO,
) (O, error)

func ConstructWithValidate added in v0.3.0

func ConstructWithValidate[
	O ObjectValidable,
	FO Option[O] | optionAlias[O],
](
	obj O,
	opts ...FO,
) (O, error)

func Must added in v0.8.0

func Must[T any](t T, err error) T

func MustNew

func MustNew[
	O Object,
	FO Option[O] | optionAlias[O],
](
	opts ...FO,
) O

func New

func New[
	O Object,
	FO Option[O] | optionAlias[O],
](
	opts ...FO,
) (O, error)
Example

ExampleNew just configures object - no validate applied

opts := []WorkerOption{
	WithW(invalidW), nil,
	WithS(invalidS), nil,
	WithI(invalidI), nil,
}

obj, err := New(opts...)
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", obj)
Output:

s=lolkek;i=999;w_is_nil=true;is_valid=false;

func NewWithContext

func NewWithContext[
	O Object,
	FO OptionWithContext[O] | optionWithContextAlias[O],
](
	ctx context.Context,
	opts ...FO,
) (O, error)
Example

ExampleNewWithContext just configures object - no validate applied. Also ctx is required For example - http.Request as struct attribute

ctx := context.TODO()

opts := []WorkerOptionWithContext{
	WithWCtx(invalidW), nil,
	WithSCtx(invalidS), nil,
	WithICtx(invalidI), nil,
}

obj, err := NewWithContext(ctx, opts...)
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", obj)
Output:

s=lolkek;i=999;w_is_nil=true;is_valid=false;

func NewWithContextValidate added in v0.3.0

func NewWithContextValidate[
	O ObjectValidable,
	FO OptionWithContext[O] | optionWithContextAlias[O],
](
	ctx context.Context,
	opts ...FO,
) (O, error)
Example

ExampleNewWithContextValidate configures and validates object. Also ctx is required For example - http.Request as struct attribute

ctx := context.TODO()

opts := []WorkerOptionWithContext{
	WithWCtx(validW), nil,
	WithSCtx(validS), nil,
	WithICtx(validI), nil,
}

obj, err := NewWithContextValidate(ctx, opts...)
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", obj)
Output:

s=foobar;i=100500;w_is_nil=false;is_valid=true;

func NewWithValidate added in v0.3.0

func NewWithValidate[
	O ObjectValidable,
	FO Option[O] | optionAlias[O],
](
	opts ...FO,
) (O, error)
Example

ExampleNewWithValidate configures and validates object

opts := []WorkerOption{
	WithW(validW), nil,
	WithS(validS), nil,
	WithI(validI), nil,
}

obj, err := NewWithValidate(opts...)
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", obj)
Output:

s=foobar;i=100500;w_is_nil=false;is_valid=true;

Types

type Object

type Object interface{ any }

type ObjectValidable added in v0.3.0

type ObjectValidable interface{ Validate() error }

type Option

type Option[O Object] func(*O) error

type OptionWithContext

type OptionWithContext[O Object] func(context.Context, *O) error

Jump to

Keyboard shortcuts

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