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 program for implementation of Radix Sort
GO Program to Find Factorial of a Number
GO language program with example of Sort Functions for integer, strings and float64 data type
GO Program to print full Pyramid using *
How do you send an HTTP PATCH request in Go?
How to create an empty Slice in Golang?
How do you handle HTTP server health checks in Go?
Go program to find Forward(A) record of a domain
Golang program for implementation of Shell Sort
Go program to find TXT records of a domain