Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
go-exhaustruct linterのすすめ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Shoichi Kaji
February 27, 2026
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
go-exhaustruct linterのすすめ
kamakura.go #8 2026/02/27
Shoichi Kaji
February 27, 2026
More Decks by Shoichi Kaji
See All by Shoichi Kaji
Parallel::Pipesの紹介
skaji
2
1.1k
宿泊予約サイトにおける検索と料金計算の両立
skaji
2
4.2k
昔のGo, 今のGo ~比較, ソート編~
skaji
0
310
Perl Quiz
skaji
0
180
cpm at PerlCon 2019
skaji
0
150
Perl5 Package Manager
skaji
0
800
Internal of cpm
skaji
0
660
How to execute external programs in Perl
skaji
3
750
Writing Perl with w0rp/ale
skaji
0
2.5k
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
It's Worth the Effort
3n
188
29k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
340
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
New Earth Scene 8
popppiees
3
2.5k
How STYLIGHT went responsive
nonsquared
100
6.3k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
470
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Un-Boring Meetings
codingconduct
0
410
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Transcript
go-exhaustruct linterͷ͢͢Ί Shoichi Kaji
ҙࣝ package user type Input struct { Name string Age
int } type User struct { Name string Age int } func New(input Input) (*User, error) { // όϦσʔγϣϯͳͲΛ͔·͢ return &User{ Name: input.Name, Age: input.Age, }, nil } user.User͕͋Δͱ͢Δ ͦΕΛ֤ॴͰ͍ͬͯΔ // ༻ॴ1 usr, err := user.New(user.Input{ Name: "Taro", Age: 25, }) // ༻ॴ2 for _, r := range results { u, err := user.New(user.Input{ Name: r.Name, Age: r.Age, }) // ... }
ҙࣝ package user type Input struct { Name string Age
int Address string // Ճʂ } type User struct { Name string Age int Address string } func New(input Input) (*User, error) { // όϦσʔγϣϯͳͲΛ͔·͢ return &User{ Name: input.Name, Age: input.Age, Address: input.Address, }, nil } user.UserʹAddressՃ AddressΛՃ͠ΕΔ😢 // ༻ॴ1 usr, err := user.New(user.Input{ Name: "Taro", Age: 25, Address: "Tokyo", // ͪ͜͜ΌΜͱՃͨ͠ }) // ༻ॴ2 for _, r := range results { u, err := user.New(user.Input{ Name: r.Name, Age: r.Age, // Ε͍ͯΔ... }) // ... }
ҙࣝ • structʹ৽ͨͳϑΟʔϧυΛՃͯ͠ɺgolang উखʹθϩΛิͬͯ͘ΕΔ • ୯ͳΔ"Ε"ͰϑΟʔϧυΛࢦఆ͍ͯ͠ͳͯ͘ ίϯύΠϧΤϥʔʹͳΒͳ͍ • ͜ͷθϩʹҙຯΛݟग़ࣗ͠ಈͰิͬͯ͘ΕΔͷ golangͷ͍͍ͱ͜Ζͱݴ͑Δ͕ɺ໌ࣔతʹॻ
͘ํʹ͍ͨ͠ͱ͖͋Δ
ҙࣝ • ࡢࠓɺΞϓϦέʔγϣϯΛԿʹ͚ͯߏங͢ Δ͜ͱ͕૿͍͑ͯΔ • ͦͷ߹ɺ֤ͷಠཱੑΛߴΊΔͨΊɺಉ͡ structΛ͍ճ͢ͷͰͳ͘ɺ֤ͰstructΛݸ ผʹఆٛ͢Δ͜ͱଟ͍ • ΑͬͯɺstructͷϑΟʔϧυࢦఆ͠Ε͕ى
͖͏ΔՕॴ͕૿͍͑͢
https://github.com/ GaijinEntertainment/ go-exhaustruct
go-exhaustructͱʁ • structͷϑΟʔϧυ͕શͯ໌ࣔతʹॻ͔Ε͍ͯΔ͜ ͱΛ੩తʹݕ͢Δlinter • ઌͷྫͩͱɺҎԼͷΑ͏ʹAddressࢦఆΕΛݕ Ͱ͖Δ👍 • ❯ golangci-lint
run --enable exhaustruct ./... main.go:6:23: user.Input is missing field Address (exhaustruct) usr, err := user.New(user.Input{ ^ 1 issues: * exhaustruct: 1
go-exhaustructͱʁ • ͢Ͱʹgolangci-lintͬͯΔਓenable exhaustructͱ͢Ε Α͍ • ઃఆͰ͍Ζ͍ΖΧελϚΠζࢦఆͰ͖Δ • ࠷ॳؾʹͳΔͱ͜Ζ͚ͩenableʹ͢Δͱಋೖ͍͢͠ •
coreͷpackageignoreʹͯ͠Αͦ͞͏ • ࣮ࡍɺۀΞϓϦέʔγϣϯͷCIʹΈࠐΜͰ͓Γɺgo- exhaustruct༗༻ͩͳͱࢥ͍ͬͯΔ
·ͱΊ • go-exhaustruct linterͷհΛͨ͠ • golangstructͷϑΟʔϧυΛࢦఆ͠ͳͯ͘θϩ Ͱิͬͯ͘ΕΔ͕ɺͦΕ͕ʹͳΔͱ͖͋Δ • ϨΠϠʔυΞʔΩςΫνϟͷ࠾༻Ͱݦஶʹ •
go-exhaustructͰstructͷϑΟʔϧυࢦఆ͠ΕΛ ੩తʹݕͰ͖Δ