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
Alexey Palazhchenko
November 08, 2016
Programming
1
420
Go generate everything
Alexey Palazhchenko
November 08, 2016
Tweet
Share
More Decks by Alexey Palazhchenko
See All by Alexey Palazhchenko
Using PostgreSQL's Background Worker Processes For Fun and Profit
aleksi
0
120
Песнь Хорьков и Гоферов
aleksi
0
360
Fuzzy generics
aleksi
0
150
On Ferrets and Gophers
aleksi
0
250
How to Go Wrong with Concurrency
aleksi
2
770
Adding context to existing code
aleksi
1
140
Зачем и как написать свой database/sql драйвер
aleksi
1
170
Cooking gRPC
aleksi
1
870
Profiling and Optimizing Go Programs
aleksi
1
1.8k
Other Decks in Programming
See All in Programming
CSC509 Lecture 05
javiergs
PRO
0
300
Leading Effective Engineering Teams in the AI Era
addyosmani
5
420
XP, Testing and ninja testing ZOZ5
m_seki
3
660
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
490
Writing Better Go: Lessons from 10 Code Reviews
konradreiche
0
1.2k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
370
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
230
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
250
株式会社 Sun terras カンパニーデック
sunterras
0
310
Advance Your Career with Open Source
ivargrimstad
0
540
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
230
dynamic!
moro
10
7.9k
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Producing Creativity
orderedlist
PRO
347
40k
Code Reviewing Like a Champion
maltzj
526
40k
The Straight Up "How To Draw Better" Workshop
denniskardys
238
140k
What's in a price? How to price your products and services
michaelherold
246
12k
Done Done
chrislema
185
16k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
61k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
189
55k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Docker and Python
trallard
46
3.6k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
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