Golang reflect.Copy() function example
package reflect
Golang reflect.Copy() function usage example
package main
import (
"fmt"
"reflect"
)
func main() {
oldSlice := []string{"abc", "def"}
newSlice := []string{"efg", "hij", "klm"}
// will overwrite "efg" and "hij"
var n = reflect.Copy(reflect.ValueOf(newSlice), reflect.ValueOf(oldSlice))
fmt.Printf("Copied %d elements.\n", n)
fmt.Printf("newSlice elements are now : %v \n", newSlice)
}
Reference :
Advertisement
Something interesting
Tutorials
+35.5k Golang : Smarter Error Handling with strings.Contains()
+6.2k Golang : Calculate US Dollar Index (DXY)
+25.4k Golang : Generate MD5 checksum of a file
+9.1k Golang : Intercept and compare HTTP response code example
+14.6k Golang : Execute function at intervals or after some delay
+10.4k Golang : Generate random integer or float number
+17k Golang : XML to JSON example
+6.7k Golang : When to use make or new?
+9.7k Random number generation with crypto/rand in Go
+10.9k Golang : Removes punctuation or defined delimiter from the user's input
+19.6k Golang : Set or Add HTTP Request Headers
+20.9k PHP : Convert(cast) int to double/float