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
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
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
1
270
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
120
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
140
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
7.1k
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
310
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
280
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
220
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
140
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
120
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4.9k
No More NoSuchMethodError
exoego
1
120
続・コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions-again
handlename
0
150
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Tell your own story through comics
letsgokoyo
1
1.1k
How to Talk to Developers About Accessibility
jct
2
600
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
430
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
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