Documentation ¶
Index ¶
- func Construct[O Object, FO Option[O] | OptionFunc[O]](obj O, opts ...FO) (O, error)
- func ConstructExtended[O ObjectExtended, FO OptionWithContext[O] | OptionFuncWithContext[O]](ctx context.Context, obj O, opts ...FO) (O, error)
- func ConstructWithContext[O Object, FO OptionWithContext[O] | OptionFuncWithContext[O]](ctx context.Context, obj O, opts ...FO) (O, error)
- func MustConstruct[O Object, FO Option[O] | OptionFunc[O]](obj O, opts ...FO) O
- func MustNew[O Object, FO Option[O] | OptionFunc[O]](opts ...FO) O
- func New[O Object, FO Option[O] | OptionFunc[O]](opts ...FO) (O, error)
- func NewExtended[O ObjectExtended, FO OptionWithContext[O] | OptionFuncWithContext[O]](ctx context.Context, opts ...FO) (O, error)
- func NewWithContext[O Object, FO OptionWithContext[O] | OptionFuncWithContext[O]](ctx context.Context, opts ...FO) (O, error)
- type Object
- type ObjectExtended
- type Option
- type OptionFunc
- type OptionFuncWithContext
- type OptionWithContext
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstructExtended ¶ added in v0.1.0
func ConstructExtended[ O ObjectExtended, FO OptionWithContext[O] | OptionFuncWithContext[O], ]( ctx context.Context, obj O, opts ...FO, ) (O, error)
func ConstructWithContext ¶
func ConstructWithContext[ O Object, FO OptionWithContext[O] | OptionFuncWithContext[O], ]( ctx context.Context, obj O, opts ...FO, ) (O, error)
func MustConstruct ¶
func MustNew ¶
Example ¶
ExampleMustNew describes basic flow - just construct object. Validation and initialization are on responsibility of an engineer.
var ( ctx = context.TODO() w bytes.Buffer ) opts := []MyStructOption{ WithW(&w), WithS("foobar"), WithI(100), } obj := MustNew(opts...) fmt.Printf("Is valid: %t\n", obj.Validate() == nil) fmt.Printf("Is inited: %t\n", obj.Init(ctx) == nil) fmt.Printf("%s\n", obj)
Output: Is valid: true Is inited: true foobar100
func NewExtended ¶ added in v0.1.0
func NewExtended[ O ObjectExtended, FO OptionWithContext[O] | OptionFuncWithContext[O], ]( ctx context.Context, opts ...FO, ) (O, error)
Example ¶
ExampleNewExtended describes flow guarantees that .Validate() and .Init() method succeed Methods must be present on generic type
var ( ctx = context.TODO() w bytes.Buffer ) opts := []MyStructOptionWithContext{ WithWCtx(&w), WithSCtx("foobar"), WithICtx(100), } obj, err := NewExtended(ctx, opts...) if err != nil { panic(err) } fmt.Printf("%s\n", obj)
Output: foobar100
func NewWithContext ¶
func NewWithContext[ O Object, FO OptionWithContext[O] | OptionFuncWithContext[O], ]( ctx context.Context, opts ...FO, ) (O, error)
Example ¶
ExampleNewWithContext describes flow where attributes requires ctx to be created. For example - http.Request as attribute
var ( ctx = context.TODO() w bytes.Buffer ) opts := []MyStructOptionWithContext{ WithWCtx(&w), WithSCtx("foobar"), WithICtx(100), } obj, err := NewWithContext(ctx, opts...) if err != nil { panic(err) } fmt.Printf("Is valid: %t\n", obj.Validate() == nil) fmt.Printf("Is inited: %t\n", obj.Init(ctx) == nil) fmt.Printf("%s\n", obj)
Output: Is valid: true Is inited: true foobar100
Types ¶
type ObjectExtended ¶ added in v0.1.0
type OptionFunc ¶
type OptionFuncWithContext ¶
Click to show internal directories.
Click to hide internal directories.