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
Пакет embed: распаковка знаний - Илья Данилкин
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
GopherCon Russia
April 23, 2021
Programming
310
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Пакет embed: распаковка знаний - Илья Данилкин
GopherCon Russia
April 23, 2021
Transcript
28 slides
Илья Данилкин Senior Engineer / Scrum Master Москва — 2021
ПАКЕТ EMBED: РАСПАКОВКА ЗНАНИЙ
2 Илья Данилкин Senior Engineer / Scrum Master Пишу на
Go, начиная с версии 1.6. Работаю в Авито в юните Auto. Наша команда делает сервисы для профессиональных пользователей в категории Авто. ► Спикер GopherCon Russia 2018-2021 ► OpenGApps contributor nezorfla.me/golang-talks
AGENDA 3 ► Что такое “embedding”? ► Варианты решений для
Go ► Go 1.16 и “embed” ► Live demo ► Итоги
ЧТО ТАКОЕ EMBEDDING? ПАКЕТ EMBED: РАСПАКОВКА ЗНАНИЙ 4
EMBEDDING Встраивание файлов в исполняемый файл (обычно на этапе компиляции)
► Дистрибуция одним файлом ► Использование ресурсов напрямую (иконка приложения) ► HTTP-сервер: статика для сайта 5
► C / C++: xxd, ld, bin2cpp ► Rust: include_bytes,
rust-embed, etc. 6 USAGE $ cat test.txt some text for testing $ xxd /-include test.txt unsigned char test_txt[] = { 0x73, 0x6f, 0x6d, 0x65, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67 }; unsigned int test_txt_len = 21;
ВАРИАНТЫ РЕШЕНИЙ ДЛЯ GO ПАКЕТ EMBED: РАСПАКОВКА ЗНАНИЙ 7
► Кодогенерация (бинарник / go generate) ► Использование через Asset()
► Сжатие 8 GO-BINDATA //go:generate go-bindata -pkg $GOPACKAGE -o assets.go assets/ data, err /= Asset("assets/style/foo.css") if err /= nil { // Asset was not found. } // use asset data > go-bindata -o myfile.go data/ ☠ RIP [2011 - 2018]
АЛЬТЕРНАТИВЫ ► shurcooL/vfsgen ► rakyll/statik ► gobuffalo/packr ► GeertJohan/go.rice 9
КЛЮЧЕВЫЕ ФИЧИ 10 Ease of use 01.
КЛЮЧЕВЫЕ ФИЧИ 11 Ease of use 01. Архивация 02.
КЛЮЧЕВЫЕ ФИЧИ 12 Ease of use 01. Архивация 02. http.FileSystem
03.
КЛЮЧЕВЫЕ ФИЧИ 13 Easy to use 01. Архивация 02. http.FileSystem
03. Local FS 04.
СРАВНЕНИЕ 14 Library Easy to use Compression http.FileSystem Local FS
go-bindata YES YES NO* YES vfsgen YES YES+ YES YES packr YES YES YES YES statik YES YES YES NO embed YES NO YES NO
GO 1.16 И “EMBED” ПАКЕТ EMBED: РАСПАКОВКА ЗНАНИЙ 15
DRAFT Design: https://golang.org/s/draft-embe d-design ► By Russ Cox, Brad Fitzpatrick
► Reddit, video ► Прототип 16
PROPOSAL ► Новый пакет embed ► import _ "embed" ►
Упаковка: initEmbed() -> cmd/compile/internal/gc/e mbed.go GitHub 17
FILE 18 ► string, []byte ► //go:embed foo static/ abc/*
► Не забываем пустой импорт!
EMBED FS 19 ► embed.FS ► read-only ► Без *
учитывает файлы с . и _ Proposal для go:embed all
HTTP STATIC 20 ► http.FileSystem ► http/template ► Не путать
с text/tempalte!
COMMUNITY 21 ► embed-encrypt - AES-шифрование More coming soon? 😉
LIVE DEMO ПАКЕТ EMBED: РАСПАКОВКА ЗНАНИЙ 22
23 LIVE DEMO пакет embed: распаковка знаний
ИТОГИ ПАКЕТ EMBED: РАСПАКОВКА ЗНАНИЙ 24
ИТОГИ 25 Простое barebones - решение 01.
ИТОГИ 26 Простое barebones - решение 01. Альтернативы для большего
кол-ва фич 02.
ИТОГИ 27 Простое barebones - решение 01. Альтернативы для большего
кол-ва фич 02. Power of community! 03.
Москва — 2021 Илья Данилкин Senior Engineer / Scrum Master
avito-tech nezorflame nezorflame Draft & proposal Ссылки: Artwork: ashleymcnamara/gophers awesome-go: resource embedding pkg.go.dev/embed
More Decks by GopherCon Russia
See All by GopherCon Russia
Go Profiling from Bottom Up - Felix Geisendörfer
gopherconrussia
0
270
Learning Unsung Gotchas of Go - Rashmi Nagpal
gopherconrussia
1
310
Прозрачный gRPC-proxy один-ко-многим - Андрей Смирнов
gopherconrussia
0
200
Из Python в Go и обратно - Андрей Минкин
gopherconrussia
0
200
Оптимизация работы с PostgreSQL в Go: от 50 до 5000 RPS - Иван Осадчий
gopherconrussia
0
240
За пару мгновений до main() - Олег Ковалев
gopherconrussia
0
190
Тестирование в Go c Ginkgo и Gomega - Александр Егурнов
gopherconrussia
0
180
Building an Autoscaling HTTP Proxy for Kubernetes - Aaron Schlesinger
gopherconrussia
0
180
Designing Pluggable Idiomatic Go Applications – Mark Bates
gopherconrussia
0
95
Other Decks in Programming
See All in Programming
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.3k
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
220
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.9k
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
4
4k
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
200
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
Crash Auto Pipelines
veronikapj
1
410
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
250
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2.1k
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
11k
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
1
380
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
320
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.9k
The Curse of the Amulet
leimatthew05
4
17k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
69k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Utilizing Notion as your number one productivity tool
mfonobong
4
640
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
400
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Are puppies a ranking factor?
jonoalderson
2
4.2k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
380
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
480
Site-Speed That Sticks
csswizardry
13
1.6k