[학습 노트] Golang: Golang 1.16의 새로운 기능에 대한 간단한 소개
Source: Dev.to
TL;DR
이 글에서는 다음을 소개합니다:
How to install the Golang 1.16 preview version
시험해 보고 싶고 Homebrew에서 아직 지원되는 Golang 버전이 없을 경우(2021‑02‑19 기준), 로컬에 테스트 버전을 설치할 수 있습니다:
go get golang.org/dl/go1.16
go1.16 download
컴파일된 바이너리가 로컬에 설치됩니다. 이후 go1.16 build 혹은 go1.16 test와 같은 명령을 실행할 수 있습니다.
Main list of new features in 1.16
Apple Silicon (i.e., the current Apple M1 Chip) support
Go 1.16은 Apple Silicon(64‑bit ARM)을 공식 지원합니다. 다음 컴파일러 파라미터를 사용하세요:
GOOS=darwin GOARCH=arm64 # Apple M1용 macOS
(iOS의 경우 GOOS=darwin GOARCH=ios/arm64를 사용합니다.)
Apple M1용 바이너리를 컴파일하려면:
env GOOS=darwin GOARCH=arm64 go build
Go Module Retract
버전 리트랙션을 통해 모듈 작성자는 특정 버전을 문제 있는 것으로 표시할 수 있습니다. 자세한 내용은 다음 글을 참고하세요:
Go 1.16 New Feature “Version Retraction (Removal)” (Go Modules retraction)
Embedding Files (including static files in the project)
Go 1.16 이전에는 정적 파일을 go-bindata, packr, pkger와 같은 우회 방법으로 처리해야 했습니다. Go 1.16부터는 embed 패키지를 통해 네이티브 지원이 추가되었습니다.
다음과 같은 프로젝트 구조를 가정합니다:
.
├── go.mod
├── main.go
├── static
│ └── css
│ └── main.css
├── templates
│ └── index.html.tmpl
└── title.txt
파일을 직접 Go 코드에 임베드할 수 있습니다. 전체 예시는 해당 gist를 참고하세요.
Related information
- Go Doc: Embed Files
- Embedding static files in a Go binary using go embed (Medium)
- How to embed files into Go binaries (Stack Overflow)