I have read an article about how to reduce the number of servers from 30 to 2, and the performance is even better. The article describes the language used to complete this excellent task as Go, so I became interested in the Go language and gradually learned that it is still a relatively new language with great potential. So I started my research journey ~
Features:
1. Introduce a lightweight thread-coroutine, which is called goroutine in the Go language.
2. Adopt the Erlang-style concurrency model, that is, the message is the only communication mode (rather than the shared memory) between processes ). Two goroutines communicate with each other through a channel.
3. The Code style is forcibly unified. For example, the public variable must start with an uppercase letter, and the private variable must start with a lowercase letter, thus omitting the two keywords. {In {} cannot start another line.
4. The defer keyword, regardless of whether the program is abnormal or not, indicates the code executed when the program exits. Avoid a large number of try and catch statements.
5. The function allows multiple values to be returned, and the last value is of the error type, which is used to return detailed information in case of an error.
6. overload of (not supplied) Functions and operators, and inheritance, virtual functions, and virtual functions. However, the combination is provided to achieve the purpose of inheritance.
7. There is no constructor or destructor, and interfaces are provided. The biggest difference with other languages is that interfaces are non-invasive. That is, the Implementation class does not need to be derived from the interface
8. Supports anonymous functions and closures.
... Continue to study
In Windows, the development environment is set up:
IDE has two options: liteIDE developed by Chinese people and goclipse plug-in downloaded for eclipse. However, for unknown reasons, I have not adjusted the gocode-based Go language auto-completion function in eclipse. So I chose liteIDE. The following describes how to build the liteIDE environment. Let's explore the eclipse method by yourself. Share your experience.
1. download the Go language installation package, Go to the following link, select the appropriate installation package for download (My go1.0.3.windows-386.msi), and then install it. Record the installed root directory for configuration.
: Https://code.google.com/p/go/downloads/list
Then you can open the software.
: Https://code.google.com/p/golangide/downloads/list
The software interface is as follows:
3. Configure the liteIDE information. When you enable the IDE for the first time, you must configure the relevant information to use it correctly. Click View → options. The options page is displayed, and then select LiteEnv from the list ,:
4. Modify the corresponding file for your system. I am a 32-bit system, so I need to modify win32-user.env and win32.env. The modification content is as follows:
#nativecompilerwindows386
GOROOT=E:\go
GOBIN=E:\go\bin
GOARCH=386
GOOS=windows
CGO_ENABLED=1
PATH=%GOBIN%;%GOROOT%\bin;%PATH%
LITEIDE_GDB=gdb
LITEIDE_MAKE=mingw32-make
LITEIDE_TERM=%COMSPEC%
LITEIDE_TERMARGS=
LITEIDE_EXEC=%COMSPEC%
LITEIDE_EXECOPT=/C
Both GOROOT and GOBIN are configured based on the directory selected during the previous Go language installation. When installing the Go language, select the path E: \ Go
5. configure GOPATH, click View → set GOPATH. In the window that appears, Click Browse at custom GOPATH, select the folder where you want to save the Go project, and click OK. :
6. close the IDE and re-open it. Click View> tool WINDOW> Package browsing. After you open the Package browsing, if you can see the Go directory, then you can use it.
With respect to our predecessors, let's have a tour of HelloWorld ~
Select create on the start page, select Go1 Command Project in the template, set a name, and click OK. The HelloWorld program is automatically generated ~
Click the BR button in the upper part of the editing window to run the program and get the output in the compilation output window.
Well, now we can explore this stage. Installing the goclipse plug-in Eclipse has encountered various problems. Although it was successfully installed, it does not have the auto-completion function. So I gave up ~
The following is a feature provided by liteIDE:
Welcome to Go ~