mk

package
v0.235.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any]() *T

New will make a new T and call Init function recursively on it if it is implemented.

Example
package main

import (
	"go.llib.dev/frameless/pkg/mk"
)

func main() {
	v := mk.New[TypeWithInit]()

	_ = v
}

type TypeWithInit struct {
	V1  string
	V2  string
	Foo string
	Bar int
	Baz bool
}

func (v *TypeWithInit) Init() {
	v.V1 = "V1i"
	v.V2 = "V2i"
}
Example (Nested)
package main

import (
	"go.llib.dev/frameless/pkg/mk"
)

func main() {
	v := mk.New[NestedType]()
	_ = v        // initialised
	_ = v.Nested // initialised
}

type TypeWithInit struct {
	V1  string
	V2  string
	Foo string
	Bar int
	Baz bool
}

func (v *TypeWithInit) Init() {
	v.V1 = "V1i"
	v.V2 = "V2i"
}

type NestedType struct {
	V1     string
	Nested TypeWithInit
}

func (nt *NestedType) Init() {
	nt.V1 = "NT:" + nt.Nested.V1
}

func ReflectNew

func ReflectNew(typ reflect.Type) reflect.Value

ReflectNew will make a new T and call Init function recursively on it if it is implemented.

Types

This section is empty.

Jump to

Keyboard shortcuts

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