[Go] Go 언어 시작하기 (VS Code 사용 및 설치)
이번 포스팅은 GO언어와
vscode 설치에 관한 포스팅입니다.
Mac에 VScode 설치
- 아래 홈페이지에 접속해서 Mac 버전의 vscode를 설치
Visual Studio Code - Code Editing. Redefined
Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.
code.visualstudio.com
- 설치가 완료되면 아래와 같은 화면을 볼 수 있음
- VScode에서 Go언어를 편하게 사용하기 위해 Go extension을 설치한다
- 터미널에서 code . 명령어로 바로 vscode를 열기 위해 path에 추가해줘야 한다.
아래와 같이 vscode를 오픈한 상태에서 command + shift + p를 누르면 아래와 같은 검색 창이 뜬다
shell command라고 검색하면 Install 'code' command in PATH가 첫 번째로 나오고 클릭하면 된다
- 원하는 경로에 들어가서 code. 을 입력하면 바로 vscode 실행
Go 설치
- 아래 홈페이지에 접속해서 go를 설치
Downloads - The Go Programming Language
Downloads After downloading a binary release suitable for your system, please follow the installation instructions. If you are building from source, follow the source installation instructions. See the release history for more information about Go releases
golang.org
- 각자의 컴퓨터에 맞는 버전을 선택하여 다운로드
- Apple macOS 기준으로 설치 진행, 설치가 잘 되었는지 확인하기 위해
$ go version
VScode에서 Go 사용
- 설치된 go의 정보 확인
$ go env
- 위에서 출력된 gopath에 해당하는 폴더로 접속 or 디렉터리 생성
- go/ 밑에 서브 디렉토리 3개를 생성한다.
$ mkdir bin
$ mkdir src
$ mkdir pkg
- src로 들어가서 프로젝트 폴더 생성
$ mkdir learngo
- 프로젝트 폴더 안쪽에서 main.go 파일을 생성
$ touch main.go
- 프로젝트 폴더 안에서 vscode 실행 (위에서 vscode 설정을 해줘야 실행된다)
$ code .
- vscode 아래 파란 부분에 설치가 warning이 뜨면 클릭하여 설치한다 ("Analsis Tools Missing")
Go언어로 Hello World 출력
- 위에서 생성 한 main.go파일에 아래와 같이 작성
package main
import "fmt"
func main() {
fmt.Plintln("Hello World")
}
- vscode 터미널에서 main.go 실행
$ go run main.go