Go Getting Started

2020.04.24
yesdoing

목차

  • What is the Go?
  • How to Install
  • Project Setting
  • Go Fundamentals
  • Examples

What is the Go?

Go(Golang) 은 2009년에 구글에서 개발한
컴파일 프로그래밍 언어로 다양한 목적을 가지고 개발되었습니다.

What is the Go?

Go는 다음과 같은 장점들을 가지고 있습니다.

What is the Go?

What is the Go?

간결한 문법

Go는 등록된 Keyword의 수가 다른 언어보다 적습니다.

배우고 이해해야 할 키워드의 수가 적기 때문에 간결하고
이해하기 쉬운 코드를 작성하기 쉽습니다.

What is the Go?

빠른 컴파일 속도

Go provides a model for software construction that makes dependency analysis easy and avoids much of the overhead of C-style include files and libraries.

What is the Go?

동시성

Go 의 특징을 말할 때 동시성을 빼놓을 수 없습니다.
Go는 다른 언어에 비해 쉽게 동시성 코드를 작성 할 수 있으며
처음 언어를 설계할 때부터 개발팀이 동시성을 고려하여
언어의 설계와 GC를 설계하였습니다.

What is the Go?

What is the Go?

타입 시스템

고는 계층구조가 없는 유연한 타입 시스템을 제공합니다. 

Go는 합성이라고 부르는 디자인 패턴과 비슷하게 메서드를
재 사용하기 위해 타입을 받습니다.

이로 인해 결합성을 떨어뜨리고 높은 응집도를 가진
모델링을 구현할 수 있습니다.

How to install?

How to install

설치 방법은 크게 2가지로 나뉩니다.

  1. 홈페이지에서 설치
  2. homebrew 를 통한 설치

How to install

1. 홈페이지를 통한 설치

  • https://golang.org에 접속해 귀여운 Gopher 아래의 Download 버튼을 눌러주세요.

How to install

1. 홈페이지를 통한 설치

홈페이지를 통한 설치 시 설치 프로그램이 자동으로 GOPATH를 잡아줍니다.

하지만 GOPATH 설정을 바꾸고 싶으시면 터미널의 bash 파일에서
PATH를 수정해 주시면 됩니다.

How to install

2. Homebrew를 이용한 설치

 

  1. brew install go
  2. bash 파일에 GOPATH 설정
    1. export GOPATH=$HOME/go
    2. export PATH=$PATH:$GOPATH/bin
  3. GOPATH에 3가지 파일 생성
    1. mkdir $GOPATH/src
    2. mkdir $GOPATH/bin
    3. mkdir $GOPATH/pkg

How to install

GOPATH에 만든 3가지 파일은 다음과 같은 역할을 가지고 있습니다.

  1. bin/ : 바이너리 파일 저장소로 실행파일이 들어갑니다.
  2. pkg/ : 패키지 파일들이 들어가는 장소로 라이브러리 파일들이나 빌드된 go 코드들이 저장되는 파일입니다. 
  3. src/ : 소스코드가 저장되는 장소로 자신의 패키지 경로를 만들고 그 경로 아래에서 코드를 작성해야합니다. 

Project Setting

Project Setting

Go V1.11 이전 까지는 GOPATH의 src 폴더 아래에서만
코드 작성이 가능했습니다.

 

하지만 Go V1.11 에서 Go modules 가 나오면서 GOPATH 외부에서 Go 소스코드 작성이 가능하게 되었습니다.

 

Project Setting

Go modules 를 사용하여 Go Project를
생성하는 방법은 다음과 같습니다.

modulepath를 작성하면 go.mod 파일이 생성되면서
go version과 build에 필요한 dependency 가 쓰여집니다.

Go Fundamentals

Hello Go!

Go

Java

Variables

Variables Types

Go 의 Primitive Types
int8 은 int로 축약해서
사용 할 수 있지만
float type은 축약을 할 수 없다. 

Array & Iteration

struct & method

Example

Go Getting Started

By yesdoing

Go Getting Started

  • 166