Go - Structs - 5
Comparable struct can be a key of a map. (What will happen when struct value changed?) Can declare a named struct type in another struct as field ...
Comparable struct can be a key of a map. (What will happen when struct value changed?) Can declare a named struct type in another struct as field ...
Shorthand notation to create and initialize a struct variable Ex. pp := &Point{1,2} It’s same as pp := new(Point) *pp = Point{1,2} If all f...
A struct can be declared to require client need assign values to each fields with right order. Such pattern will be hard to maintain in the future...
A named type S CAN NOT declare a field with the same type S, but it can contains a field with type *S, for recursive data structure Zero struct field...
Declared: map[KeyType]ValueType Ex. m := make(map[string]int) m["a"]=1 m{"b"]=2 Ex. m := map[string]int { "a":1, "b":2,...
Slices contains many example images, causes I can’t save in Blogger in one article. So I split to 3 parts. Go - Slices (1/3) Go - Slices (2/3) Go - Slices (...
Ex. Slice is in the middle of an array, what will happen in that array after append? => Array value will reflect slice change, but array instance will ...
Slice is NOT comparable Standard library provide a way to compare 2 byte slices Reference type such as pointers and channels, the == test whether...
Slice is declared as "var s []T" Declare a slice by make([]int,length,capacity) Slice looks like an array without size Pointer: point to the first eleme...
We use Cassandra 2.0.17. Sometimes we suffer IO problem in system, we can use "iotop" to know process IO loading. But sometimes we need more detail, such a...
Declare an array Ex. var a [3]int a[0] len(a) for idx, v range a {} for _, v range a ,{} Declare with specified values. Default value is ...
Just some ways to declare const
Boolean bool boolean Strings Conventionally UTF-8 Built-in function len returns the number of bytes, not runes in a string Detect length of s...
float float32, max value: math.MaxFloat32 float64, max value: math.MaxFloat64 float can be printed by fmt package %e: exponent %f: no ex...
int8 int16 int32 int64 uint8 uint16 uint32 uint64 int uint : natural and most efficient size on a particular platform. Different compiler may choose di...
Syntactic block: Enclosed in braces Lexical block: Not explicitly surrounded by braces Universe block: A lexical block for the entire source code. In...
Package Import Import path: packages are identified by an unique string, called import path Go lang spec doesn't define what "import path" mean, it's u...
Package Variables Exported identifiers start with an upper-case letter files in the same package can be in the same folder Package level variables ca...
Named type Format: type typeName underlying-type A constructor with underlying-type value will exist without declaring package main import ( &n...