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
Try Web Assembly for Go!! ~ gopherdojo#3 LT ~
Search
Go Takagi
September 18, 2018
Technology
2.4k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Try Web Assembly for Go!! ~ gopherdojo#3 LT ~
https://mercari.connpass.com/event/101178/
Go Takagi
September 18, 2018
More Decks by Go Takagi
See All by Go Takagi
日経電子版のStoreKit2フルリニューアル
shimastripe
4
1.5k
アプリ内課金と自社の認証認可基盤を連携する複雑な課金ネットワークを構築する
shimastripe
5
4.6k
日経iOSプロジェクトのマルチモジュール戦略
shimastripe
45
2.1k
UIKit ベースの Custom UIContentConfiguration API を 用いた複雑なカスタムセルの作り方
shimastripe
14
4k
リーダーアプリに外部課金リンクを設置する
shimastripe
2
2k
Effective PencilKit / 新聞スクラップ体験の実現
shimastripe
4
3.9k
SPM Build tools を用いて SwiftGen を導入する上での罠とTips / SPM-SwiftGen-Plugin
shimastripe
6
3.4k
Background Notificationで新聞紙面の大きい画像の自動ダウンロードを実現する
shimastripe
12
5.6k
Otemachi.swift#04 今から始めるCodable移行
shimastripe
1
1.2k
Other Decks in Technology
See All in Technology
Why is RC4 still being used?
tamaiyutaro
0
280
AWS Summit Japan 2026の振り返りと2027へ向けて / AWS Summit Japan 2026 Recap and Prospects for 2027
kaminashi
1
180
知見・人・API・DB・予算 ─ ナイナイ尽くしだった人事データ整備 with dbt、5年間の学び
ken6377
1
140
ご挨拶「10周年を迎える共創ラボのこれまでとこれから」
iotcomjpadmin
0
180
認証認可だけじゃない! ID管理の構成要素と ライフサイクルを意識しよう
ritou
1
450
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.3k
AIに「使われる」時代のSaaS戦略 〜既存WebAPIのMCPサーバー化における開発ノウハウ〜
ekispert_api
0
270
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
140
BPaaSで進むAIオペレーションの現在地 AI実装が効く領域とスケーラビリティの選定と実装
kentarofujii
0
250
cccccc
moznion
0
1.6k
水を運ぶ人としてのリーダーシップ
izumii19
4
1.2k
勉強会企画をアプリで構造化してみた 〜そこで見えた、AIとの付き合い方〜 / I've structured a study group plan using an app.
pauli
0
290
Featured
See All Featured
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
340
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
For a Future-Friendly Web
brad_frost
183
10k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
170
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
240
The Curse of the Amulet
leimatthew05
2
13k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Discover your Explorer Soul
emna__ayadi
2
1.2k
We Have a Design System, Now What?
morganepeng
55
8.2k
Transcript
ϑϩϯτΤϯυͰ Go͍ͨ͠!! Goಓ #3 LTେձ Go Takagi @shimastripe
✦ ໊લ • ߴ ߽ ✦ େֶ • ౦ژۀେֶ M2
✴ ϦόʔεΤϯδχΞϦϯάϓϩάϥϜཧղʹؔ͢ΔݚڀγςϚε ✦ ීஈ • iOS / ϑϩϯτΤϯυपΓ͕جຊ͖Ͱ͢ ✦ SNS • GitHub : @shimastripe • Twitter : @shimastriper • Blog : https://shimastripe.goat.me • KyashID: root ࣗݾհ
Goಓɺ໘ന͔ͬͨ!! ͔ͤͬͩ͘͠࠷৽ͷGoࣄ ৮ͬͯΈ͍ͨ
WebAssembly Go 1.11 adds an experimental port to WebAssembly.
✦ ϑϩϯτ(ϒϥβ)Ͱಈ͘όΠφϦ • ϝΠϯjsͰਏ͔ͬͨύϑΥʔϚϯεΛͳΜͱ͔͢Δ • αΠζখ͍͞ɺಡΈࠐΈվળ ✦ ଟ࠼ͳݴޠ͔ΒੜͰ͖Δ • C/C++/Rust/Go/etc.
✴ WebΛλʔήοτʹίϯύΠϧ͢ΔΠϝʔδ ✴ ࠓ·ͰJavaScriptʹม͢ΔࢼΈ͕ଟ ✤ Scala.jsͱ͔GopherJSͱ͔ Web Assembly
✦ ͋͘·ͰϝΠϯܭࢉߴԽ (ܭࢉ + file size) • ήʔϜͱ͔WebGL ͕͠Β͘ओ ✦
DOMૢ࡞Ͱ͖ͳ͍ (ࠓͷॴ?) • GoͰWebAssembly͔ΒJSͷؔΛίʔϧ (import "syscall/js") • DOM, EventListenerΛҰԠर͑Δ ✦ طଘͷϥΠϒϥϦͱͷ݉Ͷ߹͍ • JSϑϨʔϜϫʔΫ͕ੵΈ্͛ͨࢿ࢈؆୯ʹख์ͤͳ͍ ✦ όΠτίʔυ • ؆қಡԽʹͳΔ͔!! ۜͷؙ͔? (JSΛશͯஔ͖͑Δ???)
✦ Document • Β͍͠doc·ͩͳ͍ • https://github.com/golang/go/wiki/WebAssembly • αϯϓϧίʔυ͕͞ΕͯΔ ✦ ͱΓ͋͑ͣ
$ curl -sO https://raw.githubusercontent.com/golang/go/ master/misc/wasm/wasm_exec.html $ curl -sO https://raw.githubusercontent.com/golang/go/ master/misc/wasm/wasm_exec.js ```main.go func main() { fmt.Println(“Hello WASM!!”) } ```
Hello WASM !! $ GOOS=js GOARCH=wasm go build -o test.wasm
main.go $ open wasm_exec.html Goͷඪ४ग़ྗ͕console.log͞ΕΔ
✦ JS→Gomain͔͠·ͩݺͳ͍? • wasm_exec.js ্Ͱrun(main)͔͠ఆٛ͞Ε͍ͯͳ͍ ✴ JSଆͷ͔͠Εͳ͍ ✦ JS→GoଆʹͤΔ? •
jsͷGo InstanceͷargvʹΛೖΕΔ ✴ os.Args() ͔Βर͑Δ ✴ ڥม͍͚Δ ✦ Go→JSʹͤΔ? • os.Stdoutʹग़ͨ͠Βconsole.log͞ΕΔ͜ͱ͔͠ݟͨΒͳ͍… • Go͔ΒJSΛcallͯ͠eventListenerʹؔΛηοτͰ͖Δ Experimental: ͨͿΜ࠷ॳʹͿͪ͋ͨΔ(ͬͨ)͜ͱ
✦ wasm_exec.js Λ֦ு • console.log ͍ͯͨ͠ՕॴΛDOMʹॻ͖ࠐ·ͤΔ ✦ Goଆ (shimabot.NotifyTrainInformation()) •
ࣗͷChatBotͷ౦ٸઢӡߦεΫϦϓτΛbuild ✴ ఆظతʹݟʹߦͬͯిं͕ࢭ·ͬͯͳ͍͔֬ೝ • JSଆͷnotify()ؔʹొ͢Δ ͏গ͠… writeSync(fd, buf) { outputBuf += decoder.decode(buf); const nl = outputBuf.lastIndexOf("\n"); if (nl != -1) { const elm = document.querySelector("#wrapper"); let div = document.createElement('div'); div.textContent = outputBuf.substr(0, nl); elm.appendChild(div); }
✦ ࣮ߦͰ͖ͨ!! • CORS֎͞ͳ͍ͱ ͍͚ͳ͔ͬͨ • ґଘϥΠϒϥϦͰ Ϗϧυࣦഊ͕݁ߏ͋Γ… ✦ ͬͯΈͯ
• APIϦΫΤετ͘Β͍ͳΒׂͱ ͦͷ··ಈ͔ͤΔ • JSଆ͔ΒGoͷؔΛࢦఆͯ͠ ݺΔΑ͏ʹͳΕศར ϒϥβ্ͰࣗલGoίʔυͷ࣮ߦ
✦ Web Assembly • ϋΠύϑΥʔϚϯε͕ٻΊΒΕΔΑ͏ʹͳͬͨ WebΛࢧ͑ΔͨΊͷόΠφϦΛ༻͍ͨߴԽ ✦ Go Web Assembly
• ·ͩࢼݧ of ࢼݧஈ֊ɻ • GoଆͷؔΛׂͱ؆୯ʹϒϥβͰ࣮ߦͰ͖ͨ • CLIͰ࡞͖ͬͯͨػೳΛ্ख͘׆༻Ͱ͖ͨΓ͠ͳ͍͔? ·ͱΊ ͜Ε͔ΒͷAPI࣍ୈ͚ͩͲɺ͍ΖΜͳ͍ํͰ͖ͦ͏!!
✦ Wiki • https://github.com/golang/go/wiki/WebAssembly ✦ Tutorial • https://www.youtube.com/watch?v=4kBvvk2Bzis • https://www.youtube.com/watch?v=iTrx0BbUXI4
✦ Blog • https://blog.gopheracademy.com/advent-2017/go-wasm/ • https://www.kabuku.co.jp/developers/go-to-webassembly • http://iqeiq.hatenablog.com/entry/2017/12/02/033238 • https://yhara.jp/2017/12/01/webassembly ࢀߟࢿྉ (Ҿ༻)