01.0 is ready
121
ru/01.1.md
Normal file
@@ -0,0 +1,121 @@
|
||||
# 1.1 Installation
|
||||
|
||||
## Three ways to install Go
|
||||
|
||||
There are many ways to configure the Go development environment on your computer, and you can choose whichever one you like. The three most common ways are as follows.
|
||||
|
||||
|
||||
- Official installation packages.
|
||||
- The Go team provides convenient installation packages in Windows, Linux, Mac and other operating systems. This is probably the easiest way to get started.
|
||||
- Install it yourself from source code.
|
||||
- Popular with developers who are familiar with Unix-like systems.
|
||||
- Using third-party tools.
|
||||
- There are many third-party tools and package managers for installing Go, like apt-get in Ubuntu and homebrew for Mac.
|
||||
|
||||
In case you want to install more than one version of Go on a computer, you should take a look at a tool called [GVM](https://github.com/moovweb/gvm). It is the best tool I've seen so far for accomplishing this task, otherwise you'd have to deal with it yourself.
|
||||
|
||||
## Install from source code
|
||||
|
||||
Because some parts of Go are written in Plan 9 C and AT&T assembler, you have to install a C compiler before taking the next step.
|
||||
|
||||
On a Mac, if you have installed Xcode, you already have the compiler.
|
||||
|
||||
On Unix-like systems, you need to install gcc or a similar compiler. For example, using the package manager apt-get (included with Ubuntu), one can install the required compilers as follows:
|
||||
|
||||
`sudo apt-get install gcc libc6-dev`
|
||||
|
||||
On Windows, you need to install MinGW in order to install gcc. Don't forget to configure your environment variables after the installation has completed.( ***Everything that looks like this means it's commented by a translator: If you are using 64-bit Windows, you should install the 64-bit version of MinGW*** )
|
||||
|
||||
At this point, execute the following commands to clone the Go source code and compile it.( ***It will clone the source code to your current directory. Switch your work path before you continue. This may take some time.*** )
|
||||
|
||||
git clone https://go.googlesource.com/go
|
||||
cd go/src
|
||||
./all.bash
|
||||
|
||||
A successful installation will end with the message "ALL TESTS PASSED."
|
||||
|
||||
On Windows, you can achieve the same by running `all.bat`.
|
||||
|
||||
If you are using Windows, the installation package will set your environment variables automatically. In Unix-like systems, you need to set these variables manually as follows. ( ***If your Go version is greater than 1.0, you don't have to set $GOBIN, and it will automatically be related to your $GOROOT/bin, which we will talk about in the next section***)
|
||||
|
||||
export GOROOT=$HOME/go
|
||||
export GOBIN=$GOROOT/bin
|
||||
export PATH=$PATH:$GOROOT/bin
|
||||
|
||||
If you see the following information on your screen, you're all set.
|
||||
|
||||

|
||||
|
||||
Figure 1.1 Information after installing from source code
|
||||
|
||||
Once you see the usage information of Go, it means you have successfully installed Go on your computer. If it says "no such command", check that your $PATH environment variable contains the installation path of Go.
|
||||
|
||||
## Using the standard installation packages
|
||||
|
||||
Go has one-click installation packages for every supported operating system. These packages will install Go in `/usr/local/go` (`c:\Go` in Windows) by default. Of course this can be modified, but you also need to change all the environment variables manually as I've shown above.
|
||||
|
||||
### How to check if your operating system is 32-bit or 64-bit?
|
||||
|
||||
Our next step depends on your operating system type, so we have to check it before we download the standard installation packages.
|
||||
|
||||
If you are using Windows, press `Win+R` and then run the command tool. Type the `systeminfo` command and it will show you some useful system information. Find the line that says "system type" -if you see "x64-based PC" that means your operating system is 64-bit, 32-bit otherwise.
|
||||
|
||||
I strongly recommend downloading the 64-bit package if you are a Mac user, as Go no longer supports pure 32-bit processors on Mac OSX.
|
||||
|
||||
Linux users can type `uname -a` in the terminal to see system information.
|
||||
A 64-bit operating system will show the following:
|
||||
|
||||
<some description> x86_64 x86_64 x86_64 GNU/Linux
|
||||
// some machines such as Ubuntu 10.04 will show as following
|
||||
x86_64 GNU/Linux
|
||||
|
||||
32-bit operating systems instead show:
|
||||
|
||||
<some description> i686 i686 i386 GNU/Linux
|
||||
|
||||
### Mac
|
||||
|
||||
Go to the [download page](https://golang.org/dl/), choose `go1.4.2.darwin-386.pkg` for 32-bit systems and `go1.4.2.darwin-amd64.pkg` for 64-bit systems. Going all the way to the end by clicking "next", `~/go/bin` will be added to your system's $PATH after you finish the installation. Now open the terminal and type `go`. You should see the same output shown in igure 1.1.
|
||||
|
||||
### Linux
|
||||
|
||||
Go to the [download page](https://golang.org/dl/), choose `go1.4.2.linux-386.tar.gz` for 32-bit systems and `go1.4.2.linux-amd64.tar.gz` for 64-bit systems. Suppose you want to install Go in the `$GO_INSTALL_DIR` path. Uncompress the `tar.gz` to your chosen path using the command `tar zxvf go1.4.2.linux-amd64.tar.gz -C $GO_INSTALL_DIR`. Then set your $PATH with the following: `export PATH=$PATH:$GO_INSTALL_DIR/go/bin`. Now just open the terminal and type `go`. You should now see the same output displayed in figure 1.1.
|
||||
|
||||
### Windows
|
||||
|
||||
Go to the [download page](https://golang.org/dl/), choose `go1.4.2.windows-386.msi` for 32-bit systems and `go1.4.2.windows-amd64.msi` for 64-bit systems. Going all the way to the end by clicking "next", `c:/go/bin` will be added to `path`. Now just open a command line window and type `go`. You should now see the same output displayed in figure 1.1.
|
||||
|
||||
## Use third-party tools
|
||||
|
||||
### GVM
|
||||
|
||||
GVM is a Go multi-version control tool developed by a third-party, like rvm for ruby. It's quite easy to use. Install gvm by typing the following commands in your terminal:
|
||||
|
||||
bash < <(curl -s -S -L https://raw.github.com/moovweb/gvm/master/binscripts/gvm-installer)
|
||||
|
||||
Then we install Go using the following commands:
|
||||
|
||||
gvm install go1.4.2
|
||||
gvm use go1.4.2
|
||||
|
||||
After the process has finished, you're all set.
|
||||
|
||||
### apt-get
|
||||
|
||||
Ubuntu is the most popular desktop release version of Linux. It uses `apt-get` to manage packages. We can install Go using the following commands.
|
||||
|
||||
sudo add-apt-repository ppa:gophers/go
|
||||
sudo apt-get update
|
||||
sudo apt-get install golang-stable
|
||||
|
||||
### Homebrew
|
||||
|
||||
Homebrew is a software management tool commonly used in Mac to manage packages. Just type the following commands to install Go.
|
||||
|
||||
brew install go
|
||||
|
||||
## Links
|
||||
|
||||
- [Directory](preface.md)
|
||||
- Previous section: [Go environment configuration](01.0.md)
|
||||
- Next section: [$GOPATH and workspace](01.2.md)
|
||||
BIN
ru/images/1.1.cmd.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
ru/images/1.1.linux.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
ru/images/1.1.mac.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
ru/images/1.3.go.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
ru/images/1.4.eclipse1.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
ru/images/1.4.eclipse2.png
Normal file
|
After Width: | Height: | Size: 213 KiB |
BIN
ru/images/1.4.eclipse3.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
ru/images/1.4.eclipse4.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
ru/images/1.4.eclipse5.png
Normal file
|
After Width: | Height: | Size: 224 KiB |
BIN
ru/images/1.4.eclipse6.png
Normal file
|
After Width: | Height: | Size: 285 KiB |
BIN
ru/images/1.4.emacs.png
Normal file
|
After Width: | Height: | Size: 299 KiB |
BIN
ru/images/1.4.idea1.png
Normal file
|
After Width: | Height: | Size: 66 KiB |
BIN
ru/images/1.4.idea2.png
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
ru/images/1.4.idea3.png
Normal file
|
After Width: | Height: | Size: 109 KiB |
BIN
ru/images/1.4.idea4.png
Normal file
|
After Width: | Height: | Size: 123 KiB |
BIN
ru/images/1.4.idea5.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
ru/images/1.4.liteide.png
Normal file
|
After Width: | Height: | Size: 134 KiB |
BIN
ru/images/1.4.sublime1.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
ru/images/1.4.sublime2.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
ru/images/1.4.sublime3.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
ru/images/1.4.sublime4.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
ru/images/1.4.vim.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
ru/images/13.1.flow.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
ru/images/13.1.gopath.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
ru/images/13.1.gopath2.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
ru/images/13.4.beego.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
ru/images/14.1.bootstrap.png
Normal file
|
After Width: | Height: | Size: 193 KiB |
BIN
ru/images/14.1.bootstrap2.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
ru/images/14.1.bootstrap3.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
ru/images/14.4.github.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
ru/images/14.4.github2.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
ru/images/14.4.github3.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
ru/images/14.6.pprof.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
ru/images/14.6.pprof2.png
Normal file
|
After Width: | Height: | Size: 240 KiB |
BIN
ru/images/14.6.pprof3.png
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
ru/images/2.2.array.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
ru/images/2.2.basic.png
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
ru/images/2.2.makenew.png
Normal file
|
After Width: | Height: | Size: 141 KiB |
BIN
ru/images/2.2.slice.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
ru/images/2.2.slice2.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
ru/images/2.3.init.png
Normal file
|
After Width: | Height: | Size: 93 KiB |
BIN
ru/images/2.4.student_struct.png
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
ru/images/2.5.rect_func_without_receiver.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
ru/images/2.5.shapes_func_with_receiver_cp.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
ru/images/2.5.shapes_func_without_receiver.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
ru/images/3.1.dns2.png
Normal file
|
After Width: | Height: | Size: 190 KiB |
BIN
ru/images/3.1.dns_hierachy.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
ru/images/3.1.dns_inquery.png
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
ru/images/3.1.http.png
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
ru/images/3.1.httpPOST.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
ru/images/3.1.response.png
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
ru/images/3.1.web.png
Normal file
|
After Width: | Height: | Size: 361 KiB |
BIN
ru/images/3.1.web2.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
ru/images/3.2.goweb.png
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
ru/images/3.3.http.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
ru/images/3.3.illustrator.png
Normal file
|
After Width: | Height: | Size: 66 KiB |
BIN
ru/images/4.1.login.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
ru/images/4.1.slice.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
ru/images/4.3.escape.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
ru/images/4.4.token.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
ru/images/4.5.upload.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
ru/images/4.5.upload2.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
ru/images/5.6.mongodb.png
Normal file
|
After Width: | Height: | Size: 243 KiB |
BIN
ru/images/6.1.cookie.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
ru/images/6.1.cookie2.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
ru/images/6.1.session.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
ru/images/6.4.cookie.png
Normal file
|
After Width: | Height: | Size: 69 KiB |
BIN
ru/images/6.4.hijack.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
ru/images/6.4.hijacksuccess.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
ru/images/6.4.setcookie.png
Normal file
|
After Width: | Height: | Size: 66 KiB |
BIN
ru/images/7.4.template.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
ru/images/8.1.socket.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
ru/images/8.2.websocket.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
ru/images/8.2.websocket2.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
ru/images/8.2.websocket3.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
ru/images/8.3.rest.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
ru/images/8.3.rest2.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
ru/images/8.3.rest3.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
ru/images/8.4.rpc.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
ru/images/9.1.csrf.png
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
ru/images/cover.png
Normal file
|
After Width: | Height: | Size: 123 KiB |
BIN
ru/images/ebook.jpg
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
ru/images/navi1.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
ru/images/navi10.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
ru/images/navi11.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
ru/images/navi12.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
ru/images/navi13.png
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
ru/images/navi14.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
ru/images/navi2.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
ru/images/navi3.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
ru/images/navi4.png
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
ru/images/navi5.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
ru/images/navi6.png
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
ru/images/navi7.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
ru/images/navi8.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
ru/images/navi9.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
ru/images/polling.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
96
ru/preface.md
Normal file
@@ -0,0 +1,96 @@
|
||||
- 1.[Настройка среды разработки на Go](01.0.md)
|
||||
- 1.1. [Установка](01.1.md)
|
||||
- 1.2. [$GOPATH и рабочая директория](01.2.md)
|
||||
- 1.3. [Команды Go](01.3.md)
|
||||
- 1.4. [Go development tools](01.4.md)
|
||||
- 1.5. [Summary](01.5.md)
|
||||
- 2.[Go basic knowledge](02.0.md)
|
||||
- 2.1. ["Hello, Go"](02.1.md)
|
||||
- 2.2. [Go foundation](02.2.md)
|
||||
- 2.3. [Control statements and functions](02.3.md)
|
||||
- 2.4. [struct](02.4.md)
|
||||
- 2.5. [Object-oriented](02.5.md)
|
||||
- 2.6. [interface](02.6.md)
|
||||
- 2.7. [Concurrency](02.7.md)
|
||||
- 2.8. [Summary](02.8.md)
|
||||
- 3.[Web foundation](03.0.md)
|
||||
- 3.1. [Web working principles](03.1.md)
|
||||
- 3.2. [Build a simple web server](03.2.md)
|
||||
- 3.3. [How Go works with web](03.3.md)
|
||||
- 3.4. [Get into http package](03.4.md)
|
||||
- 3.5. [Summary](03.5.md)
|
||||
- 4.[User form](04.0.md)
|
||||
- 4.1. [Process form inputs](04.1.md)
|
||||
- 4.2. [Verification of inputs](04.2.md)
|
||||
- 4.3. [Cross site scripting](04.3.md)
|
||||
- 4.4. [Duplicate submissions](04.4.md)
|
||||
- 4.5. [File upload](04.5.md)
|
||||
- 4.6. [Summary](04.6.md)
|
||||
- 5.[Database](05.0.md)
|
||||
- 5.1. [database/sql interface](05.1.md)
|
||||
- 5.2. [MySQL](05.2.md)
|
||||
- 5.3. [SQLite](05.3.md)
|
||||
- 5.4. [PostgreSQL](05.4.md)
|
||||
- 5.5. [Develop ORM based on beedb](05.5.md)
|
||||
- 5.6. [NoSQL database](05.6.md)
|
||||
- 5.7. [Summary](05.7.md)
|
||||
- 6.[Data storage and session](06.0.md)
|
||||
- 6.1. [Session and cookies](06.1.md)
|
||||
- 6.2. [How to use session in Go](06.2.md)
|
||||
- 6.3. [Session storage](06.3.md)
|
||||
- 6.4. [Prevent hijack of session](06.4.md)
|
||||
- 6.5. [Summary](06.5.md)
|
||||
- 7.[Text files](07.0.md)
|
||||
- 7.1. [XML](07.1.md)
|
||||
- 7.2. [JSON](07.2.md)
|
||||
- 7.3. [Regexp](07.3.md)
|
||||
- 7.4. [Templates](07.4.md)
|
||||
- 7.5. [Files](07.5.md)
|
||||
- 7.6. [Strings](07.6.md)
|
||||
- 7.7. [Summary](07.7.md)
|
||||
- 8.[Web services](08.0.md)
|
||||
- 8.1. [Sockets](08.1.md)
|
||||
- 8.2. [WebSocket](08.2.md)
|
||||
- 8.3. [REST](08.3.md)
|
||||
- 8.4. [RPC](08.4.md)
|
||||
- 8.5. [Summary](08.5.md)
|
||||
- 9.[Security and encryption](09.0.md)
|
||||
- 9.1. [CSRF attacks](09.1.md)
|
||||
- 9.2. [Filter inputs](09.2.md)
|
||||
- 9.3. [XSS attacks](09.3.md)
|
||||
- 9.4. [SQL injection](09.4.md)
|
||||
- 9.5. [Password storage](09.5.md)
|
||||
- 9.6. [Encrypt and decrypt data](09.6.md)
|
||||
- 9.7. [Summary](09.7.md)
|
||||
- 10.[Internationalization and localization](10.0.md)
|
||||
- 10.1 [Time zone](10.1.md)
|
||||
- 10.2 [Localized resources](10.2.md)
|
||||
- 10.3 [International sites](10.3.md)
|
||||
- 10.4 [Summary](10.4.md)
|
||||
- 11.[Error handling, debugging and testing](11.0.md)
|
||||
- 11.1. [Error handling](11.1.md)
|
||||
- 11.2. [Debugging by using GDB](11.2.md)
|
||||
- 11.3. [Write test cases](11.3.md)
|
||||
- 11.4. [Summary](11.4.md)
|
||||
- 12.[Deployment and maintenance](12.0.md)
|
||||
- 12.1. [Logs](12.1.md)
|
||||
- 12.2. [Errors and crashes](12.2.md)
|
||||
- 12.3. [Deployment](12.3.md)
|
||||
- 12.4. [Backup and recovery](12.4.md)
|
||||
- 12.5. [Summary](12.5.md)
|
||||
- 13.[Build a web framework](13.0.md)
|
||||
- 13.1. [Project program](13.1.md)
|
||||
- 13.2. [Customized routers](13.2.md)
|
||||
- 13.3. [Design controllers](13.3.md)
|
||||
- 13.4. [Logs and configurations](13.4.md)
|
||||
- 13.5. [Add, delete and update blogs](13.5.md)
|
||||
- 13.6. [Summary](13.6.md)
|
||||
- 14.[Develop web framework](14.0.md)
|
||||
- 14.1. [Static files](14.1.md)
|
||||
- 14.2. [Session](14.2.md)
|
||||
- 14.3. [Form](14.3.md)
|
||||
- 14.4. [User validation](14.4.md)
|
||||
- 14.5. [Multi-language support](14.5.md)
|
||||
- 14.6. [pprof](14.6.md)
|
||||
- 14.7. [Summary](14.7.md)
|
||||
- Appendix A [References](ref.md)
|
||||