Andrew (HQT)

Setting dev environment for Golang in Window

- Install Golang compiler 
- Install Goland IDE
- Build helloworld app in Golang
- Where to start learning?
- Add 'go fmt' and checkstyle to Goland IDE
- Create sample project 
- Auto generating unit test with gotest

1. Install Golang compiler

Setting GOROOT in Window 10

2. Install Goland IDE

To code Golang, you can use any IDE that is best convenient for you. For example Sublime, Vim, VS, Goland In my case, I would like to suggest to use Goland IDE because it is best Golang IDE at the time I write this blog. Link: https://www.jetbrains.com/go/

3. Build helloworld app in Golang

4. Where to start learning?

5. Add ‘go fmt’ to Goland

‘go fmt’ is a tool of Golang being used to format Golang code. We can add this tool to Goland IDE to run this tool every time the file of code is saved.

6. Install ‘checkstyle’ to Goland

checkstyle tool is a general tool to checking Golang code styles. We can change setting in it’s config file.
Steps:

checkstyle.PNG

Force common style rules:

    {
        "file_line":500,
        "func_line":70,
        "params_num":7,
        "results_num":3,
        "formated": true,
        "pkg_name": true,
        "camel_name": true,
        "ignore":[
            "testdata/*",
            "temp/*"
        ],
        "fatal":[
            "formated",
            "file_line",
            "func_line",
            "params_num",
            "results_num",
            "formated",
            "pkg_name",
            "camel_name"
        ]
    }

7. Setup ‘gotest’ and generate Unit test cases

Golang has built-in “testing” package. Which can help us creating unit test cases easily.
To generate test cases template automatically. We use this library:
https://github.com/cweill/gotests - Setup - Clone project - Build gotests -> Put the binary into somewhere of GOPATH or GOROOT paths. In my case, I put it in GOROOT folder: C:\Users\andrew\go-1.10\bin\gotests.exe