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 개발자처럼 생각하는 방법
329
11
표준 라이브러리
11.3.7
사용자 지정
JSON
파싱
기본 기능이 충분한 경우가 많지만, 이를 재정의 해야 하는 경우가 있다.
time
.
Time
RFC
339
포맷 내에서
JSON
항목을 지원하지만 다른 시간 포맷을 처리해야할 수도 있다. 이는
json
.
Marshaler
json
.
Unmarshaler
인 두 인터페이스를 구현하여 새로운 타입을 생성해
서 처리할 수 있다.
type RFC822ZTime struct {
time.Time
}
func (rt RFC822ZTime) MarshalJSON() ([]byte, error) {
out := rt.Time.Format(time.RFC822Z)
return []byte(`”` + out + `”`), nil
}
func (rt *RFC822ZTime) UnmarshalJSON(b []byte) error {
if string(b) == “null” {
return nil
}
t, err := time.Parse(`”`+time.RFC822Z+`”`, string(b))
if err != nil {
return err
}
*rt = RFC822ZTime{t}
return nil
}
여기서
time
.
Time
인스턴스를
RFC822ZTime
이라는 새로운 구조체에 임베딩하여 계속
time
.
Time
의 ...
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