Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
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
0
96
go-exhaustruct linterのすすめ
kamakura.go #8 2026/02/27
Shoichi Kaji
February 27, 2026
Tweet
Share
More Decks by Shoichi Kaji
See All by Shoichi Kaji
Parallel::Pipesの紹介
skaji
2
1.1k
宿泊予約サイトにおける検索と料金計算の両立
skaji
2
4.1k
昔のGo, 今のGo ~比較, ソート編~
skaji
0
280
Perl Quiz
skaji
0
160
cpm at PerlCon 2019
skaji
0
140
Perl5 Package Manager
skaji
0
770
Internal of cpm
skaji
0
650
How to execute external programs in Perl
skaji
3
730
Writing Perl with w0rp/ale
skaji
0
2.4k
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
290
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
77
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
320
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
480
Optimizing for Happiness
mojombo
378
71k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
680
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
Documentation Writing (for coders)
carmenintech
77
5.3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
85
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ͷϑΟʔϧυࢦఆ͠ΕΛ ੩తʹݕͰ͖Δ