Skip to content

Instantly share code, notes, and snippets.

View wesleymatosdev's full-sized avatar

wesleymatosdev

View GitHub Profile
// _Maps_ are Go's built-in [associative data type](http://en.wikipedia.org/wiki/Associative_array)
// (sometimes called _hashes_ or _dicts_ in other languages).
package main
import "fmt"
func main() {
// To create an empty map, use the builtin `make`:
m := map[string]int{"key": 1}
element, ok := m['key']
delete(m, 'key')
element = m['key']
m := make(map[string]int)
package main
import "fmt"
func main() {
s := []int{2, 3, 5, 7, 11, 13}
printSlice(s)
// Slice the slice to give it zero length.
s = s[:0]
package main
import "fmt"
func main() {
var m map[string]int
if m == nil {
fmt.Println("Map is nil")
}
package main
import "fmt"
func main() {
var s []int
fmt.Println(s, len(s), cap(s))
if s == nil {
fmt.Println("nil!")
}