2020. 4. 18. 13:18ㆍGo
Hi everybody, In this post, We are going to make a Go language developing environment for VisualStudie Code.
Let's install Go
1. Install Go Language.
It's easy for everyone. just Download Go.
2. Set system variable.
Open 'Edit Environment Variables' and click the 'Environment Variable'
GOPATH that mean is 'Where is Your Workplace'. So you just write there where directory you want to create.
then, create or edit your GOPATH where in SYSTEM VARIABLE section.
Moreover, you should add %GOPATH%bin path in PATH.
It's done. Isn't very simple?
3. Open Your visual studio code
Go to the Extensions menu then search Go.
You can find the Go extension easliy.
And then Open the Extensions Settings of Go.
So you have to check up if go.useLanguageServer is false. If it is true, then you have to change the value to 'false'.
4. Go modules Setup
Open GOPATH what you set and create three folders whiches mean is each as 'binary', 'package(your installed)', 'src(your local modules and your main.go)'
If you have finished like that, then open the terminal.
In 'src' folder, you should type 'go mod init <module-name>'.
The module-name will be your project-name. So, I choosed "github.com/myname/myfirstprj"
After this there are one or two files appeared.
go.mod or go.sum. anyway, if you open the go.mod, you can see like this sentences.
now, the setting has done.
let's make your local module and main.go
5. Your modules
create your module directory, main.go in src and create module.go on module directory.
You can see like this file structure. (except go.sum)
Let's write code.
main.go
package main
import (
"fmt"
"github.com/derekyu/myfirstprj" // It must be the module-name that you initlized(mod)
)
func main() {
fmt.Println(mymodule.MyModule())
}
mymodule.go
package mymodule
func MyModule() string {
return "My Module Function"
}
To build your code, go src and type 'go build' on your terminal.
myfirstprj.exe will be created.
It was very simple and clear.
Thank you for reading.
'Go' 카테고리의 다른 글
How to sign in and sign up with Firebase on Javascript (0) | 2020.04.25 |
---|---|
How to use 'Html/Template' For your Echo Server in Go! (0) | 2020.04.18 |
C# WebSocket-Sharp, Make it more smart (0) | 2020.04.13 |
C# The way to make Real-time audio communication RTC in WPF with WebSocket-Sharp (0) | 2020.04.12 |
[Go] 데이터베이스 Sqlite3 사용하기 (0) | 2020.03.11 |