Go Programming Blueprints
- http. Handle ("/", &templatehandler{filename: "chat.html"});
- http. Handle static method?
- function object parameters with parameters? It's an ordinary struct--. Why don't you need new?
- Go get Github.com/gorilla/websocket (Easy package dependent management!) )
- Go statement not required; end of Tag
- TDD: Assuming that a type struct is already present before it is defined?
- Control Flow: This is similar to Swift,if/for no need to add ()
- Initialization/Assignment (: =) vs (<-) Chan stream as output right input (to left can be considered a unit operation?) )
- map type: Map[keytype]valuetype-only think that map in go is treated as a built-in type
- so you don't need to define the Equals/hashcode method for the Key object class like in Java, and you need a C + + is to implement the Map container class as a template library (non-language feature)
- chan type can you also think of this?
- put Chan/map in front of the type, a bit of Haskell style?
- What Chan can think of as a conduit for message communication between go routine? Must the same type be said in each of the Chan's messages?
- The definition within the struct is join Chan *client, but is used for {select {case client: = <-r.join: ...}}, the programming style is too weird.
- Can only think of the * in go inside the pointer type, should be understood as a reference? and access its members using. Instead of
- The for-select here seems to draw on the idiomatic approach of Erlang
- Create Chan:make (chan []byte)//not called New call make~
- Any parameter: a ... interface{}
- Define a (Member) method for a struct? It feels like a objective-c.
- Certification: Handler wrapper (design mode)
- Processing file uploads: filename, header, err: = req. Formfile ("Avatarfile")//where is the file saved? Multipart. File interface type?
- Data, err: = Ioutil. ReadAll (file)
- The more generic the interface, the better-but does the standard library ensure that all the common ones are defined?
- Net/http the file server that is built into the package:
- http. Handle ("/avatars/", http. Stripprefix ("/avatars/", http. Fileserver (http. Dir ("./avatars"))))
- Bufio
- S: = Bufio. Newscanner (OS. Stdin)//may be scanned using regular expressions?
- For S.scan () {...}//Let me always think of the Java StringTokenizer class
- OS/EXEC: Connecting multiple processes with pipelines
- Exec.Command:nextCmd.Stdin = Thiscmd.stdoutpipe (), then call the start () method of the Cmd object and Wait ()
- NSQ
- Install driver: Go get github.com/bitly/go-nsq
- Install MongoDB driver: Go get gopkg.in/mgo.v2
- Mongod--dbpath./db
- ITER: = db. DB ("ballots"). C ("polls"). Find (nil). Iter ()
- TCP Long connections
- NETC, err: = Net. Dialtimeout (NETW, addr, 5*time. Second)//go The name of the real TM heck, dial?
- HttpClient = &http. client{
-
Transport: &http. transport{
-
dial:dial,//Use the custom Dial method (? )
-
},}
- Environment variables: ' env: ' sp_twitter_key,required '
- Fmt. Println (reflect. TypeOf(struct{}{}). Size ())//=0
- Stopchan <-chan struct{}//Only accepted channel? This syntax is so weird that the operator can be part of a type signature
- Capturing OS Signals
- Termchan: = Make (chan os. Signal, 1)
- Signal. Notify (Termchan, Syscall. SIGINT, Syscall. SIGTERM, Syscall. SIGHUP)
- Implementing RESTful APIs
- var vars map[*http. request]map[string]interface{}
- var varslock sync. Rwmutex//go The use of read-write locks inside, performance is not a problem?
- See also Wrapper:func Withapikey (fn http. Handlerfunc) http. Handlerfunc {...//the high-order function has been used here (Python adorner?). )
- Withcors (Withvars (withdata (DB, Withapikey (handlepolls))))
- The facade interface exposes a single public method, which would return the public view of a struct
- Q.lat, _ = StrConv. Parsefloat (req. Url. Query (). Get ("Lat"), 64)//library API designed to be concise
- var ZIP archiver = (*zipper) (nil)//compiler performs interface type consistency check
- var _ Interface = (*implementation) (nil)
- If err: = os. Mkdirall(filepath. Dir (dest), 0777); Err! = Nil {...
- Dirhash: Essentially converting a directory to a key string object, using a comparison of strings instead of a comparison of the directory attributes (decoupled)
- Case <-Time. after (time. Duration (*interval) * time. Second): ...//hmm? Returns a channel that will send the specified timeout message
- Gopath//equivalent to the repo concept in Maven, or Java_home?
- Go get code.google.com/p/go.tools/cmd/goimports//hmm? Why not built-in
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Go Programming Blueprints reading notes (talked about NSQ/MGO processing data persistence, but business logic is not complex)