effective Go (Official document) Notes
- Automatic local variable promotion (compile time complete?) ): Return &...;
- Built-in functions:
- New/make
- Copy, append
- Delete
- Range (is this the keyword?) Because there is no back ())
- Array is a value object
- Slice: Referencing array
- 2-D slicing (slightly)
- Map
- If seconds, OK: = Timezone[tz]; OK {...
- Func (f *file) Read (buf []byte) (n int, err error) {...
- Note that this adds a read method to the *file type, and BUF is the outgoing parameter (slice is a reference!). )
- Fmt. Printf ("...%d ...", 1); C-style;
- Fmt. Printf (os.stdout, args, ...); C + +-style? Here, args needs to implement IO. Writer interface (serialization?) )
- %v,% #v
- %T
- Type MyString string
- Switch T: = T. (type) {...//go how is run-time introspection implemented? Does this mean that each value/ref contains a type field?
- Variable parameter: v ... interface{} ==> v ... (Do not add ...) Individual v can be considered as slice, can be applied with range operation)
- Func Append (slice []t, elements ... T) []t
- Append: Cannot actually determine the type of T at run time, need compiler support at compile time (so-called builtin function)
- Defer: Deferred until the end of the Func, even if panic (function scope, non-block)
- C/c++/java programmer can be understood as Func internal whole package with try{...} finally{...}?
- Enumeration: const {_= iota \ n A B C ...}
- Variable Group declaration: var {...}
- Init () in each file: used to verify the initial state?
- Sort callback: Len () int, less (i, J int) bool, Swap (i, J int)//This is equivalent to treating the sort object as a Randomaccessiterator interface in C + +?
- Type conversions
- STR: = value. (string)//If the type does not match the runtime error;
- Net/http
- Type Handler interface {
-
servhttp (w responsewriter, req *request)
- = = Once you have the handler instance, register with http: http. Handle ("/path", Handler)
- Tie a channel to Web page?
- Extension method for Func:
- Type Handlerfunc func (Responsewriter, *request)
- Func (f Handlerfunc) servhttp (w ..., req ...) {f (W, req)}
- _ = FD//unused, webkit/chromium often see this type of notation, unused variables are explicitly marked, unused code to be removed
- Embedding (combination of type)
- The name of the other type can be added directly to the type struct, without the variable name, which is equivalent to the mixin of type traits?
- Share by communicating
- Goroutines:the stack starts small (dynamically adjustable stack)-that's probably why go supports massively concurrent programs
- <-chan: Waiting for completion message (auto-blocking)
- * The FOR loop variable (set to i) is reused? =
- Go func (I ...) { ... ) (i)//pass into the closure to generate a new copy
- I: = I//shadowing of the name (this feature C language is not, C + + namespace can be considered similar?) )
- Channels of Channels
- Parallel: Runtime. Gomaxprocs (NCPU)
- Panic/recover
- Recover executed at unwinding, i.e. defer func () {...} In
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Effective Go (Official document) notes