상세 컨텐츠

본문 제목

Setting up Go develop environment for Beginners

Go

by 경밤 2020. 4. 18. 13:18

본문

반응형

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.

https://golang.org/

 

The Go Programming Language

Download Go Binary distributions available for Linux, macOS, Windows, and more. // You can edit this code! // Click here and start typing. package main import "fmt" func main() { fmt.Println("Hello, 世界") } Hello, World! Conway's Game of Life Fibonacci Clos

golang.org

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.

반응형

관련글 더보기