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 initialize a struct containing a slice of structs in Golang?
How to create Slice of Struct in Golang?
How to build a map of struct and append values to it?
Concurrently printing array elements using goroutines and channels
How to convert Struct fields into Map String?