From dab03f4a841ba3043404bc00c17e08bb233655b3 Mon Sep 17 00:00:00 2001 From: Denis Koltsov Date: Sat, 19 Nov 2016 14:01:11 +0100 Subject: [PATCH 1/4] Fix unresolved conflicts in gitignore, readme and en-version of the book --- .gitignore | 4 ---- .gitignore.orig | 8 -------- README.md.orig | 46 ---------------------------------------------- en/13.5.md | 10 ---------- 4 files changed, 68 deletions(-) delete mode 100644 .gitignore.orig delete mode 100644 README.md.orig diff --git a/.gitignore b/.gitignore index b2eb862a..dfebd51a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,3 @@ pkg/* *.html *.exe -<<<<<<< HEAD -======= - ->>>>>>> eead24cf064976b648de5826eab51880c803b0fa diff --git a/.gitignore.orig b/.gitignore.orig deleted file mode 100644 index b2eb862a..00000000 --- a/.gitignore.orig +++ /dev/null @@ -1,8 +0,0 @@ -*~ -pkg/* -*.html -*.exe -<<<<<<< HEAD -======= - ->>>>>>> eead24cf064976b648de5826eab51880c803b0fa diff --git a/README.md.orig b/README.md.orig deleted file mode 100644 index af091edb..00000000 --- a/README.md.orig +++ /dev/null @@ -1,46 +0,0 @@ -# Multiple Language Versions -<<<<<<< HEAD -======= -* [English](en/) ->>>>>>> eead24cf064976b648de5826eab51880c803b0fa -* [French](fr/) -* [Spanish](es/) -* [中文](zh/) -* [日本語](ja/) -* [Turkish](tr/) -* [Português - Brasil](pt-br/) -* [German](de/) -* [Русский](ru/) - -# Donate - -AliPay: alipay - -English Donate:[donate](http://beego.me/donate) - -## Community -QQ群:148647580 - -BBS:[http://golanghome.com/](http://golanghome.com/) - -## Acknowledgments - - - [四月份平民](https://plus.google.com/110445767383269817959) (review代码) - - [Hong Ruiqi](https://github.com/hongruiqi) (review代码) - - [BianJiang](https://github.com/border) (编写go开发工具Vim和Emacs的设置) - - [Oling Cat](https://github.com/OlingCat)(review代码) - - [Wenlei Wu](mailto:spadesacn@gmail.com)(提供一些图片展示) - - [polaris](https://github.com/polaris1119)(review书) - - [雨痕](https://github.com/qyuhen)(review第二章) - -<<<<<<< HEAD -======= -Translator: - - [LarryBattle](https://github.com/LarryBattle) ->>>>>>> eead24cf064976b648de5826eab51880c803b0fa -## License -Book License: [CC BY-SA 3.0 License](http://creativecommons.org/licenses/by-sa/3.0/) - -Code License: [BSD 3-Clause License]() - - diff --git a/en/13.5.md b/en/13.5.md index c11d0bd8..e011b8b0 100644 --- a/en/13.5.md +++ b/en/13.5.md @@ -127,11 +127,7 @@ func (this *EditController) Get() { id, _ := strconv.Atoi(this.Ctx.Params[":id"]) this.Data["Post"] = models.GetBlog(id) this.Layout = "layout.tpl" -<<<<<<< HEAD - this.TplNames = "new.tpl" -======= this.TplNames = "edit.tpl" ->>>>>>> eead24cf064976b648de5826eab51880c803b0fa } func (this *EditController) Post() { @@ -154,17 +150,11 @@ type DeleteController struct { } func (this *DeleteController) Get() { -<<<<<<< HEAD - id, _ := strconv.Atoi(this.Ctx.Params[":id"]) - this.Data["Post"] = models.DelBlog(id) - this.Ctx.Redirect(302, "/") -======= id, _ := strconv.Atoi(this.Ctx.Input.Params[":id"]) blog := models.GetBlog(id) this.Data["Post"] = blog models.DelBlog(blog) this.Ctx.Redirect(302, "/") ->>>>>>> eead24cf064976b648de5826eab51880c803b0fa } ``` From b19cd5d8d3aa28fe22880778c485249e22ccfd07 Mon Sep 17 00:00:00 2001 From: Denis Koltsov Date: Sat, 19 Nov 2016 14:01:39 +0100 Subject: [PATCH 2/4] Add system and generated files to the .gitignore --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 4 ++++ 2 files changed, 4 insertions(+) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 557367ed970ed56d928b9b2c78d9ee0221d6e012..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&2G~`5S~p_uoDRx0a7I{K7tfb2!vddGzCSXD5_B_L{YG7w{d0c$aa!K6e$Nz zJOO9^-vhyk2Y^T66lQ;d?ATmsg?6OfZ@l}>X7<~7*9!ooJ+f~BXaJyKp;#t)!oK`I~>IBN>fcUOf22w)5jB;McP!14kMdnw}{mTL=U z=m8YK2B+(#INviI2mCaL?BsBw70!vge{CQu+EF2xh7-Qaqo-a23UC+6D5(c3OhJv3p%i!KQ>_gsfY{N z2+S$KHFN2Hn_LSzmsD&4S)&yW=Dxy-bF)6dITjWRtm(QV$C^Y#@!$Am4LvuCtJR;R zuvT0@cV1CT<#M@H)-INw8iQbB#AZB-+GhBKJ-N1H3BPB?gQfo{2)sYOY3;hsq_17x z4E)%1eJ4zW?(ez29ZcH6$hV_?gO9i8+VP;TUFn6+7(;ue@9esfYq_2qzfe?FRn)$= zF`d@x^@?6=)MgcZ+GtcO`kmW%XEW`UqFlXRZ*4yw&R)NL_x{7jPoKYhWzz+M#~QOs z0+;X&9VW)u2z@W`kMNmt3-A&KX`$Ido+OrjImW4@n4D5R^-N>}QUR&JSyO=S4>}f# zO@VWcZ0o>^T>%h_*vt%l`oTbBbb(EQbB@@9MtCS94<+J?L3lW}>w?!5IOoX2fr!fo z5x-2t4TZ2@$MJPW2h!vyYpH-#Ag#a}f7IytzxDU~e>zA$Nd=?=|CIuy*fBb7oRT Date: Sat, 19 Nov 2016 14:08:01 +0100 Subject: [PATCH 3/4] Fix english 7.4 chapter preventing book to be built --- en/07.4.md | 56 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/en/07.4.md b/en/07.4.md index c645d7a2..8543f254 100644 --- a/en/07.4.md +++ b/en/07.4.md @@ -9,11 +9,11 @@ The following demonstrates the template mechanism: Figure 7.1 Template mechanism -Most of the content that web applications respond to clients with is static, and the dynamic parts are usually very small. For example, if you need to display a list users who have visited a page, only the user name would be dynamic. The style of the list remains the same. As you can see, templates are useful for reusing static content. +Most of the content that web applications respond to clients with is static, and the dynamic parts are usually very small. For example, if you need to display a list users who have visited a page, only the user name would be dynamic. The style of the list remains the same. As you can see, templates are useful for reusing static content. ## Templating in Go -In Go, we have the `template` package to help handle templates. We can use functions like `Parse`, `ParseFile` and `Execute` to load templates from plain text or files, then evaluate the dynamic parts, as shown in figure 7.1. +In Go, we have the `template` package to help handle templates. We can use functions like `Parse`, `ParseFile` and `Execute` to load templates from plain text or files, then evaluate the dynamic parts, as shown in figure 7.1. Example: @@ -75,8 +75,8 @@ If you print `{{.}}` in a template, Go outputs a formatted string of this object We know how to output a field now. What if the field is an object, and it also has its own fields? How do we print them all in one loop? We can use `{{with …}}…{{end}}` and `{{range …}}{{end}}` for exactly that purpose. -- `{{range}}` just like range in Go. -- `{{with}}` lets you write the same object name once and use `.` as shorthand for it ( ***Similar to `with` in VB*** ). +- {% raw %}`{{range}}`{% endraw %} just like range in Go. +- {% raw %}`{{with}}`{% endraw %} lets you write the same object name once and use `.` as shorthand for it ( ***Similar to `with` in VB*** ). More examples: @@ -305,6 +305,7 @@ Here's a complete example, supposing that we have the following three files: `he Main template: +{% raw %} //header.tmpl {{define "header"}} @@ -330,10 +331,11 @@ Main template: {{end}} - - //When using subtemplating make sure that you have parsed each sub template file, + + //When using subtemplating make sure that you have parsed each sub template file, //otherwise the compiler wouldn't understand what to substitute when it reads the {{template "header"}} +{% endraw %} Code: package main @@ -344,9 +346,9 @@ Code: "io/ioutil" "text/template" ) - + var templates *template.Template - + func main() { var allFiles []string files, err := ioutil.ReadDir("./templates") @@ -359,13 +361,13 @@ Code: allFiles = append(allFiles, "./templates/"+filename) } } - + templates, err = template.ParseFiles(allFiles...) #parses all .tmpl files in the 'templates' folder - + s1, _ := templates.LookUp("header.tmpl") s1.ExecuteTemplate(os.Stdout, "header", nil) fmt.Println() - s2, _ := templates.LookUp("content.tmpl") + s2, _ := templates.LookUp("content.tmpl") s2.ExecuteTemplate(os.Stdout, "content", nil) fmt.Println() s3, _ := templates.LookUp("footer.tmpl") @@ -380,19 +382,19 @@ When you don't want to use `{{define}}`, then you can just create a text file wi Templates in one set know each other, but you must parse them for every single set. -Some times you want to contextualize templates, for instance you have a `_head.html`, you might have a header who's value you have to populate based on which data you are loading for instance for a todo list manager you can have three categories `pending`, `completed`, `deleted`. for this suppose you have an if statement like this +Some times you want to contextualize templates, for instance you have a `_head.html`, you might have a header who's value you have to populate based on which data you are loading for instance for a todo list manager you can have three categories `pending`, `completed`, `deleted`. for this suppose you have an if statement like this - {{if eq .Navigation "pending"}} Tasks + <title>{{if eq .Navigation "pending"}} Tasks {{ else if eq .Navigation "completed"}}Completed {{ else if eq .Navigation "deleted"}}Deleted {{ else if eq .Navigation "edit"}} Edit {{end}} - + Note: Go templates follow the Polish notation while performing the comparison where you give the operator first and the comparison value and the value to be compared with. The else if part is pretty straight forward Typically we use a `{{ range }}` operator to loop through the context variable which we pass to the template while execution like this: - + //present in views package context := db.GetTasks("pending") //true when you want non deleted notes homeTemplate.Execute(w, context) @@ -412,31 +414,31 @@ We get the context object from the database as a struct object, the definition i Search string Message string } - + //present in database package var task []types.Task var context types.Context context = types.Context{Tasks: task, Navigation: status} - + //This line is in the database package where the context is returned back to the view. - -We use the task array and the Navigation in our templates, we saw how we use the Navigation in the template, + +We use the task array and the Navigation in our templates, we saw how we use the Navigation in the template, we'll see how we'll use the actual task array in our template. - + Here in the `{{ if .Tasks }}` we first check if the Tasks field of our context object which we passed to the template while executing is empty or not. If it is not empty then we will range through that array to populate the title and content of Task. The below example is very important when it comes to looping through an array in a template, we start with the Range operator, then we can give any member of that struct as `{{.Name}}`, my Task structure has a Title and a Content, (please note the capital T and C, they are exported names and they need to be capitalised unless you want to make them private). - - so {{ range .Tasks }} - {{ .Title }} - {{ .Content }} - {{ end }} - + + {{ range .Tasks }} + {{ .Title }} + {{ .Content }} + {{ end }} + This block of code will print each title and content of the Task array. Below is a full example from github.com/thewhitetulip/Tasks home.html template. - +
{{ if .Tasks}} {{range .Tasks}}
From a91ae34cf055f0a45e030f1cf723be2cb728a69f Mon Sep 17 00:00:00 2001 From: Denis Koltsov Date: Sat, 19 Nov 2016 14:09:06 +0100 Subject: [PATCH 4/4] Fix japanese book missing src folder preventing book to be built --- ja/src | 1 - ja/src/.DS_Store | Bin 0 -> 6148 bytes ja/src/1.2/main.go | 13 +++++++++++++ ja/src/1.2/sqrt.go | 11 +++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) delete mode 120000 ja/src create mode 100644 ja/src/.DS_Store create mode 100644 ja/src/1.2/main.go create mode 100644 ja/src/1.2/sqrt.go diff --git a/ja/src b/ja/src deleted file mode 120000 index 9fc720a7..00000000 --- a/ja/src +++ /dev/null @@ -1 +0,0 @@ -../../ebook/src \ No newline at end of file diff --git a/ja/src/.DS_Store b/ja/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4d63beace0cee612b117b73fbb5af88423808527 GIT binary patch literal 6148 zcmeH~J!->15QX2^E(~r|rraiNz&XJp>=XC`DFSJN1A(O8qvy>}V8^P6urOo3#Su?<{=R%(-#@NztaugJM9hqp35)&OmWY4|h=2%) zfC#LJK%U~*A6E2CdK3{5fprk@??a=z_R^6WpALo?0jN8c!?=!Fg4(=5?WH4?6`Ixb zVAX0dhIl>NsjaT-r6V=lVKsbM-PwGKp;@-W8WWoJ5CstsfdzqW=98cQXZm0B|Dr{y z2#CO)5wP9qa+>*4b+-O`J+Hr1)z^bgjmsHsegc^IQT#v;<9_o6wU>@mR%rSW2n-4$ I@UH}Z06&8e+5i9m literal 0 HcmV?d00001 diff --git a/ja/src/1.2/main.go b/ja/src/1.2/main.go new file mode 100644 index 00000000..132c60a7 --- /dev/null +++ b/ja/src/1.2/main.go @@ -0,0 +1,13 @@ +// 章节 1.2 +// $GOPATH/src/mathapp/main.go + +package main + +import ( + "fmt" + "mymath" +) + +func main() { + fmt.Printf("Hello, world. Sqrt(2) = %v\n", mymath.Sqrt(2)) +} diff --git a/ja/src/1.2/sqrt.go b/ja/src/1.2/sqrt.go new file mode 100644 index 00000000..1d596053 --- /dev/null +++ b/ja/src/1.2/sqrt.go @@ -0,0 +1,11 @@ +// 章节 1.2 +// $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 +}