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 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
440
1
Share
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
180
Песнь Хорьков и Гоферов
aleksi
0
390
Fuzzy generics
aleksi
0
190
On Ferrets and Gophers
aleksi
0
270
How to Go Wrong with Concurrency
aleksi
2
790
Adding context to existing code
aleksi
1
160
Зачем и как написать свой database/sql драйвер
aleksi
1
210
Cooking gRPC
aleksi
1
910
Profiling and Optimizing Go Programs
aleksi
1
1.8k
Other Decks in Programming
See All in Programming
事業会社でのセキュリティ長期インターンについて
masachikaura
0
260
第3木曜LT会 #28
tinykitten
PRO
0
110
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
CDK Deployのための ”反響定位”
watany
5
800
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
180
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
110
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
3
350
How Swift's Type System Guides AI Agents
koher
0
290
tRPCの概要と少しだけパフォーマンス
misoton665
2
230
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
550
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
150
AI-DLC Deep Dive
yuukiyo
9
4.7k
Featured
See All Featured
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.2k
GraphQLとの向き合い方2022年版
quramy
50
15k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
sira's awesome portfolio website redesign presentation
elsirapls
0
220
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
370
The browser strikes back
jonoalderson
0
980
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
170
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
55k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.2k
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