This is a creation in Article, where the information may have evolved or changed.
Some of the feelings of learning go language are not necessarily accurate.
If there is a war, Java is generally the role of the carrier battle group.
Once dispatched, it is frigate, cruiser, carrier aircraft, early warning machine, electronic warfare aircraft, submarine, etc.
Mighty, Kill will pass.
(JVM, dozens of jar packages, Tomcat middleware, SSH framework, various configuration files ...) Born to be heavyweight, specifically for large-scale warfare)
And the go language is more like a F35 fighter bomber.
Single-handedly, silently, dropping bombs and leaving.
Exclusive bomber, air combat will be a little bit.
Really can not make, call it eldest brother F22.
(Go is a compiled language that doesn't need to be relied on, doesn't need a virtual machine, can call C code and it's simple enough, but very comprehensive)
Planning the knowledge points for Go language learning
1. Setting up an HTTP service
2. Connect to the database
3. Local IO
4. Multithreading
5. Network
6. Calling local commands
7. Calling the C language code
First, build a static server.
I write programs like using HTML to send JSON requests to back-end processing via Ajax.
Httpserver.go
Package Mainimport ("Flag" "Io/ioutil" "Log" "Net/http" "OS" "strings") var real Path *stringfunc StaticResource (w http. Responsewriter, R *http. Request) {path: = R.url. Path Request_type: = path[strings. LastIndex (Path, "."):] switch Request_type {case ". css": W.header (). Set ("Content-type", "text/css") case ". js": W.header (). Set ("Content-type", "Text/javascript") Default:} fin, err: = OS. Open (*realpath + path) defer fin. Close () if err! = Nil {log. Fatal ("Static resource:", err)} fd, _: = Ioutil. ReadAll (Fin) w.write (FD)}func main () {Realpath = flag. String ("Path", "", "Static Resource Path") flag. Parse () http. Handlefunc ("/", StaticResource) Err: = http. Listenandserve (": 8080", nil) if err! = Nil {log. Fatal ("Listenandserve:", Err)}}
See a more BT method on the Web:
Package Mainimport ( "Net/http") func main () { http. Handle ("/", HTTP. Fileserver (http. Dir ("/tmp/static/"))) http. Listenandserve (": 8080", nil)}
Extract the Easyui front-end framework into the/tmp/static directory:
Executed under the Gopath
Copy CodeThe code is as follows:
Go run Httpserver.go--path=/tmp/static
View Web page, everything is OK.
So the go language in less than 50 lines of code, compiled less than 7M of executable files, the implementation of a simple static server.