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
The Go Playgoroundで 外部パッケージ使いたい
Search
Hazumi Ichijo
October 19, 2018
Programming
7k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The Go Playgoroundで 外部パッケージ使いたい
Go(Un)Conference(Goあんこ)LT大会 4kg
https://gounconference.connpass.com/event/99487/
の発表資料です。
Hazumi Ichijo
October 19, 2018
More Decks by Hazumi Ichijo
See All by Hazumi Ichijo
RailsとRidgepoleの マイグレを120倍早くする
hazumirr
0
410
CIを整備してメンテナンスを生成AIに任せる
hazumirr
0
1.5k
病院の情報フローを理解して、 予約〜会計の見え方が変わった話
hazumirr
1
1.9k
Rubyのコード削除したい時 僕がやること
hazumirr
0
280
テーブル駆動テストと状態
hazumirr
5
2.2k
オンラインテストしようと思った その日に開始できる環境を目指して
hazumirr
0
1.1k
推薦によるプロダクト改善とマイクロサービスが噛み合った話
hazumirr
2
4.8k
ChatGPTで僕が知っていることまとめ
hazumirr
3
3.1k
プロダクトチームとどう 協業し分析環境を改善するか
hazumirr
2
1.6k
Other Decks in Programming
See All in Programming
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
150
Oxcを導入して開発体験が向上した話
yug1224
4
320
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
270
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
200
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
140
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
550
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
710
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
150
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
550
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
140
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.5k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
Agile that works and the tools we love
rasmusluckow
331
21k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
200
The World Runs on Bad Software
bkeepers
PRO
72
12k
How to build a perfect <img>
jonoalderson
1
5.7k
A designer walks into a library…
pauljervisheath
211
24k
Optimising Largest Contentful Paint
csswizardry
37
3.7k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Transcript
©2018 Wantedly, Inc. The Go PlaygoroundͰ ֎෦ύοέʔδ͍͍ͨ Go(Un)Conference 4kg 19.Oct.2018
- Hazumi Ichijo
©2018 Wantedly, Inc. ࣗݾհ Ұᑍ!IB[VNJSS!SFSPTU 8FC"QQMJDBUJPO&OHJOFFS (P 3BJMT 3FBDUʜ ۴࿏ߴઐஜେֶ8BOUFEMZ
©2018 Wantedly, Inc. 1MBZHSPVOE JSC SBJMTDPOTPMF ࢼ͠ʹίʔυΛಈ͔͍ͨ͠ͱ͖
©2018 Wantedly, Inc. 1MBZHSPVOE JSC SBJMTDPOTPMF ࢼ͠ʹίʔυΛಈ͔͍ͨ͠ͱ͖
֎෦ύοέʔδ͑ͳ͍ɾɾɾ
©2018 Wantedly, Inc. package main import ( "fmt" "gopkg.in/guregu/null.v3" )
func main() { fmt.Println(null.StringFrom("PlayGround")) }
©2018 Wantedly, Inc. HPHFUΛ࣮ߦ͢Δ͚ͩͰ ύοέʔδͷґଘղܾͯ͘͠Εͨͣɾɾɾʁ
©2018 Wantedly, Inc. func compileAndRun(req *request) (*response, error) { //
TODO(andybons): Add semaphore to limit number of running programs at once. tmpDir, err := ioutil.TempDir("", "sandbox") if err != nil { return nil, fmt.Errorf("error creating temp directory: %v", err) } defer os.RemoveAll(tmpDir) src := []byte(req.Body) in := filepath.Join(tmpDir, "main.go") if err := ioutil.WriteFile(in, src, 0400); err != nil { return nil, fmt.Errorf("error creating temp file %q: %v", in, err) } https://github.com/golang/playground/blob/master/sandbox.go
©2018 Wantedly, Inc. func compileAndRun(req *request) (*response, error) { //
TODO(andybons): Add semaphore to limit number of running programs at once. tmpDir, err := ioutil.TempDir("", "sandbox") if err != nil { return nil, fmt.Errorf("error creating temp directory: %v", err) } defer os.RemoveAll(tmpDir) src := []byte(req.Body) in := filepath.Join(tmpDir, "main.go") if err := ioutil.WriteFile(in, src, 0400); err != nil { return nil, fmt.Errorf("error creating temp file %q: %v", in, err) } https://github.com/golang/playground/blob/master/sandbox.go
©2018 Wantedly, Inc. ݁ہϑΝΠϧʹॻ͖ग़ͯ͠Ϗϧυ͍ͯ͠Δ͚ͩͳͷͰ ॻ͖ग़͠ઌΛ(01"5)ҎԼʹ͢Δ HPHFUΛ࣮ߦ͢Δ ͜Ε͚ͩͰ͍͚Δʁʢ͍͚ΔΘ͚͕ͳͦ͞͏ʣ
©2018 Wantedly, Inc. https://github.com/rerost/playground/compare/e07747d8d2cee6639b14ba8021d453a6b8dd9edc...master
©2018 Wantedly, Inc.
©2018 Wantedly, Inc. ಈ͍ͯ͠·ͬͨɾɾɾ
©2018 Wantedly, Inc. https://play-dot-k8s-test-219404.appspot.com/ @hazumirr
©2018 Wantedly, Inc. ͳͥ͜ͷํ๏Ͱ্ख͍͔ͬͨ͘
©2018 Wantedly, Inc. ͳͥ͏·͘ߦͬͨͷ͔ 4BOECPY͕ίʔυͷ࣮ߦ࣌ͷΈ༗ޮʹͳ͍ͬͯͨ ػೳ͕γϯϓϧͩͬͨ
©2018 Wantedly, Inc. cmd.Env = []string{"GOOS=nacl", "GOARCH=amd64p32", "GOPATH=" + os.Getenv("GOPATH")}
if out, err := cmd.CombinedOutput(); err != nil { if _, ok := err.(*exec.ExitError); ok { // Return compile errors to the user. // Rewrite compiler errors to refer to progName // instead of '/tmp/sandbox1234/main.go'. errs := strings.Replace(string(out), in, progName, -1) // "go build", invoked with a file name, puts this odd // message before any compile errors; strip it. errs = strings.Replace(errs, "# command-line-arguments\n", "", 1) return &response{Errors: errs}, nil } return nil, fmt.Errorf("error building go source: %v", err) } ctx, cancel := context.WithTimeout(context.Background(), maxRunTime) defer cancel() cmd = exec.CommandContext(ctx, "sel_ldr_x86_64", "-l", "/dev/null", "-S", "-e", exe, testParam) https://github.com/golang/playground/blob/master/sandbox.go#L320-L339
©2018 Wantedly, Inc. cmd.Env = []string{"GOOS=nacl", "GOARCH=amd64p32", "GOPATH=" + os.Getenv("GOPATH")}
if out, err := cmd.CombinedOutput(); err != nil { if _, ok := err.(*exec.ExitError); ok { // Return compile errors to the user. // Rewrite compiler errors to refer to progName // instead of '/tmp/sandbox1234/main.go'. errs := strings.Replace(string(out), in, progName, -1) // "go build", invoked with a file name, puts this odd // message before any compile errors; strip it. errs = strings.Replace(errs, "# command-line-arguments\n", "", 1) return &response{Errors: errs}, nil } return nil, fmt.Errorf("error building go source: %v", err) } ctx, cancel := context.WithTimeout(context.Background(), maxRunTime) defer cancel() cmd = exec.CommandContext(ctx, "sel_ldr_x86_64", "-l", "/dev/null", "-S", "-e", exe, testParam) https://github.com/golang/playground/blob/master/sandbox.go#L320-L339
©2018 Wantedly, Inc. NaClͱ αϯυϘοΫεΛ࣮ݱ͢ΔͨΊͷͷɹ $ISPNFͷΣϒετΞͰ͞ΕΔ ΞϓϦέʔγϣϯΛ࣮ߦ͢ΔͷʹΘΕΔͷ
/B$M༻ʹϏϧυ͞ΕͨόΠφϦ͕ඞཁ<ཁग़య> https://ja.wikipedia.org/wiki/Google_Native_Client
©2018 Wantedly, Inc. ͳͥ͏·͍ͬͨ͘ͷ͔ /B$M ίʔυͷ࣮ߦͷࡍͷΈ༗ޮͩͬͨ /B$MͰ4BOECPY͕࣮ݱ͞Ε͍ͯͨ
(P͕/B$M༻ͷόΠφϦΛ࡞ΕΔʢ(004OBDMʣɹ
©2018 Wantedly, Inc. ͳͥ͏·͍ͬͨ͘ͷ͔
©2018 Wantedly, Inc. https://play-dot-k8s-test-219404.appspot.com/ ੬ऑੑෆ۩߹ͳͲΛݟ͚ͭͨΒڭ͍͑ͯͩ͘͞