From 6ce8b89114da3f3fc47ac8dbd945ae35e8bff602 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 09:44:29 +0000 Subject: [PATCH 01/16] Move to gopath dir and introduce new package --- .../microsoft/vscode-remote-try-go/hello/hello.go | 8 ++++++++ .../microsoft/vscode-remote-try-go/main/server.go | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/github.com/microsoft/vscode-remote-try-go/hello/hello.go rename server.go => src/github.com/microsoft/vscode-remote-try-go/main/server.go (75%) diff --git a/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go b/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go new file mode 100644 index 0000000..f0b1780 --- /dev/null +++ b/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go @@ -0,0 +1,8 @@ +package hello + +import () + +// Hello writes a welcome string +func Hello() string { + return "Hello golang!" +} diff --git a/server.go b/src/github.com/microsoft/vscode-remote-try-go/main/server.go similarity index 75% rename from server.go rename to src/github.com/microsoft/vscode-remote-try-go/main/server.go index 90bfbb3..ee37faa 100644 --- a/server.go +++ b/src/github.com/microsoft/vscode-remote-try-go/main/server.go @@ -7,17 +7,18 @@ package main import ( "fmt" + "github.com/microsoft/vscode-remote-try-go/hello" "io" "net/http" ) -func hello(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, "Hello remote world!") +func helloOld(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, hello.Hello()) } func main() { portNumber := "9000" - http.HandleFunc("/", hello) + http.HandleFunc("/", helloOld) fmt.Println("Server listening on port ", portNumber) http.ListenAndServe(":"+portNumber, nil) } From 9f74e9ea39c2c77ef4718bbdc85191a464d81328 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 09:44:51 +0000 Subject: [PATCH 02/16] Add gopls --- .devcontainer/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4f95662..67f6324 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -22,6 +22,7 @@ RUN go get -u -v \ github.com/sqs/goreturns \ golang.org/x/tools/cmd/goimports \ golang.org/x/lint/golint \ + golang.org/x/tools/cmd/gopls \ github.com/alecthomas/gometalinter \ honnef.co/go/tools/... \ github.com/golangci/golangci-lint/cmd/golangci-lint \ From 0668677fcb155e3b0a45302e5f82bb68998b96d9 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 09:46:11 +0000 Subject: [PATCH 03/16] Use language server and infer gopath --- .devcontainer/devcontainer.json | 4 +++- .vscode/settings.json | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a7d3c13..41e715c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,6 +11,8 @@ "seccomp=unconfined" ], "settings": { - "go.gopath": "/go" + "go.gopath": "/go", + "go.inferGopath": true, + "go.useLanguageServer": true } } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5672a16 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "go.useLanguageServer": true, + "go.inferGopath": true +} \ No newline at end of file From 2abffe3bd5b8162ff6c4a16436662ce92ac9ea49 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 09:47:50 +0000 Subject: [PATCH 04/16] Point to new program location --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4b21482..a739ed3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "type": "go", "request": "launch", "mode": "debug", - "program": "${workspaceFolder}/server.go" + "program": "${workspaceFolder}/src/github.com/microsoft/vscode-remote-try-go/main/server.go" } ] } \ No newline at end of file From 824ed7d4d07ed5b02f5967160b14b4374d8182a1 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 10:11:39 +0000 Subject: [PATCH 05/16] Add godoctor for refactoring --- .devcontainer/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 67f6324..78bed94 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -15,6 +15,7 @@ RUN go get -u -v \ github.com/uudashr/gopkgs/cmd/gopkgs \ github.com/ramya-rao-a/go-outline \ github.com/acroca/go-symbols \ + github.com/godoctor/godoctor \ golang.org/x/tools/cmd/guru \ golang.org/x/tools/cmd/gorename \ github.com/rogpeppe/godef \ From cedf8363038681086000e811d5914c26813d324c Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 10:51:09 +0000 Subject: [PATCH 06/16] Add github.com/josharian/impl for method stubs --- .devcontainer/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 78bed94..529935e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -21,6 +21,7 @@ RUN go get -u -v \ github.com/rogpeppe/godef \ github.com/zmb3/gogetdoc \ github.com/sqs/goreturns \ + github.com/josharian/impl \ golang.org/x/tools/cmd/goimports \ golang.org/x/lint/golint \ golang.org/x/tools/cmd/gopls \ From 9a5fb7923285e556ad55f1f89d6fca06cd89d0ce Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 11:23:05 +0000 Subject: [PATCH 07/16] Add fillstruct --- .devcontainer/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 529935e..330917a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -22,6 +22,7 @@ RUN go get -u -v \ github.com/zmb3/gogetdoc \ github.com/sqs/goreturns \ github.com/josharian/impl \ + github.com/davidrjenni/reftools/cmd/fillstruct \ golang.org/x/tools/cmd/goimports \ golang.org/x/lint/golint \ golang.org/x/tools/cmd/gopls \ From 378e01a632c9c4c3133551888368245356bb2a5b Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 13:36:53 +0200 Subject: [PATCH 08/16] Add struct for demonstration fillstruct --- .../vscode-remote-try-go/hello/hello.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go b/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go index f0b1780..717e9c3 100644 --- a/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go +++ b/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go @@ -2,7 +2,22 @@ package hello import () + +type user struct { + ID int64 + Name string + Addr *address +} + +type address struct { + City string + ZIP int + LatLng [2]float64 +} + +var alex = user{} + // Hello writes a welcome string func Hello() string { - return "Hello golang!" + return "Hello, "+alex.Name } From 54d7510529219537537d5afcd964f283646ad35f Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 12:10:20 +0000 Subject: [PATCH 09/16] Make structs public to demonstrate add tags --- .../microsoft/vscode-remote-try-go/hello/hello.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go b/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go index 717e9c3..323b848 100644 --- a/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go +++ b/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go @@ -2,22 +2,23 @@ package hello import () - -type user struct { +// User user type +type User struct { ID int64 Name string - Addr *address + Addr *Address } -type address struct { +// Address address type +type Address struct { City string ZIP int LatLng [2]float64 } -var alex = user{} +var alex = User{} // Hello writes a welcome string func Hello() string { - return "Hello, "+alex.Name + return "Hello, " + alex.Name } From fd311b878d5c82377860c8732ca7c83dc7ef37c2 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 12:11:34 +0000 Subject: [PATCH 10/16] Change build order and add modifytags tool --- .devcontainer/Dockerfile | 46 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 330917a..5e083b2 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,28 +10,6 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get -y install --no-install-recommends apt-utils 2>&1 -RUN go get -u -v \ - github.com/mdempsky/gocode \ - github.com/uudashr/gopkgs/cmd/gopkgs \ - github.com/ramya-rao-a/go-outline \ - github.com/acroca/go-symbols \ - github.com/godoctor/godoctor \ - golang.org/x/tools/cmd/guru \ - golang.org/x/tools/cmd/gorename \ - github.com/rogpeppe/godef \ - github.com/zmb3/gogetdoc \ - github.com/sqs/goreturns \ - github.com/josharian/impl \ - github.com/davidrjenni/reftools/cmd/fillstruct \ - golang.org/x/tools/cmd/goimports \ - golang.org/x/lint/golint \ - golang.org/x/tools/cmd/gopls \ - github.com/alecthomas/gometalinter \ - honnef.co/go/tools/... \ - github.com/golangci/golangci-lint/cmd/golangci-lint \ - github.com/mgechev/revive \ - github.com/derekparker/delve/cmd/dlv 2>&1 - # gocode-gomod RUN go get -x -d github.com/stamblerre/gocode 2>&1 \ && go build -o gocode-gomod github.com/stamblerre/gocode \ @@ -48,3 +26,27 @@ ENV DEBIAN_FRONTEND=dialog # Set the default shell to bash rather than sh ENV SHELL /bin/bash + +# go tools +RUN go get -u -v \ + github.com/mdempsky/gocode \ + github.com/uudashr/gopkgs/cmd/gopkgs \ + github.com/ramya-rao-a/go-outline \ + github.com/acroca/go-symbols \ + github.com/godoctor/godoctor \ + golang.org/x/tools/cmd/guru \ + golang.org/x/tools/cmd/gorename \ + github.com/rogpeppe/godef \ + github.com/zmb3/gogetdoc \ + github.com/sqs/goreturns \ + github.com/josharian/impl \ + github.com/davidrjenni/reftools/cmd/fillstruct \ + github.com/fatih/gomodifytags \ + golang.org/x/tools/cmd/goimports \ + golang.org/x/lint/golint \ + golang.org/x/tools/cmd/gopls \ + github.com/alecthomas/gometalinter \ + honnef.co/go/tools/... \ + github.com/golangci/golangci-lint/cmd/golangci-lint \ + github.com/mgechev/revive \ + github.com/derekparker/delve/cmd/dlv 2>&1 From 2f69679a341071b9c3ee68f8f13cd3ce4f4e0a88 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 12:51:52 +0000 Subject: [PATCH 11/16] Rename method --- src/github.com/microsoft/vscode-remote-try-go/main/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/github.com/microsoft/vscode-remote-try-go/main/server.go b/src/github.com/microsoft/vscode-remote-try-go/main/server.go index ee37faa..91d962d 100644 --- a/src/github.com/microsoft/vscode-remote-try-go/main/server.go +++ b/src/github.com/microsoft/vscode-remote-try-go/main/server.go @@ -12,13 +12,13 @@ import ( "net/http" ) -func helloOld(w http.ResponseWriter, r *http.Request) { +func handle(w http.ResponseWriter, r *http.Request) { io.WriteString(w, hello.Hello()) } func main() { portNumber := "9000" - http.HandleFunc("/", helloOld) + http.HandleFunc("/", handle) fmt.Println("Server listening on port ", portNumber) http.ListenAndServe(":"+portNumber, nil) } From 60a049bf7823b67b824bf6a5c4b36a74ed7fbf94 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 12:53:33 +0000 Subject: [PATCH 12/16] Add github.com/cweill/gotests for test generation --- .devcontainer/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5e083b2..dcba975 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -42,6 +42,7 @@ RUN go get -u -v \ github.com/josharian/impl \ github.com/davidrjenni/reftools/cmd/fillstruct \ github.com/fatih/gomodifytags \ + github.com/cweill/gotests/... \ golang.org/x/tools/cmd/goimports \ golang.org/x/lint/golint \ golang.org/x/tools/cmd/gopls \ From ded18bad50136dfe35ca1447d43dbc8b6d9243a3 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 12:58:29 +0000 Subject: [PATCH 13/16] Extend the docu with the new functionality --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13f9c0f..9924b5d 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,26 @@ Some things to try: - Press F1 and run the **Remote-Containers: Forward Port from Container...** command. - Select port 5000. - Click "Open Browser" in the notification that appears to access the web app on this new port. - +3. **Refactoring - rename:** + - Open `hello.go`, select method name `Hello` press F1 and run the **Rename Symbol** command. +3. **Refactoring - extract:** + - Open `hello.go` and select string, press F1 and run the **Go: Extract to variable** command. + - Open `hello.go` and select line with return statement, press F1 and run the **Go: Extract to function** command. +3. **Generate tests:** + - Open `hello.go` and press F1 and run the **Go: Generate Unit Tests For File** command. + - Implement a test case: Open file `hello_test.go` and edit the line with the `TODO` comment: `{"hello without name", "Hello, "},` + - You can toggle between implementation file and test file with press F1 and run the **Go: Toggle Test File** + - Tests can also run as benchmarks: Open file `hello_test.go`, press F1 and run the **Go: Benchmark File** +4. **Stub generation:** ( [details](https://github.com/josharian/impl)) + - define a struct `type mock struct {}`, enter a new line , press F1 and run the **Go: Generate interface stubs** command. + - edit command `m *mock http.ResponseWriter` +4. **Fill structs:** ( [details](https://github.com/davidrjenni/reftools/tree/master/cmd/fillstruct)) + - Open `hello.go` and select `user{}` of variable asignment, press F1 and run the **Go: Fill struct** command. +4. **Add json tags to structs:** ( [details](https://github.com/fatih/gomodifytags)) + - Open `hello.go` and go with cursor in to a struct, press F1 and run the **Go: Add Tags To Struct Fields** command. + + + ## Contributing This project welcomes contributions and suggestions. Most contributions require you to agree to a From b6cda78c17aae7233b15df7a0d9aea90d5747eec Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 13:38:07 +0000 Subject: [PATCH 14/16] Simplify folder structure --- .../microsoft/vscode-remote-try-go => }/hello/hello.go | 0 .../microsoft/vscode-remote-try-go => }/main/server.go | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{github.com/microsoft/vscode-remote-try-go => }/hello/hello.go (100%) rename src/{github.com/microsoft/vscode-remote-try-go => }/main/server.go (92%) diff --git a/src/github.com/microsoft/vscode-remote-try-go/hello/hello.go b/src/hello/hello.go similarity index 100% rename from src/github.com/microsoft/vscode-remote-try-go/hello/hello.go rename to src/hello/hello.go diff --git a/src/github.com/microsoft/vscode-remote-try-go/main/server.go b/src/main/server.go similarity index 92% rename from src/github.com/microsoft/vscode-remote-try-go/main/server.go rename to src/main/server.go index 91d962d..2afa31f 100644 --- a/src/github.com/microsoft/vscode-remote-try-go/main/server.go +++ b/src/main/server.go @@ -7,7 +7,7 @@ package main import ( "fmt" - "github.com/microsoft/vscode-remote-try-go/hello" + "hello" "io" "net/http" ) From 4c65000c4c1f75a86e71b5b9dc6d25650bb6dcb1 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 13:42:27 +0000 Subject: [PATCH 15/16] Point to the correct dir --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a739ed3..a99da60 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "type": "go", "request": "launch", "mode": "debug", - "program": "${workspaceFolder}/src/github.com/microsoft/vscode-remote-try-go/main/server.go" + "program": "${workspaceFolder}/src/main/server.go" } ] } \ No newline at end of file From 9ca36323da7ee199898df7c9348c30ff91a346b3 Mon Sep 17 00:00:00 2001 From: Alexander Krieg Date: Sat, 15 Jun 2019 18:46:53 +0000 Subject: [PATCH 16/16] Add goplay for running in go playground --- .devcontainer/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index dcba975..ddf0c1e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -38,6 +38,7 @@ RUN go get -u -v \ golang.org/x/tools/cmd/gorename \ github.com/rogpeppe/godef \ github.com/zmb3/gogetdoc \ + github.com/haya14busa/goplay/cmd/goplay \ github.com/sqs/goreturns \ github.com/josharian/impl \ github.com/davidrjenni/reftools/cmd/fillstruct \