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 개발자처럼 생각하는 방법
202
러닝 Go
return err
}
defer gz.Close()
return process(gz)
이제 압축되지 않은 파일에서 읽은 것과 동일한 코드가 압축된 파일에서 읽도록 했다.
TIP
코드가 무엇을 필요하는지 설명하는 표준 라이브러리의 인터페이스가 있다면 사용하도록 하자.
인터페이스를 만족하는 타입은 인터페이스의 일부가 아닌 추가적인 메서드를 지정하는 것은
문제가 없다. 한 세트의 사용자 코드는 이러한 메서드를 신경 쓰지 않을 수 있지만, 다른 세트
는 신경을 쓸 수 있다. 예를 들어,
io
.
File
타입은
io
.
Writer
인터페이스도 만족한다. 코드
가 파일을 읽는 것만 신경을 썼다면, 파일 인스턴스를 참조하기 위해
io
.
Reader
인터페이스만
사용하여 다른 메서드는 무시할 수 있다.
7.7
임베딩과 인터페이스
구조체에 타입을 임베딩 할 수 있는 것처럼, 인터페이스에 인터페이스를 임베딩 할 수 있다. 예
를 들어,
io
.
ReadCloser
인터페이스는
io
.
Reader
io
.
Closer
로 구성된다.
type Reader interface {
Read(p []byte) (n int, err error)
}
type Closer interface {
Close() error
}
type ReadCloser interface {
Reader
Closer
}
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