Go 시작하기

지니🧸·2023년 8월 29일
0

Go

목록 보기
1/8
post-thumbnail

본 게시글은 Golang Tutorial for Beginners | Full Go Course을 학습하며 작성한 개인 노트입니다.

Go를 시작하며

Go의 특징

  • 멀티코어에 적합한 디자인으로 동시성 지원
  • 동시성을 구현하기 쉽고 효율적이다
  • Python's simple syntax + efficiency/safety of C++
  • server/backend language
  • fast build time, start up, run
  • requires fewer resources
  • compiled language: compiles into single binary machine code
    • faster than interpreted languages

Go의 활용

  • 성능이 좋아야 하는 어플리케이션
  • 클라우드 등의 플랫폼의 분산 시스템 등

How to start coding in Go

1. 모듈부터 만들자

  • 새 모듈을 생성한다
  • module path에는 레포지토리 이름 사용하면 됨

터미널에

go mod init <module path>
  • go.mod 파일이 생성됨: 이름/모듈 경로와 Go 버전 명시

2. Go 코드의 첫줄은 패키지 명시

package main

3. Go requires the entrypoint

Go 프로젝트에 여러 파일이 존재할 때 어디서부터 실행해야할지 명시해야 함

Go 프로그램의 entrypoint는 main function이다

package main

func main() {
	Print("Hello World")
}

4. Specifically import necessary packages

Go programs are organized into packages
Go's standard library provides core packages to use

(ex) fmt provides print function

package main

import "fmt"

func main() {
	fmt.Println("Hello World")
}
import (
	"fmt"
	"strings"
)

imported packages must be used; otherwise error

5. Execute the file

go run main.go

Go keywords

profile
우당탕탕

0개의 댓글