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
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
120
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
Test your architecture with Archunit
thirion
1
2.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.9k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
400
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
640
Building AI with AI
inesmontani
PRO
1
800
Testing 201, or: Great Expectations
jmmastey
46
8.1k
Embracing the Ebb and Flow
colly
88
5k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
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ͷϑΟʔϧυࢦఆ͠ΕΛ ੩తʹݕͰ͖Δ