Documentation
¶
Overview ¶
Package setter allows for manipulation of a value of an exported field of any struct.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Set ¶
Set assigns the value `val` to the field `field` on the struct `strct`. Unexported fields are supported.
Example (ErrFieldDoesNotExists) ¶
package main
import (
"fmt"
"github.com/gomponents/gontainer-helpers/setter"
)
func main() {
person := struct {
name string
}{}
err := setter.Set(&person, "firstname", "Mary")
fmt.Println(err)
}
Output: set `*struct { name string }`."firstname": field `firstname` does not exist
Example (ErrNoPtr) ¶
package main
import (
"fmt"
"github.com/gomponents/gontainer-helpers/setter"
)
func main() {
person := struct {
name string
}{}
err := setter.Set(person, "name", "Mary")
fmt.Println(err)
}
Output: expected pointer to struct, struct given
Example (Ok) ¶
package main
import (
"fmt"
"github.com/gomponents/gontainer-helpers/setter"
)
func main() {
person := struct {
name string
}{}
err := setter.Set(&person, "name", "Mary")
fmt.Println(person.name)
fmt.Println(err)
}
Output: Mary <nil>
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.