package
0.0.0-20200307222426-973ca76dd17c
Repository: https://github.com/at-ishikawa/samples.git
Documentation: pkg.go.dev
# README
Spec
function
- Multiple values can be returned
defer
- defer works first-in-last-out
slice
make
is used to have the size of variable.make([]int, size)
- To implement like foreach,
for index, element := range slice
can be used
map
- Declaration:
m := map[string]int{}
method
- The receiver can be pointer or value. All methods should have the either pointer or value for a type.
- interfaces can be implemented implicitly.
- A receiver can be nil in a method
- The empty inteface
interface{}
can be used for unknown type. - Type assertion
var.(T)
. See type-switches.go
Standard interface
- Stringers to println in fmt.
type Stringer interface {
String() string
}
- Error interface, used such as fmt
type error interface {
Error() string
}
Go routine
- By
make(chan int, bufferSize int)
, channels can be created. - Receive values by
channel <- v
- The values can be received by loop
for i := range channel
close
should be closed by a senderselect
is wait on multiple operations. See select.go for more details Note that if default case is presented, select does not wait but run in a defaultsync.Mutex
andLock/Unlock
is used when no communication is required
# Constants
No description provided by the author