Created
April 7, 2021 12:31
-
-
Save e7/149af9faf4fa7c6112d09a8b42a719ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
type row struct { i, j int } | |
func main() { | |
aRow := row{} | |
// make a pointer to an empty slice | |
rowType := reflect.ValueOf(aRow).Type() | |
slicePtrVal := reflect.New(reflect.SliceOf(rowType)) | |
slicePtrIface := slicePtrVal.Interface() | |
// append a zero row to it | |
rowVal := reflect.Zero(rowType) | |
sliceVal := reflect.Indirect(slicePtrVal) | |
sliceVal.Set(reflect.Append(sliceVal, rowVal)) | |
fmt.Println(slicePtrIface) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment