Skip to content

Instantly share code, notes, and snippets.

@tonyyang-svail
Last active December 18, 2018 16:37
Show Gist options
  • Save tonyyang-svail/0ce49cf4e73bb7db122d5b5b01213461 to your computer and use it in GitHub Desktop.
Save tonyyang-svail/0ce49cf4e73bb7db122d5b5b01213461 to your computer and use it in GitHub Desktop.

:= is similar to var =

Setting GOPATH

export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin

:= slice is shallow copy

s := []string{"0", "1", "2"}
ss := s // shallow copy
sss := s[:2] // also shallow copy

:= array is deep copy

s := [3]string{"0", "1", "2"}
ss := s // deep copy

Verbose print

package main

import (
	"fmt"
)

func main() {
	type T struct {
		a int
		b float64
		c string
	}
	t := T{7, -2.35, "abc\tdef"}
	fmt.Printf("%#v\n", t) // prints main.T{a:7, b:-2.35, c:"abc\tdef"}
}

An interface type is defined as a set of method signatures. A value of interface type can hold any value that implements those methods. Under the hood, interface values can be thought of as a tuple of a value and a concrete type: (value, type)

To get all the dependency files: go get -d ./.... The pattern ./... means start in the current directory (./) and find all packages below that directory (...).

@helinwang
Copy link

:= array is deep copy

Array always deep copies, array is just a plain memory structure, no pointer involved.
This is a good read: https://blog.golang.org/go-slices-usage-and-internals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment