Skip to content

Commit

Permalink
Oof, some PRs on master that should be on main (quii#362)
Browse files Browse the repository at this point in the history
* Update outdated descriptions and links (quii#358)

* Update reflection.md (quii#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 <johanbaaij@gmail.com>
  • Loading branch information
3 people authored Jun 18, 2020
1 parent 3284385 commit 930a66a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
14 changes: 7 additions & 7 deletions install-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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:

Expand Down
32 changes: 20 additions & 12 deletions reflection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 930a66a

Please sign in to comment.