From 930a66a6d3faabd959464cb21647a3f3584cc871 Mon Sep 17 00:00:00 2001 From: Chris James Date: Thu, 18 Jun 2020 14:32:37 +0100 Subject: [PATCH] Oof, some PRs on master that should be on main (#362) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update outdated descriptions and links (#358) * Update reflection.md (#361) Code examples for chan and func are incorrect Co-authored-by: 森 優太 mori <59682979+uta-mori@users.noreply.github.com> Co-authored-by: Johan Baaij --- install-go.md | 14 +++++++------- reflection.md | 32 ++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/install-go.md b/install-go.md index cebafa090..e959a3cad 100644 --- a/install-go.md +++ b/install-go.md @@ -17,7 +17,7 @@ xcode-select --install Then you run the following to install homebrew: ```sh -/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" ``` At this point you can now install Go with: @@ -85,7 +85,7 @@ A `go.mod` file could look like this: ``` module cmd -go 1.12 +go 1.14 require ( github.com/google/pprof v0.0.0-20190515194954-54271f7e092f @@ -117,13 +117,13 @@ You can confirm VS Code installed correctly you can run the following in your sh code . ``` -VS Code is shipped with very little software enabled, you can enable new software by installing extensions. To add Go support you must install an extension, there are a variety available for VS Code, an exceptional one is [Luke Hoban's package](https://github.com/Microsoft/vscode-go). This can be installed as follows: +VS Code is shipped with very little software enabled, you can enable new software by installing extensions. To add Go support you must install an extension, there are a variety available for VS Code, an exceptional one is [Luke Hoban's package](https://github.com/golang/vscode-go). This can be installed as follows: ```sh -code --install-extension ms-vscode.go +code --install-extension golang.go ``` -When you open a Go file for the first time in VS Code, it will indicate that the Analysis tools are missing, you should click the button to install these. The list of tools that gets installed (and used) by VS Code are available [here](https://github.com/Microsoft/vscode-go/wiki/Go-tools-that-the-Go-extension-depends-on). +When you open a Go file for the first time in VS Code, it will indicate that the Analysis tools are missing, you should click the button to install these. The list of tools that gets installed (and used) by VS Code are available [here](https://github.com/golang/vscode-go/blob/master/docs/tools.md). ## Go Debugger @@ -133,11 +133,11 @@ A good option for debugging Go (that's integrated with VS Code) is Delve. This c go get -u github.com/go-delve/delve/cmd/dlv ``` -For additional help configuring and running the Go debugger in VS Code, please reference the [VS Code debugging documentation](https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code). +For additional help configuring and running the Go debugger in VS Code, please reference the [VS Code debugging documentation](https://github.com/golang/vscode-go/blob/master/docs/debugging.md). ## Go Linting -An improvement over the default linter can be configured using [GolangCI-Lint](https://github.com/golangci/golangci-lint). +An improvement over the default linter can be configured using [GolangCI-Lint](https://golangci-lint.run). This can be installed as follows: diff --git a/reflection.md b/reflection.md index 98794b670..e3d8b4fab 100644 --- a/reflection.md +++ b/reflection.md @@ -818,20 +818,24 @@ We can iterate through all values sent through channel until it was closed with func walk(x interface{}, fn func(input string)) { val := getValue(x) - var getField func(int) reflect.Value + walkValue := func(value reflect.Value) { + walk(value.Interface(), fn) + } switch val.Kind() { case reflect.String: fn(val.String()) case reflect.Struct: - numberOfValues = val.NumField() - getField = val.Field + for i := 0; i < val.NumField(); i++ { + walkValue(val.Field(i)) + } case reflect.Slice, reflect.Array: - numberOfValues = val.Len() - getField = val.Index + for i := 0; i < val.Len(); i++ { + walkValue(val.Index(i)) + } case reflect.Map: for _, key := range val.MapKeys() { - walk(val.MapIndex(key).Interface(), fn) + walkValue(val.MapIndex(key)) } case reflect.Chan: for v, ok := val.Recv(); ok; v, ok = val.Recv() { @@ -879,20 +883,24 @@ Non zero-argument functions do not seem to make a lot of sense in this scenario. func walk(x interface{}, fn func(input string)) { val := getValue(x) - var getField func(int) reflect.Value + walkValue := func(value reflect.Value) { + walk(value.Interface(), fn) + } switch val.Kind() { case reflect.String: fn(val.String()) case reflect.Struct: - numberOfValues = val.NumField() - getField = val.Field + for i := 0; i < val.NumField(); i++ { + walkValue(val.Field(i)) + } case reflect.Slice, reflect.Array: - numberOfValues = val.Len() - getField = val.Index + for i := 0; i < val.Len(); i++ { + walkValue(val.Index(i)) + } case reflect.Map: for _, key := range val.MapKeys() { - walk(val.MapIndex(key).Interface(), fn) + walkValue(val.MapIndex(key)) } case reflect.Chan: for v, ok := val.Recv(); ok; v, ok = val.Recv() {