package main
import (
"fmt"
)
func main() {
// slice of string
sl := []string{"one", "two"}
// make memory len(sl) for slice of interface
var sliceOfIntf []interface{} = make([]interface{}, len(sl))
// copy data from slice of string to slice of interface
for i, d := range sl {
sliceOfIntf[i] = d
}
// .... and slice of interface to interface
var intf interface{} = sliceOfIntf
// result print
fmt.Printf("Interface: %v\nInterface in real: %#v\n\n", intf, intf)
// How to get data?
fmt.Print("=== OUTPUT ===\n")
for k, v := range intf.([]interface{}) {
fmt.Printf("%v -> %v\n", k, v)
}
}
Created
January 17, 2017 12:46
-
-
Save velp/1c8f7cb0c2afa374428cf9067eba0596 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment