From 18b796972639303e472c8f5d1575061d8c8da2ac Mon Sep 17 00:00:00 2001 From: Flo Date: Tue, 22 Oct 2019 23:11:23 +0100 Subject: add go build tags --- go.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index ae99535b..4fc155b5 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -30,6 +30,12 @@ Go comes with a good standard library and a sizeable community. /* Multi- line comment */ + /* A build tag is a line comment starting with // +build + and can be execute by go build -tags="foo bar" command. + Build tags are placed before the package clause near or at the top of the file + followed by a blank line or other line comments. */ +// +build prod, dev, test + // A package clause starts every source file. // Main is a special name declaring an executable rather than a library. package main -- cgit v1.2.3 From a7242df7d7f49ee2a7440a5a10f203d64e481f24 Mon Sep 17 00:00:00 2001 From: Michael Graf Date: Thu, 30 Jan 2020 15:29:06 -0800 Subject: go/en: add type switch and multiple cases --- go.html.markdown | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 4fc155b5..49f1ade4 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -12,6 +12,7 @@ contributors: - ["Alexej Friesen", "https://github.com/heyalexej"] - ["Clayton Walker", "https://github.com/cwalk"] - ["Leonid Shevtsov", "https://github.com/leonid-shevtsov"] + - ["Michael Graf", "https://github.com/maerf0x0"] --- Go was created out of the need to get work done. It's not the latest trend @@ -196,7 +197,7 @@ func learnFlowControl() { x := 42.0 switch x { case 0: - case 1: + case 1, 2: // Can have multiple matches on one case case 42: // Cases don't "fall through". /* @@ -208,6 +209,19 @@ func learnFlowControl() { default: // Default case is optional. } + + // Type switch allows switching on the type of something instead of value + var data interface{} + data = "" + switch c := data.(type) { + case string: + fmt.Println(c, "is a string") + case int64: + fmt.Printf("%d is an int64\n", c) + default: + // all other cases + } + // Like if, for doesn't use parens either. // Variables declared in for and if are local to their scope. for x := 0; x < 3; x++ { // ++ is a statement. -- cgit v1.2.3 From 3869472f749e74f554eda136654ec9d098cf0fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hou=C5=A1ka?= Date: Sat, 8 Feb 2020 22:57:43 +0100 Subject: [go/en] Clarify safety of local variable address taking. --- go.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 49f1ade4..ec812f20 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -168,10 +168,11 @@ func learnNamedReturns(x, y int) (z int) { // Go is fully garbage collected. It has pointers but no pointer arithmetic. // You can make a mistake with a nil pointer, but not by incrementing a pointer. +// Unlike in C/Cpp taking and returning an address of a local varible is also safe. func learnMemory() (p, q *int) { // Named return values p and q have type pointer to int. p = new(int) // Built-in function new allocates memory. - // The allocated int is initialized to 0, p is no longer nil. + // The allocated int slice is initialized to 0, p is no longer nil. s := make([]int, 20) // Allocate 20 ints as a single block of memory. s[3] = 7 // Assign one of them. r := -2 // Declare another local variable. -- cgit v1.2.3 From cd631729a89faaf1cd77d7659e86c00be18e0309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hou=C5=A1ka?= Date: Sat, 8 Feb 2020 23:11:33 +0100 Subject: [go/en] Add value/reference semantics information for arr/slices. --- go.html.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 49f1ade4..0c9082c6 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -109,6 +109,11 @@ can include line breaks.` // Same string type. a5 := [...]int{3, 1, 5, 10, 100} // An array initialized with a fixed size of five // elements, with values 3, 1, 5, 10, and 100. + // Arrays have value semantics. + a4_cpy := a4 // a4_cpy is a copy of a4, two separate instances. + a4_cpy[0] = 25 // Only a4_cpy is changed, a4 stays the same. + fmt.Println(a4_cpy[0] == a4[0]) // false + // Slices have dynamic size. Arrays and slices each have advantages // but use cases for slices are much more common. s3 := []int{4, 5, 9} // Compare to a5. No ellipsis here. @@ -116,6 +121,11 @@ can include line breaks.` // Same string type. var d2 [][]float64 // Declaration only, nothing allocated here. bs := []byte("a slice") // Type conversion syntax. + // Slices (as well as maps and channels) have reference semantics. + s3_cpy := s3 // Both variables point to the same instance. + s3_cpy[0] = 0 // Which means both are updated. + fmt.Println(s3_cpy[0] == s3[0]) // true + // Because they are dynamic, slices can be appended to on-demand. // To append elements to a slice, the built-in append() function is used. // First argument is a slice to which we are appending. Commonly, -- cgit v1.2.3 From 131d536f40ee0e28f6b88b157408835740c434f5 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Sun, 23 Feb 2020 12:44:28 +0000 Subject: Add Golang University playlist links --- go.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 739ec05d..3c0c8e18 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -13,6 +13,7 @@ contributors: - ["Clayton Walker", "https://github.com/cwalk"] - ["Leonid Shevtsov", "https://github.com/leonid-shevtsov"] - ["Michael Graf", "https://github.com/maerf0x0"] + - ["John Arundel", "https://bitfieldconsulting.com/golang"] --- Go was created out of the need to get work done. It's not the latest trend @@ -459,7 +460,7 @@ There you can follow the tutorial, play interactively, and read lots. Aside from a tour, [the docs](https://golang.org/doc/) contain information on how to write clean and effective Go code, package and command docs, and release history. -The language definition itself is highly recommended. It's easy to read +The [Go language specification](https://golang.org/ref/spec) itself is highly recommended. It's easy to read and amazingly short (as language definitions go these days.) You can play around with the code on [Go playground](https://play.golang.org/p/tnWMjr16Mm). Try to change it and run it from your browser! Note that you can use [https://play.golang.org](https://play.golang.org) as a [REPL](https://en.wikipedia.org/wiki/Read-eval-print_loop) to test things and code in your browser, without even installing Go. @@ -472,4 +473,9 @@ documentation](http://golang.org/pkg/) and the source code comes up! Another great resource to learn Go is [Go by example](https://gobyexample.com/). +There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer [John Arundel](https://bitfieldconsulting.com/golang) has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: +* [Golang University 101](https://www.youtube.com/playlist?list=PLEcwzBXTPUE9V1o8mZdC9tNnRZaTgI-1P) introduces fundamental Go concepts and shows you how to use the Go tools to create and manage Go code +* [Golang University 201](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) steps it up a notch, explaining important techniques like testing, web services, and APIs +* [Golang University 301](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques + Go Mobile adds support for mobile platforms (Android and iOS). You can write all-Go native mobile apps or write a library that contains bindings from a Go package, which can be invoked via Java (Android) and Objective-C (iOS). Check out the [Go Mobile page](https://github.com/golang/go/wiki/Mobile) for more information. -- cgit v1.2.3 From e3c1b63e555733f81d5bdd41b5e1332afb088c7b Mon Sep 17 00:00:00 2001 From: John Arundel Date: Tue, 25 Feb 2020 18:16:47 +0000 Subject: Fix playlist link --- go.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 3c0c8e18..0866fcae 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -476,6 +476,6 @@ Another great resource to learn Go is [Go by example](https://gobyexample.com/). There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer [John Arundel](https://bitfieldconsulting.com/golang) has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: * [Golang University 101](https://www.youtube.com/playlist?list=PLEcwzBXTPUE9V1o8mZdC9tNnRZaTgI-1P) introduces fundamental Go concepts and shows you how to use the Go tools to create and manage Go code * [Golang University 201](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) steps it up a notch, explaining important techniques like testing, web services, and APIs -* [Golang University 301](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques +* [Golang University 301](https://www.youtube.com/watch?v=YHRO5WQGh0k&list=PLEcwzBXTPUE8KvXRFmmfPEUmKoy9LfmAf) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques Go Mobile adds support for mobile platforms (Android and iOS). You can write all-Go native mobile apps or write a library that contains bindings from a Go package, which can be invoked via Java (Android) and Objective-C (iOS). Check out the [Go Mobile page](https://github.com/golang/go/wiki/Mobile) for more information. -- cgit v1.2.3 From 32f3ec1880a15db2ab37955612631609e2400698 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Wed, 26 Feb 2020 15:23:37 +0000 Subject: Update go.html.markdown Remove link in body --- go.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 0866fcae..726bb134 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -473,7 +473,7 @@ documentation](http://golang.org/pkg/) and the source code comes up! Another great resource to learn Go is [Go by example](https://gobyexample.com/). -There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer [John Arundel](https://bitfieldconsulting.com/golang) has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: +There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer John Arundel of Bitfield Consulting has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: * [Golang University 101](https://www.youtube.com/playlist?list=PLEcwzBXTPUE9V1o8mZdC9tNnRZaTgI-1P) introduces fundamental Go concepts and shows you how to use the Go tools to create and manage Go code * [Golang University 201](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) steps it up a notch, explaining important techniques like testing, web services, and APIs * [Golang University 301](https://www.youtube.com/watch?v=YHRO5WQGh0k&list=PLEcwzBXTPUE8KvXRFmmfPEUmKoy9LfmAf) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques -- cgit v1.2.3 From 2643d9f2f05a2162e39d281b47d4986e82b36ff8 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Thu, 27 Feb 2020 11:50:39 +0000 Subject: Remove links/source mention --- go.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 726bb134..b727e59d 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -13,7 +13,7 @@ contributors: - ["Clayton Walker", "https://github.com/cwalk"] - ["Leonid Shevtsov", "https://github.com/leonid-shevtsov"] - ["Michael Graf", "https://github.com/maerf0x0"] - - ["John Arundel", "https://bitfieldconsulting.com/golang"] + - ["John Arundel", "https://github.com/bitfield"] --- Go was created out of the need to get work done. It's not the latest trend @@ -473,7 +473,7 @@ documentation](http://golang.org/pkg/) and the source code comes up! Another great resource to learn Go is [Go by example](https://gobyexample.com/). -There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer John Arundel of Bitfield Consulting has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: +There are many excellent conference talks and video tutorials on Go available on YouTube, and here are three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: * [Golang University 101](https://www.youtube.com/playlist?list=PLEcwzBXTPUE9V1o8mZdC9tNnRZaTgI-1P) introduces fundamental Go concepts and shows you how to use the Go tools to create and manage Go code * [Golang University 201](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) steps it up a notch, explaining important techniques like testing, web services, and APIs * [Golang University 301](https://www.youtube.com/watch?v=YHRO5WQGh0k&list=PLEcwzBXTPUE8KvXRFmmfPEUmKoy9LfmAf) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques -- cgit v1.2.3