This is a creation in
Article, where the information may have evolved or changed.
Summarize oneself in the study not to know very much place.
Record here, if you can provide help, but the best!
Import
This package name, and the functions in this package, are available only after you import a package.
A package contains (the public):
- Public functions (only accessible by package name)
- Method of the object (called by the object)
- Public type (accessed by package name)
So when calling a method in a package, there must be a point in front of "." (the signature of the point may be the package name or the object name)
Types and methods of public
Remember, it must be capitalized!
Fmt. Println (A, B, c)
When you print A, B, C, it is automatically separated by a "space".
Slice and map can be traversed using the range keyword
When using byte arrays, note the length of the byte array. Especially when passing a byte array to a function
PackageMainImport("bytes" "FMT" "OS")funcMain () {varNumintBUF: = Make([]byte,2048) F, _: = OS. Open ("Golang")deferF.close () n, _: = F.read (BUF) fmt. Println (string(Buf[:n]), N)//This is not buf, but Buf[:n] //Here is also buf[:n], you can see the return value n,_: = F.read (BUF) the use of N. for_, Sentence: =Rangebytes. Fieldsfunc (Buf[:n], F1) { for_, Words: =Rangebytes. Fields (sentence) {num++ fmt. Printf ("%q", words)}} fmt. Println () fmt. Println ("File", F.name (),"In total"Num"a word.")}funcF1 (rRune)BOOL{ifr = =','|| r = ='!'|| r = ='.'{return true}Else{return false}}
In a function that has a return value, you can no longer use return in the IF statement.
It seems that the rules have been exhausted ... I can use it after the test anyway.
Control Statement article: http://www.cnblogs.com/howDo/archive/2013/06/01/golang-control.html
Function
First refer to the article: http://www.cnblogs.com/howDo/archive/2013/06/04/GoLang-function.html
Interface
Staging stack (segmented stack)