Golang reflect.MakeMap() function example
package reflect
Golang reflect.MakeMap() function usage example
package main
import (
"fmt"
"reflect"
)
func main() {
var str map[int]string // must be a map type for reflect.MakeMap() to work
var strValue reflect.Value = reflect.ValueOf(&str)
indirectStr := reflect.Indirect(strValue)
valueMap := reflect.MakeMap(indirectStr.Type()) // otherwise, will panice
fmt.Printf("valueMap type is [%v] .", valueMap.Kind())
}
Output :
valueMap type is [map] .
Reference :
Advertisement
Something interesting
Tutorials
+12.3k Golang : Get month name from date example
+7.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+4.4k Golang : Valued expressions and functions example
+10.2k Golang : Text file editor (accept input from screen and save to file)
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+9k Golang : Get SPF and DMARC from email headers to fight spam
+16.8k Golang : read gzipped http response
+17.4k Golang : Multi threading or run two processes or more example
+11.1k Golang : Read until certain character to break for loop
+6.1k Golang : Measure execution time for a function
+9.1k Golang : Intercept and compare HTTP response code example