SlideShare a Scribd company logo
1 of 42
Download to read offline
2016©MNU co. ltd.
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n
n
n
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
APPサーバ リソースサーバクライアント
リクエスト
リクエスト
レスポンス
レスポンス
ワーカーを占有
してしまう!
www.usa-mimi.jp
2016©MNU co. ltd.
n
APPサーバクライアント
リクエスト(アップロード)
レスポンス
アップロード完了まで
新規リクエスト受付不可!
www.usa-mimi.jp
2016©MNU co. ltd.
n
APPサーバクライアント
リクエスト
通知イベント
レスポンス
リクエスト受けられない
www.usa-mimi.jp
2016©MNU co. ltd.
n
APPサーバクライアント
リクエスト
レスポンス
リクエスト
レスポンス
リクエスト
レスポンス
APPサーバクライアント
リクエスト
レスポンス
リクエスト
レスポンス
リクエスト
レスポンス
これができない
1セット
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
var x int
var x int = 10
var x = 10 // 型を省略できる
x := 10 // := で varを省略できる
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
var arr [10] int
a := [3]int{1, 2, 3}
b := [10]int{1, 2, 3}
c := [...]int{4, 5, 6}
var fslice []int
slice := []byte {'a', 'b', 'c', 'd'}
slice = arr[1:3]
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n
sum := 0
for i := 0; i < 10; i++ {
sum += i
}
sum := 1
for sum < 1000 {
sum += sum
}
for {
// 無限ループ
}
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
if x > 10 {
fmt.Println("x is greater than 10")
} else {
fmt.Println("x is less than 10")
}
func add(x int, y int) int {
return x + y
}
www.usa-mimi.jp
2016©MNU co. ltd.
n
go f(x, y, z)
www.usa-mimi.jp
2016©MNU co. ltd.
package main
import (
"fmt"
"runtime"
)
func say(s string) {
for i := 0; i < 5; i++ {
runtime.Gosched()
fmt.Println(s)
}
}
func main() {
go say(“world”) //新しいGoroutinesを実行する。
say("hello") //現在のGoroutines実行
}
// 実行結果
// hello
// world
// hello
// world
// hello
// world
// hello
// world
// hello
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n
ch <- v // v をチャネル ch へ送信する
v := <-ch // ch から受信した変数を v へ割り当てる
ci := make(chan int)
cs := make(chan string)
cf := make(chan interface{})
www.usa-mimi.jp
2016©MNU co. ltd.
package main
import "fmt"
func sum(a []int, c chan int) {
total := 0
for _, v := range a {
total += v
}
c <- total // send total to c
}
func main() {
a := []int{7, 2, 8, -9, 4, 0}
c := make(chan int)
go sum(a[:len(a)/2], c)
go sum(a[len(a)/2:], c)
x, y := <-c, <-c // receive from c
fmt.Println(x, y, x + y)
}
// 実行結果
// -5 17 12
// または
// 17 -5 12
www.usa-mimi.jp
2016©MNU co. ltd.
package main
import (
"fmt"
"net/http"
"log"
)
func sayhelloName(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello!") //ここでwに入るものがクライアントに出力されます。
}
func main() {
http.HandleFunc("/", sayhelloName) //アクセスのルーティングを設定します。
err := http.ListenAndServe(":9090", nil) //監視するポートを設定します。
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
www.usa-mimi.jp
2016©MNU co. ltd.
n
func (srv *Server) Serve(l net.Listener) error {
defer l.Close()
if fn := testHookServerServe; fn != nil {
fn(srv, l)
}
var tempDelay time.Duration // how long to sleep on accept failure
if err := srv.setupHTTP2_Serve(); err != nil {
return err
}
baseCtx := context.Background()
ctx := context.WithValue(baseCtx, ServerContextKey, srv)
ctx = context.WithValue(ctx, LocalAddrContextKey, l.Addr())
for {
rw, e := l.Accept()
// ...
tempDelay = 0
c := srv.newConn(rw)
c.setState(c.rwc, StateNew) // before Serve can return
go c.serve(ctx)
}
}
www.usa-mimi.jp
2016©MNU co. ltd.
package main
import (
//…
"golang.org/x/net/websocket"
)
func Echo(ws *websocket.Conn) {
var err error
for {
var reply string
if err = websocket.Message.Receive(ws, &reply); err != nil {
break
}
fmt.Println("Received back from client: " + reply)
msg := "Received: " + reply
if err = websocket.Message.Send(ws, msg); err != nil {
break
}
}
}
func main() {
http.Handle("/", websocket.Handler(Echo))
if err := http.ListenAndServe(":1234", nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
}
www.usa-mimi.jp
2016©MNU co. ltd.
www.usa-mimi.jp
2016©MNU co. ltd.
www.usa-mimi.jp
2016©MNU co. ltd.
n
APPサーバ
Goサーバ
Nginx
リクエスト
リバース
プロキシ
サーバ
認証・ロケーション
www.usa-mimi.jp
2016©MNU co. ltd.
Goサーバ Appサーバクライアント
リクエスト
認証等
レスポンス
リソース取得
リソースサーバ
ノンブロック
www.usa-mimi.jp
2016©MNU co. ltd.
n
APPサーバ
Goサーバ
Object Storage
アップロード
必要があれば
リバースプロキシ
認証・メタデータの
DB書込等
アップロード
www.usa-mimi.jp
2016©MNU co. ltd.
n
Goサーバ Appサーバクライアント
アップロード
認証等
レスポンス
アップロード
ObjectStorage
メタデータの書込等
ノンブロック
www.usa-mimi.jp
2016©MNU co. ltd.
n
func UploadOS(user, key, authUrl, container, fileId, contentType string, body io.Reader) (string, error) {
storageUrl, storageToken, err := authenticate(user, key, authUrl)
if err != nil {
return "", err
}
req := goreq.Request{Uri: storageUrl + "/" + container + "/" + fileId, Method: "PUT", Body: body}
req.AddHeader("X-Auth-Token", storageToken)
req.AddHeader("Content-Type", contentType)
req.AddHeader("Transfer-Encoding", "chunked”)
res, err := req.Do()
if err != nil {
return "", err
}
if res.StatusCode != 201 {
log.Info(res.StatusCode)
return "", errors.New("upload failed")
}
return res.Header.Get("ETag"), nil
}
www.usa-mimi.jp
2016©MNU co. ltd.
n
APPサーバ
Goサーバ
監視
通知HTTP, pubsub等
通知
クライアント
www.usa-mimi.jp
2016©MNU co. ltd.
n
Goサーバクライアント
監視
通知
通知
APPサーバ
www.usa-mimi.jp
2016©MNU co. ltd.
n
www.usa-mimi.jp
2016©MNU co. ltd.
www.usa-mimi.jp
2016©MNU co. ltd.
n
n
n

More Related Content

Similar to Ocif2016_go_web_freamwork

Similar to Ocif2016_go_web_freamwork (10)

161027 net opscoding-junos-automation
161027 net opscoding-junos-automation161027 net opscoding-junos-automation
161027 net opscoding-junos-automation
 
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
 
いまどきのPHP開発現場 -2015年秋-
いまどきのPHP開発現場 -2015年秋-いまどきのPHP開発現場 -2015年秋-
いまどきのPHP開発現場 -2015年秋-
 
Web環境構築概論 2012/01/12
Web環境構築概論 2012/01/12Web環境構築概論 2012/01/12
Web環境構築概論 2012/01/12
 
Ansible2.0と実用例
Ansible2.0と実用例Ansible2.0と実用例
Ansible2.0と実用例
 
OpenWrtによるサイト間IPsec接続
OpenWrtによるサイト間IPsec接続OpenWrtによるサイト間IPsec接続
OpenWrtによるサイト間IPsec接続
 
10 分で書ける Cloud Foundry Route Service
10 分で書ける Cloud Foundry Route Service10 分で書ける Cloud Foundry Route Service
10 分で書ける Cloud Foundry Route Service
 
Laravelの認証について
Laravelの認証についてLaravelの認証について
Laravelの認証について
 
AzureでLaravel動かしてみた
AzureでLaravel動かしてみたAzureでLaravel動かしてみた
AzureでLaravel動かしてみた
 
Spring I/O 2016 報告 Test / Cloud / Other Popular Sessions
Spring I/O 2016 報告 Test / Cloud / Other Popular SessionsSpring I/O 2016 報告 Test / Cloud / Other Popular Sessions
Spring I/O 2016 報告 Test / Cloud / Other Popular Sessions
 

More from Shuichi Yukimoto (11)

Softlayer_bluemix-summit
Softlayer_bluemix-summitSoftlayer_bluemix-summit
Softlayer_bluemix-summit
 
SendGridを使ってみよう
SendGridを使ってみようSendGridを使ってみよう
SendGridを使ってみよう
 
Mnu_pbox
Mnu_pboxMnu_pbox
Mnu_pbox
 
Emacs softLayer
Emacs softLayerEmacs softLayer
Emacs softLayer
 
Soft layer APIの使い方と実装のポイント
Soft layer APIの使い方と実装のポイントSoft layer APIの使い方と実装のポイント
Soft layer APIの使い方と実装のポイント
 
SoftLayerオブジェクトストレージと連携サービスPBOXについて
SoftLayerオブジェクトストレージと連携サービスPBOXについてSoftLayerオブジェクトストレージと連携サービスPBOXについて
SoftLayerオブジェクトストレージと連携サービスPBOXについて
 
Pbox on softlayer
Pbox on softlayerPbox on softlayer
Pbox on softlayer
 
第2回名古屋SoftLayer勉強会 PBOX on SoftLayer
第2回名古屋SoftLayer勉強会 PBOX on SoftLayer第2回名古屋SoftLayer勉強会 PBOX on SoftLayer
第2回名古屋SoftLayer勉強会 PBOX on SoftLayer
 
Object storageを使ってみる
Object storageを使ってみるObject storageを使ってみる
Object storageを使ってみる
 
Mnu特許説明スライド
Mnu特許説明スライドMnu特許説明スライド
Mnu特許説明スライド
 
第2回ビジネスモバイル研究会
第2回ビジネスモバイル研究会第2回ビジネスモバイル研究会
第2回ビジネスモバイル研究会
 

Ocif2016_go_web_freamwork