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 개발자처럼 생각하는 방법
410
러닝 Go
i, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return err
}
field.SetInt(i)
case reflect.String:
field.SetString(val)
case reflect.Bool:
b, err := strconv.ParseBool(val)
if err != nil {
return err
}
field.SetBool(b)
default:
return fmt.Errorf(“cannot handle field of kind %v”,
field.Kind())
}
}
return nil
}
해당 함수는 새롭게 생성된
reflect
.
Value
에 각 항목을 순회하며 현제 항목의
csv
구조체 태
그를 사용하여 이름을 찾고
namePos
맵을 사용하여 데이터 슬라이스 요소를 조회된 결과를 문
자열에서 알맞은 값으로 변환 및 현재 항목에 값을 설정한다. 모든 항목이 채워진 후에 함수는
반환을 한다.
마샬링과 언마샬링을 하는 것을 작성했고, 이제
Go
표준 라이브러리의 기존
CSV
지원과 통합
을 해보자.
data := `name,age,has_pet
Jon,”100”,true
“Fred “”The Hammer”” Smith”,42,false
Martha,37,”true”
`
r := csv.NewReader(strings.NewReader(data)) ...
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