package main import ( "fmt" "reflect" ) func main() { var num int = 10 fmt.Println(reflect.TypeOf(num)) }
package main import ( "fmt" "reflect" ) type Person struct { Name string Age int } func main() { p := Person{Name: "John", Age: 25} v := reflect.ValueOf(&p).Elem() field := v.FieldByName("Name") if field.Kind() == reflect.String { field.SetString("Doe") } fmt.Println(p) }This code example uses the reflect package to set the value of a struct field. It creates a new instance of a `Person` struct, then uses the `reflect.ValueOf` function to get a `Value` object of the struct. We then get the `Name` field using `FieldByName`, check if it's a `string`, and set the value to `"Doe"`. The output will be `{Doe 25}`. The package library for `reflect.Value` is `reflect`.