diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4f95662..ddf0c1e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,24 +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 \ - golang.org/x/tools/cmd/guru \ - golang.org/x/tools/cmd/gorename \ - github.com/rogpeppe/godef \ - github.com/zmb3/gogetdoc \ - github.com/sqs/goreturns \ - golang.org/x/tools/cmd/goimports \ - golang.org/x/lint/golint \ - 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 \ @@ -44,3 +26,29 @@ 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/haya14busa/goplay/cmd/goplay \ + github.com/sqs/goreturns \ + 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 \ + 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 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/launch.json b/.vscode/launch.json index 4b21482..a99da60 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/main/server.go" } ] } \ 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 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 diff --git a/src/hello/hello.go b/src/hello/hello.go new file mode 100644 index 0000000..323b848 --- /dev/null +++ b/src/hello/hello.go @@ -0,0 +1,24 @@ +package hello + +import () + +// User user type +type User struct { + ID int64 + Name string + Addr *Address +} + +// Address address type +type Address struct { + City string + ZIP int + LatLng [2]float64 +} + +var alex = User{} + +// Hello writes a welcome string +func Hello() string { + return "Hello, " + alex.Name +} diff --git a/server.go b/src/main/server.go similarity index 80% rename from server.go rename to src/main/server.go index 90bfbb3..2afa31f 100644 --- a/server.go +++ b/src/main/server.go @@ -7,17 +7,18 @@ package main import ( "fmt" + "hello" "io" "net/http" ) -func hello(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, "Hello remote world!") +func handle(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, hello.Hello()) } func main() { portNumber := "9000" - http.HandleFunc("/", hello) + http.HandleFunc("/", handle) fmt.Println("Server listening on port ", portNumber) http.ListenAndServe(":"+portNumber, nil) }