gobootcamp / book Goto Github PK
View Code? Open in Web Editor NEWSource code of the companion book/website
Home Page: http://www.golangbootcamp.com/book
Source code of the companion book/website
Home Page: http://www.golangbootcamp.com/book
I'm getting a 'duplicate argument name' with the below code
func location(name, city string) (name, continent string) {
switch city {
case "New York", "LA", "Chicago":
continent = "North America"
default:
continent = "Unknown"
}
return
}
func main() {
name, continent := location("Matt", "LA")
fmt.Printf("%s lives in %s", name, continent)
}
go version go1.4.2 darwin/amd64
Hi everyone! Exist any translating to portuguese Brazil? I'm desiring get started!
package main
import (
"fmt"
"time"
)
func timeMap(y interface{}) {
z, ok := y.(map[string]interface{})
if ok {
z["updated_at"] = time.Now()
}
}
func main() {
foo := map[string]interface{}{
"Matt": 42,
}
timeMap(foo)
fmt.Println(foo)
}
Here, timeMap func is a magic to me. You neither specify any return value for this nor pass a pointer to it while calling, but it is working fine. Can you explain the logic in it?
Thanks
p.s Your book is awesome!
Following the setup in Chapter 9, I found the repos at the bottom have moved from code.google.com.
Stevens-MacBook-Pro:go cittzl$ go get code.google.com/p/go.tools/cmd/godoc
the code.google.com/p/go.tools/cmd/godoc command has moved; use golang.org/x/tools/cmd/godoc instead.
Stevens-MacBook-Pro:go cittzl$ go get code.google.com/p/go.tools/cmd/vet
can't load package: the code.google.com/p/go.tools/cmd/vet command has moved; use golang.org/x/tools/cmd/vet instead.
In your Bitcoin exercise, you calculate the number of coins for "Augustus" as 10, when it should be 13, leaving you with -1 coins. I'd submit a pull request, but I'm not sure if you'd rather use a different name, increase the # of coins, etc.
Section 3.3 we are covering Type Assertion http://www.golangbootcamp.com/book/types#sec-type-assertion.
The examples in the book are going over interface
type assertions. I, being new to go, don't quite understand interfaces yet. So these examples are not helpful at all.
It would be better if:
Similarly, in this example we are also going over maps
which aren't covered till the next section in section 4.
Maybe Type Assertion should be moved to after all these other concepts have been covered. So that the code examples aren't so confusing to new go programmers.
Please compile new version for online book
I found,
Chapter 2: The Basics |> 2.7 Functions, signature, return values, named results
The content of online book , still old than source book
Hi,
there are a couple of dead links in the book, which reference code.google.com.
These packages seem to be moved to golang.org.
I will fix this and create a PR for that.
Mattagohni
Is this book getting updated or is this project abandoned?
Last updated date is a year ago.
Hi Matt
As stated in PR #38, we still have a problem of goroutine leak and channel leak. Some Walk
invocations will never return because they are stuck writing in a channel that is not read anymore. I revealed the leaks on my computer by calling Same
a large number of times on different trees : the memory footprint of the program, as shown by top
, kept growing and growing.
Below I will suggest two possible fixes.
My feeling about concurrency in Go is :
Possible fix 1 : "drain" the channels after use, i.e. loop to read all the potential unused values in ch1
and ch2
. So we ensure recWalk
will finish and Walk
will close the channel, so the goroutines can properly end and the channels will be garbage collected.
Advantage : it is short and straightforward to implement.
Drawback : completing the Walk
of a big tree is an undesirable amount of work when the tree comparison returns false
early : we should not have to process the remainder of the tree.
Possible fix 2 : create a quit
channel for each tree, as described in this slide.
Advantage : no more leaks, no useless work.
Drawback : the code is lengthier and more difficult to write and read.
What do you think?
I can make a pull request for (fix 1) or (fix 2) of the go code, and the paragraph would need to be updated to explain the plumbing.
Cheers
You introduce the idea of type assertion with examples of interfaces and structures.
y.(map[string]interface{})
value.(type)
Consider moving this section to advanced concepts and perhaps referencing this:
ex 3.3 Type assertion
"for more advanced subject of type conversion, please see section 2001.1" etc
EDIT: I think the whole document could use a good edit so that the examples and subjects flow with what is learned. Throughout the book, examples are presented using concepts and techniques that have not yet been introduced and explained, therefore it frustrates.
In the book, the example is shown as
`func location(name, city string) (region, continent string) {
switch city {
case "New York", "LA", "Chicago":
continent = "North America"
default:
continent = "Unknown"
}
return
}
func main() {
region, continent := location("Matt", "LA")
fmt.Printf("%s lives in %s", region, continent)
}`
But, the Go Playground shows
`package main
import "fmt"
func location(city string) (region, continent string) {
switch city {
case "Los Angeles", "LA", "Santa Monica":
region, continent = "California", "North America"
case "New York", "NYC":
region, continent = "New York", "North America"
default:
region, continent = "Unknown", "Unknown"
}
return
}
func main() {
region, continent := location("Santa Monica")
fmt.Printf("Matt lives in %s, %s", region, continent)
}
`
The Playground seems to be more correct than the code shown in the book text.
On http://www.golangbootcamp.com/book/tricks_and_tips
search for "dramatic twist", the rest of that chapter is not correctly formatted
String change - 's/page/package/g' in the following text I believe.
"Pi is exported and can be accessed from outside the page, while pi isn’t available."
2.6 Exported names
What license is this awesome book under? Could you add a LICENSE file with this information?
It seems the code in the playground (http://play.golang.org/p/aOSABxXoiU) linked at the end of section 2.7 (https://github.com/GoBootcamp/book/blob/master/chapters/basics.md#422) doesn't match the code given in the example just above it.
func location(name, city string) (name, continent string)
should be
func location(name, city string) (region, continent string)
Running the current cod in the playground will return:
prog.go:5: duplicate argument name
However, the linked playground code is correct.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.