Skip to Content
러닝 Go : Go 개발자처럼 생각하는 방법
book

러닝 Go : Go 개발자처럼 생각하는 방법

by 존 보드너, 윤대석
February 2022
Beginner to intermediate
452 pages
10h 48m
Korean
Hanbit Media, Inc.
Content preview from 러닝 Go : Go 개발자처럼 생각하는 방법
246
러닝 Go
9.3.2
패키지 생성과 접근
Go
에서 패키지 만드는 것은 쉽다. 이것을 시연하는 작은 프로그램을 살펴보자. 해당 프로그
램은 깃허브
2
에서 찾아볼 수 있다.
package
_
example
내에 두 추가적인 디렉터리인
math
formatter
를 볼 수 있을 것이다.
math
디렉터리에서는
math
.
go
파일이 다음의 내용으로 구
현되어 있다.
package math
func Double(a int) int {
return a * 2
}
파일의 첫 번째 라인을
패키지 절
package
clause
이라 합니다. 그것은
package
키워드와 패키지 이
름으로 구성된다. 패키지 절은
Go
소스 파일에서 비어 있지 않고 주석이 아닌 첫 번째 라인이다.
formatter
디렉터리에는 다음의 내용을 가지는
formatter
.
go
파일이 있다.
package print
import “fmt”
func Format(num int) string {
return fmt.Sprintf(“The number is %d”, num)
}
패키지 절에서 패키지 이름이
print
라고 되어있지만,
formatter
디렉터리에 있다는 점을 유
의하자. 이것은 조금 뒤에 더 다루어 보자.
마지막으로 다음의 코드는 루트 디렉터리에 있는
main
.
go
파일의 내용이다.
package main
import ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

효율적인 리눅스 명령어 사용의 기술

효율적인 리눅스 명령어 사용의 기술

Daniel J Barrett

Publisher Resources

ISBN: 9791162245309