From 9aea3b796fe82ddc2251a61097e1a778c3a8a376 Mon Sep 17 00:00:00 2001 From: vCaesar Date: Fri, 30 Jun 2017 23:44:45 +0800 Subject: [PATCH] Format and remove en/01.2.md spaces --- en/01.2.md | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/en/01.2.md b/en/01.2.md index 92f6fd61..46600e6c 100644 --- a/en/01.2.md +++ b/en/01.2.md @@ -34,18 +34,18 @@ Execute following commands. ( ***Now author goes back to talk examples*** ) mkdir mymath Create a new file called `sqrt.go`, type the following content to your file. +```Go +// Source code of $GOPATH/src/mymath/sqrt.go +package mymath - // Source code of $GOPATH/src/mymath/sqrt.go - package mymath - - func Sqrt(x float64) float64 { - z := 0.0 - for i := 0; i < 1000; i++ { - z -= (z*z - x) / (2 * x) - } - return z +func Sqrt(x float64) float64 { + z := 0.0 + for i := 0; i < 1000; i++ { + z -= (z*z - x) / (2 * x) } - + return z +} +``` Now my package directory has been created and it's code has been written. I recommend that you use the same name for your packages as their corresponding directories, and that the directories contain all of the package source files. ## Compile packages @@ -76,17 +76,17 @@ Write the following content to main.go. ```Go - //$GOPATH/src/mathapp/main.go source code. - package main - - import ( - "mymath" - "fmt" - ) - - func main() { - fmt.Printf("Hello, world. Sqrt(2) = %v\n", mymath.Sqrt(2)) - } +//$GOPATH/src/mathapp/main.go source code. +package main + +import ( +"mymath" +"fmt" +) + +func main() { +fmt.Printf("Hello, world. Sqrt(2) = %v\n", mymath.Sqrt(2)) +} ``` 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. @@ -120,7 +120,7 @@ Actually, `go get` clones source code to the $GOPATH/src of the local file syste You can use remote packages in the same way that we use local packages. ```Go - import "github.com/astaxie/beedb" +import "github.com/astaxie/beedb" ``` ## Directory complete structure