Skip to content

Commit d723761

Browse files
committed
Merge branch 'master' of github.com:astaxie/build-web-application-with-golang
2 parents cbf428d + bdf8fb4 commit d723761

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1477
-1378
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ _book
66
*.epub
77
*.pdf
88
.DS_Store
9+
.gitignore
10+
.vscode
11+
.git

de/09.4.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If the user inputs a user name or password as:
3232

3333
Then our SQL becomes the following:
3434

35-
SELECT * FROM user WHERE username='myuser' or 'foo'=='foo' --'' AND password='xxx'
35+
SELECT * FROM user WHERE username='myuser' or 'foo' = 'foo' --'' AND password='xxx'
3636

3737
In SQL, anything after `--` is a comment. Thus, inserting the `--` as the attacker did above alters the query in a fatal way, allowing an attacker to successfully login as a user without a valid password.
3838

en/01.1.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ A 64-bit operating system will show the following:
7676

7777
### Mac
7878

79-
Go to the [download page](https://golang.org/dl/), choose `go1.4.2.darwin-386.pkg` for 32-bit systems and `go1.7.4.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 figure 1.1.
79+
Go to the [download page](https://golang.org/dl/), choose `go1.4.2.darwin-386.pkg` (The later version has no 32-bit download.)for 32-bit systems and `go1.8.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 figure 1.1.
8080

8181
### Linux
8282

83-
Go to the [download page](https://golang.org/dl/), choose `go1.7.4.linux-386.tar.gz` for 32-bit systems and `go1.7.4.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.7.4.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.
83+
Go to the [download page](https://golang.org/dl/), choose `go1.8.linux-386.tar.gz` for 32-bit systems and `go1.8.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.8.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.
8484

8585
### Windows
8686

87-
Go to the [download page](https://golang.org/dl/), choose `go1.7.4.windows-386.msi` for 32-bit systems and `go1.7.4.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.
87+
Go to the [download page](https://golang.org/dl/), choose `go1.8.windows-386.msi` for 32-bit systems and `go1.8.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.
8888

8989
## Use third-party tools
9090

@@ -96,8 +96,8 @@ GVM is a Go multi-version control tool developed by a third-party, like rvm for
9696

9797
Then we install Go using the following commands:
9898

99-
gvm install go1.7.4
100-
gvm use go1.7.4
99+
gvm install go1.8
100+
gvm use go1.8
101101

102102
After the process has finished, you're all set.
103103

@@ -109,16 +109,19 @@ Ubuntu is the most popular desktop release version of Linux. It uses `apt-get` t
109109
sudo apt-get update
110110
sudo apt-get install golang-stable
111111

112-
###wget
112+
### wget
113113
```sh
114114

115-
wget https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
116-
sudo tar -xzf go1.7.4.linux-amd64.tar.gz -C /usr/local
117-
export PATH=PATH:/usr/local/go/binexportGOROOT=HOME/go
118-
export PATH=PATH:GOROOT/bin
119-
export GOPATH=HOME/gowork
120-
```
115+
wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz
116+
sudo tar -xzf go1.8.linux-amd64.tar.gz -C /usr/local
121117

118+
# Go environment
119+
export GOROOT=/usr/local/go
120+
export GOBIN=$GOROOT/bin
121+
export PATH=$PATH:$GOBIN
122+
export GOPATH=HOME/gopath
123+
```
124+
Starting from go 1.8,The GOPATH environment variable now has a default value if it is unset. It defaults to $HOME/go on Unix and %USERPROFILE%/go on Windows.
122125
### Homebrew
123126

124127
Homebrew is a software management tool commonly used in Mac to manage packages. Just type the following commands to install Go.

en/01.2.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
Go takes a unique approach to manage the code files with the introduction of a `$GOPATH` directory which contains all the go code in the machine. Note that this is different from the `$GOROOT` environment variable which states where go is installed on the machine. We have to define the $GOPATH variable before using the language, in *nix systems there is a file called `.bashrc` we need to append the below export statement to the file. The concept behind gopath is a novel one, where we can link to any go code at any instant of time without ambiguity.
66

7+
Starting from go 1.8, the GOPATH environment variable now has a default value if it is unset. It defaults to $HOME/go on Unix and %USERPROFILE%/go on Windows.
8+
79
In Unix-like systems, the variable should be used like this:
810

911
export GOPATH=/home/apple/mygo
1012

1113
In Windows, you need to create a new environment variable called GOPATH, then set its value to `c:\mygo`( ***This value depends on where your workspace is located*** )
1214

13-
It's OK to have more than one path (workspace) in $GOPATH, but remember that you have to use `:`(`;` in Windows) to break them up. At this point, `go get` will save the content to your first path in $GOPATH. So it is highly recommended to not have multiples versions, the worst case is to create a folder by the name of your project right inside $GOPATH, it breaks everything that the creators were wishing to change in programming with the creation of go language because when you create a folder inside $GOPATH you will reference your packages as directly as <packagename>, and this breaks all the applications which will import your package because the `go get` won't find your package anywhere. So please follow conventions, there is a reason conventions are created
15+
It's OK to have more than one path (workspace) in $GOPATH, but remember that you have to use `:`(`;` in Windows) to break them up. At this point, `go get` will save the content to your first path in $GOPATH. It is highly recommended to not have multiples versions, the worst case is to create a folder by the name of your project right inside $GOPATH, it breaks everything that the creators were wishing to change in programming with the creation of go language because when you create a folder inside $GOPATH you will reference your packages as directly as <packagename>, and this breaks all the applications which will import your package because the `go get` won't find your package. Please follow conventions, there is a reason conventions are created.
1416

15-
In $GOPATH, you must have three folders as follows.
17+
In $GOPATH, you must have three folders as follows:
1618

1719
- `src` for source files whose suffix is .go, .c, .g, .s.
1820
- `pkg` for compiled files whose suffix is .a.
@@ -72,6 +74,8 @@ Create a new application package called `mathapp`.
7274

7375
Write the following content to main.go.
7476

77+
```Go
78+
7579
//$GOPATH/src/mathapp/main.go source code.
7680
package main
7781

@@ -83,7 +87,8 @@ Write the following content to main.go.
8387
func main() {
8488
fmt.Printf("Hello, world. Sqrt(2) = %v\n", mymath.Sqrt(2))
8589
}
86-
90+
```
91+
8792
To compile this application, you need to switch to the application directory, which in this case is `$GOPATH/src/mathapp`, then execute the `go install` command. Now you should see an executable file called `mathapp` was generated in the directory `$GOPATH/bin/`. To run this program, use the `./mathapp` command. You should see the following content in your terminal.
8893

8994
Hello world. Sqrt(2) = 1.414213562373095
@@ -114,9 +119,9 @@ After executing the above commands, the directory structure should look like fol
114119
Actually, `go get` clones source code to the $GOPATH/src of the local file system, then executes `go install`.
115120

116121
You can use remote packages in the same way that we use local packages.
117-
122+
```Go
118123
import "github.com/astaxie/beedb"
119-
124+
```
120125
## Directory complete structure
121126

122127
If you've followed all of the above steps, your directory structure should now look like the following.

en/01.4.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ Atom is an awesome text editor released as open source cross platform, built on
468468
469469
Download: https://atom.io/
470470
471-
##Gogland
471+
## Gogland
472472
473473
Gogland is the codename for a new commercial IDE by JetBrains aimed at providing an ergonomic environment for Go development.
474474

en/02.1.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## What makes Go different from other languages?
22

33
The Go programming language was created with one goal in mind, to be able to build scalable web-applications for large scale audiences in a large team. So that is the reason they made the language as standardized as possible, hence the `gofmt` tool and the strict usage guidelines to the language was for the sake of not having two factions in the developer base, in other languages there are religious wars on where to keep the opening brace?
4+
```java
45

56
public static void main() {
67

@@ -11,6 +12,7 @@ The Go programming language was created with one goal in mind, to be able to bui
1112
{
1213

1314
}
15+
```
1416
or for python should we use 4 spaces or 6 spaces or a tab or two tabs and other user preferences.
1517

1618
While this might seem to be a shallow problem at the top, but when the codebase grows and more and more people are working on the same code base, then it is difficult to maintain the code's "beauty", if you know python then you might be aware of PEP8, which is a set of guidelines about how to write elegant code. We live in a world where robots can drive a car, so we shouldn't just write code, we should write elegant code.
@@ -40,15 +42,15 @@ Before we start building an application in Go, we need to learn how to write a s
4042
According to international practice, before you learn how to program in some languages, you will want to know how to write a program to print "Hello world".
4143

4244
Are you ready? Let's Go!
43-
45+
```Go
4446
package main
4547

4648
import "fmt"
4749

4850
func main() {
4951
fmt.Printf("Hello, world or 你好,世界 or καλημ ́ρα κóσμ or こんにちは世界\n")
5052
}
51-
53+
```
5254
It prints following information.
5355

5456
Hello, world or 你好,世界 or καλημ ́ρα κóσμ or こんにちは世界
@@ -83,10 +85,11 @@ Each go file is in some package, and that package should be a distinct folder in
8385
the thing here is that when your code is using some static files or something else, then you ought to run the binary from the root of the application as we see in the second line above, I am running the `main` binary *outside* the main package, sometimes you might wonder why your application isn't working then this might be one of the possible problems, please keep this in mind.
8486

8587
One thing you will notice here is that go doesn't see to use semi colons to end a statement, well, it does, just there is a minor catch, the programmer isn't expected to put semi colons, the compiler adds semi colons to the gocode when it compiles which is the reason that this (thankfully!) is a syntax error
86-
88+
```Go
8789
func main ()
8890
{
8991
}
92+
```
9093
because the compiler adds a semi colon at the end of `main()` which is a syntax error and as stated above, it helps avoid religious wars, i wish they combine `vim` and `emacs` and create a universal editor which'll help save some more wars! But for now we'll learn Go.
9194

9295
## Conclusion

0 commit comments

Comments
 (0)