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
O’ReillyでGo言語入門
Search
nsym-m
February 20, 2022
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
O’ReillyでGo言語入門
O’Reillyの「Go言語によるWebアプリケーション開発」でGo言語の勉強をしたのでそれで学んだことをざっくり共有する資料です。
nsym-m
February 20, 2022
More Decks by nsym-m
See All by nsym-m
Flutter入門してみた
nsym
0
130
5分でTypeScript入門!〜既存JS環境に引導を渡そう〜
nsym
0
41
Other Decks in Programming
See All in Programming
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
180
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2k
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
360
Designing for humans not robots
tammielis
254
26k
Product Roadmaps are Hard
iamctodd
55
13k
Balancing Empowerment & Direction
lara
6
1.3k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
560
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Visualization
eitanlees
153
17k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Transcript
O’ReillyでGo言語入門
自己紹介 名前:にしやま 使用言語:PHP(Laravel, CakePHP) / JavaScript(Vue.js) / Swift / Go←new!
IT業界歴:2年半くらい 職業:受託開発、来月から事業会社 趣味:犬と猫とアニメ
今回の趣旨 O’Reillyの「Go言語によりWebアプリケーション開発」(*1)でGo言語入門中なので、 その過程で学んだことを共有する為の LTです。 その為、本の内容に沿って学んだことをざっくり解説していきます。 ※第一章「WebSocketを使ったチャットアプリケーション」の一部抜粋のみ ここに載ってるソースコードの内容は私の Github(*2)にあります。本家のソースコードも別 (*3)にあります。 *1
https://www.amazon.co.jp/dp/4873117526/ *2 https://github.com/nsym-m/go-programming-blueprints/tree/main/chat *3 https://github.com/oreilly-japan/go-programming-blueprints/tree/master/chapter1/chat
まず、Go言語とは • Googleの開発した言語 • 静的型付言語 • Webの世界だとフロントにJsonを返すWebAPIとしてよく使われる • 並行処理が得意らしい •
クラスはなくて代わりに構造体がある
動作環境 Windows 10 Pro 今回の内容であれば同じバージョンの Goが入っていれば MacでもLinuxでも大きくは変わらないと思います。 PS C:\go-programming-blueprints> go
version go version go1.17.7 windows/amd64
WebSocketを使ったチャット アプリケーション
要件 • シンプルなWebSocketによるリアルタイムチャットができる Webアプリ • チャットの内容はDBに保存しない • ユーザーの区別もしない • 「ユーザーがメッセージ送信→リアルタイムで自他ユーザーの画面にメッセージが表
示される」だけの機能
疑問1:WebSocketとは? • HTTPをラップしたプロトコルの1つ • HTTPで双方向通信を実現する為の仕組み • HTTPではクライアントサイド→サーバーサイドの方向でしか通信を発火できない ◦ サーバーサイドから任意のタイミングで通信を行うことができない •
双方向からリアルタイムに通信を行うことができるようにする • チャットでよく使われるイメージ ◦ 例:ユーザーAがグループチャットに送信 →WebSocketのサーバー→全グループメンバーにリ アルタイムでメッセージが表示される • 詳しく知りたい方は”websocket とは”とかで検索してみてください
main.go 何をしている? • Webサーバーの準備/起動 ◦ テンプレートファイルの呼び出 し ◦ ルーティングの定義 ◦
指定ポートでのWebサーバー の起動 • チャットのリクエスト処理をバックグラウ ンドで走らせる ◦ “go”を手前につけることで並列処 理を走らせることができる
room.go(1) 何をしている? • roomに必要なモデルの定義 • main.goのr.run()の定義 ◦ 参加、退室、メッセージ送信それぞ れのイベントの際に実行する内容を 定義している
room.go(2) 何をしている? • WebSocketのサーバーの定義 ◦ main.goのServeHTTPを上書き している • チャットルームの生成準備
client.go 何をしている? • clientに必要なモデルの 定義 • ユーザーごとにメッセージ の書き込みと読み込みの 処理を定義
実行! ブラウザでhttp://localhost:8888を開く PS C:\go-programming-blueprints\chat> go run . -addr=":8888" 2022/02/20 15:13:24
Webサーバーを起動します。ポート : :8888
確認!(1) ↓
確認!(2) ↓(送信したメッセージがリアルタイムで複数のタブに反映されている)
おしまい ご清聴ありがとうございました!