Skip to content

Instantly share code, notes, and snippets.

@velp
Created January 17, 2017 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velp/1c8f7cb0c2afa374428cf9067eba0596 to your computer and use it in GitHub Desktop.
Save velp/1c8f7cb0c2afa374428cf9067eba0596 to your computer and use it in GitHub Desktop.
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)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment