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 generate everything
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Alexey Palazhchenko
November 08, 2016
Programming
460
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go generate everything
Alexey Palazhchenko
November 08, 2016
More Decks by Alexey Palazhchenko
See All by Alexey Palazhchenko
Using PostgreSQL's Background Worker Processes For Fun and Profit
aleksi
0
220
Песнь Хорьков и Гоферов
aleksi
0
400
Fuzzy generics
aleksi
0
210
On Ferrets and Gophers
aleksi
0
310
How to Go Wrong with Concurrency
aleksi
2
830
Adding context to existing code
aleksi
1
190
Зачем и как написать свой database/sql драйвер
aleksi
1
230
Cooking gRPC
aleksi
1
950
Profiling and Optimizing Go Programs
aleksi
1
1.8k
Other Decks in Programming
See All in Programming
速習iPhone Duo対応
yuukiw00w
2
960
Heart of Swift Concurrency
koher
0
1.2k
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
350
Jetpack Compose Mechanisms
skydoves
2
530
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
270
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.5k
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
140
すこし踏み込む CancellationToken
htkym
2
1.6k
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
7.7k
setup-vp GitLab対応の裏側
naokihaba
0
150
Kubernetes祭り #2 OP/ED
bells17
0
100
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
470
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
390
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Ethics towards AI in product and experience design
skipperchong
2
420
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
510
Skip the Path - Find Your Career Trail
mkilby
1
240
Done Done
chrislema
187
17k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
Transcript
None
None
go generate everything
Зачем?
Зачем? • Парсеры, лексеры
Зачем? • Парсеры, лексеры • Конвертация данные (Unicode-таблицы)
Зачем? • Парсеры, лексеры • Конвертация данные (Unicode-таблицы) • Встраивание
бинарных данных
Зачем? • Парсеры, лексеры • Конвертация данные (Unicode-таблицы) • Встраивание
бинарных данных • Bailerplate, автодополнение в редакторе
Зачем? • Парсеры, лексеры • Конвертация данные (Unicode-таблицы) • Встраивание
бинарных данных • Bailerplate, автодополнение в редакторе • Mocks
Зачем? • Парсеры, лексеры • Конвертация данные (Unicode-таблицы) • Встраивание
бинарных данных • Bailerplate, автодополнение в редакторе • Mocks • Generics?!
Как?
Как? • go/build
Как? • go/build • go/token, go/scanner
Как? • go/build • go/token, go/scanner • go/ast, go/parser
Как? • go/build • go/token, go/scanner • go/ast, go/parser •
go/constants, go/types
Как? • go/build • go/token, go/scanner • go/ast, go/parser •
go/constants, go/types • go/printer, go/format
Как проще?
Как проще? • text/template
Как проще? • text/template • golang.org/x/tools/go/buildutil
Как проще? • text/template • golang.org/x/tools/go/buildutil • golang.org/x/tools/go/ast/astutil
Как проще? • text/template • golang.org/x/tools/go/buildutil • golang.org/x/tools/go/ast/astutil • golang.org/x/tools/go/loader
github.com/josharian/impl $ impl 'c *Connected' events.Event func (c *Connected) String()
string { panic("not implemented") } func (c *Connected) Type() string { panic("not implemented") }
golang.org/x/tools/cmd/stringer $ stringer -type Type func (i Type) String() string
{ i -= 1 if i < 0 || i >= Type(len(_index)-1) { return fmt.Sprintf("Type(%d)", i+1) } return _name[_index[i]:_index[i+1]] }
//go:generate -type Type $ go generate foo/bar/baz
Generics func NewQueue() *Queue { return &Queue{items: make([]T, 0)} }
func (q *Queue) Push(item T) {} func (q *Queue) Pop() T {}
gopkg.in/reform.v1 type Struct interface { String() string Values() []interface{} Pointers()
[]interface{} View() View }
Вопросы?
Сообщество 12 golang-ru.slack.com 4gophers.ru/slack gophers.slack.com meetup.com/Golang-Moscow meetup.com/GolangNSK meetup.com/Golang-Peter golangshow.com