Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. ```go
  2. package main
  3.  
  4. import (
  5. "fmt"
  6. )
  7.  
  8. func main() {
  9. // slice of string
  10. sl := []string{"one", "two"}
  11. // make memory len(sl) for slice of interface
  12. var sliceOfIntf []interface{} = make([]interface{}, len(sl))
  13. // copy data from slice of string to slice of interface
  14. for i, d := range sl {
  15. sliceOfIntf[i] = d
  16. }
  17. // .... and slice of interface to interface
  18. var intf interface{} = sliceOfIntf
  19. // result print
  20. fmt.Printf("Interface: %v\nInterface in real: %#v\n\n", intf, intf)
  21.  
  22. // How to get data?
  23. fmt.Print("=== OUTPUT ===\n")
  24. for k, v := range intf.([]interface{}) {
  25. fmt.Printf("%v -> %v\n", k, v)
  26. }
  27. }
  28. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement