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
210
Песнь Хорьков и Гоферов
aleksi
0
400
Fuzzy generics
aleksi
0
200
On Ferrets and Gophers
aleksi
0
300
How to Go Wrong with Concurrency
aleksi
2
820
Adding context to existing code
aleksi
1
190
Зачем и как написать свой database/sql драйвер
aleksi
1
220
Cooking gRPC
aleksi
1
940
Profiling and Optimizing Go Programs
aleksi
1
1.8k
Other Decks in Programming
See All in Programming
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
220
自分的「カンファレンスの楽しみ方」
syumai
0
200
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
520
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
1.5k
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
230
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
220
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
200
スマート反転とウェブアクセシビリティ
camiha
0
170
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
110
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
480
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
180
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
A Soul's Torment
seathinner
7
3.6k
Facilitating Awesome Meetings
lara
57
7.1k
Music & Morning Musume
bryan
47
7.4k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
We Are The Robots
honzajavorek
0
350
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
[SF Ruby Conf 2025] Rails X
palkan
2
1.4k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Why Our Code Smells
bkeepers
PRO
340
58k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
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