How to append struct member dynamically using Empty Interface?
Example
package main
import (
"fmt"
)
type Before struct {
m string
}
func append(b interface{}) interface{} {
return struct {
Before
n string
}{b.(Before), "rest"}
}
func main() {
b := Before{"test"}
a := append(b)
fmt.Println(a)
}
{{test} rest}
Most Helpful This Week
Golang panic recover example
How to check specific field exist in struct?
Concurrently printing array elements using goroutines and channels
How to initialize a struct containing a slice of structs in Golang?
How do you catch panic in Golang?
How to build a map of struct and append values to it?
How to create Slice of Struct in Golang?
How to convert Struct fields into Map String?