Download free for 30 days
Sign in
Upload
Language (EN)
Support
Business
Mobile
Social Media
Marketing
Technology
Art & Photos
Career
Design
Education
Presentations & Public Speaking
Government & Nonprofit
Healthcare
Internet
Law
Leadership & Management
Automotive
Engineering
Software
Recruiting & HR
Retail
Sales
Services
Science
Small Business & Entrepreneurship
Food
Environment
Economy & Finance
Data & Analytics
Investor Relations
Sports
Spiritual
News & Politics
Travel
Self Improvement
Real Estate
Entertainment & Humor
Health & Medicine
Devices & Hardware
Lifestyle
Change Language
Language
English
Español
Português
Français
Deutsche
Cancel
Save
EN
Uploaded by
Masahiro Wakame
PDF, PPTX
4,549 views
GoCon2016 spring 自作Webフレームワーク uconを作った話
GoCon2016 spring 自作Webフレームワーク uconを作った話 http://gocon.connpass.com/event/27521/
Technology
◦
Read more
4
Save
Share
Embed
Embed presentation
Download
Download as PDF, PPTX
1
/ 67
2
/ 67
3
/ 67
4
/ 67
5
/ 67
6
/ 67
7
/ 67
8
/ 67
9
/ 67
10
/ 67
11
/ 67
12
/ 67
13
/ 67
14
/ 67
15
/ 67
16
/ 67
17
/ 67
18
/ 67
19
/ 67
20
/ 67
21
/ 67
22
/ 67
23
/ 67
24
/ 67
25
/ 67
26
/ 67
27
/ 67
28
/ 67
29
/ 67
30
/ 67
31
/ 67
32
/ 67
33
/ 67
34
/ 67
35
/ 67
36
/ 67
37
/ 67
38
/ 67
39
/ 67
40
/ 67
41
/ 67
42
/ 67
43
/ 67
44
/ 67
45
/ 67
46
/ 67
47
/ 67
48
/ 67
49
/ 67
50
/ 67
51
/ 67
52
/ 67
53
/ 67
54
/ 67
55
/ 67
56
/ 67
57
/ 67
58
/ 67
59
/ 67
60
/ 67
61
/ 67
62
/ 67
63
/ 67
64
/ 67
65
/ 67
66
/ 67
67
/ 67
More Related Content
PDF
速くなければスマフォじゃない - インターンバージョン-
by
Kazunari Hara
PDF
BACKBONE.JSにJasmineでテストコード書いてみた (LT資料)
by
Toshio Ehara
ODP
20090704rubyist九州
by
koki_h
PPT
Lightweight Language Tiger 2010
by
biscuitjam
PDF
Go言語で作る webアプリ@gocon 2013 spring
by
Takuya Ueda
PDF
Goのパッケージ構成で 試行錯誤してみた話 ~ Gocon 2015 Summer
by
Hirokazu Fukami
PDF
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
by
Masahiro Wakame
PDF
【とらラボLT】go言語でのweb apiの作り方3選
by
虎の穴 開発室
速くなければスマフォじゃない - インターンバージョン-
by
Kazunari Hara
BACKBONE.JSにJasmineでテストコード書いてみた (LT資料)
by
Toshio Ehara
20090704rubyist九州
by
koki_h
Lightweight Language Tiger 2010
by
biscuitjam
Go言語で作る webアプリ@gocon 2013 spring
by
Takuya Ueda
Goのパッケージ構成で 試行錯誤してみた話 ~ Gocon 2015 Summer
by
Hirokazu Fukami
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
by
Masahiro Wakame
【とらラボLT】go言語でのweb apiの作り方3選
by
虎の穴 開発室
Similar to GoCon2016 spring 自作Webフレームワーク uconを作った話
PDF
Dist 29 gcp_serverless_web_app_development
by
Shotaro Suzuki
PDF
Hypermedia: The Missing Element to Building Adaptable Web APIs in Rails (増補日本語版)
by
Toru Kawamura
PDF
ヒカルのGo 資料 Webアプリケーションの作り方
by
Yosuke Furukawa
PDF
全部入り!WGPで高速JavaScript+HML5体験
by
AdvancedTechNight
PPTX
Gunosy Go lang study #6 net http url
by
Innami Satoshi
PDF
Go言語入門者が Webアプリケーション を作ってみた話 #devfest #gdgkyoto
by
Shoot Morii
PDF
SmartPhone development guide with CoffeeScript + Node + HTML5 Technology, for...
by
Naoya Ito
PDF
50分で掴み取る ASP.NET Web API パターン&テクニック
by
miso- soup3
PDF
ネットワークAPI のあれこれ (ENOG37)
by
Kentaro Ebisawa
PPTX
EchoyaGinhanazeSu_inoka.pptx
by
keink
PDF
appengine ja night #24 Google Cloud Endpoints and BigQuery
by
Ryo Yamasaki
PDF
Goji とレイヤ化アーキテクチャ
by
Shiroyagi Corporation
PDF
デバイス WebAPI設計の進め方
by
Device WebAPI Consortium
PDF
20200708サーバーレスでのAPI管理の考え方
by
Amazon Web Services Japan
PDF
20130315 abc firefox_os
by
Tomoaki Konno
PDF
Go と Couchbase で microservices を作るには?
by
Yusuke Komatsu
PDF
Tottoruby 20110903
by
Takashi SAKAGUCHI
PDF
AWS SDK for Go in #jawsmeguro
by
VOYAGE GROUP
PDF
AWS SDK for Go in #jawsmeguro
by
Kenta Suzuki
PDF
実装(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第32回】
by
Tomoharu ASAMI
Dist 29 gcp_serverless_web_app_development
by
Shotaro Suzuki
Hypermedia: The Missing Element to Building Adaptable Web APIs in Rails (増補日本語版)
by
Toru Kawamura
ヒカルのGo 資料 Webアプリケーションの作り方
by
Yosuke Furukawa
全部入り!WGPで高速JavaScript+HML5体験
by
AdvancedTechNight
Gunosy Go lang study #6 net http url
by
Innami Satoshi
Go言語入門者が Webアプリケーション を作ってみた話 #devfest #gdgkyoto
by
Shoot Morii
SmartPhone development guide with CoffeeScript + Node + HTML5 Technology, for...
by
Naoya Ito
50分で掴み取る ASP.NET Web API パターン&テクニック
by
miso- soup3
ネットワークAPI のあれこれ (ENOG37)
by
Kentaro Ebisawa
EchoyaGinhanazeSu_inoka.pptx
by
keink
appengine ja night #24 Google Cloud Endpoints and BigQuery
by
Ryo Yamasaki
Goji とレイヤ化アーキテクチャ
by
Shiroyagi Corporation
デバイス WebAPI設計の進め方
by
Device WebAPI Consortium
20200708サーバーレスでのAPI管理の考え方
by
Amazon Web Services Japan
20130315 abc firefox_os
by
Tomoaki Konno
Go と Couchbase で microservices を作るには?
by
Yusuke Komatsu
Tottoruby 20110903
by
Takashi SAKAGUCHI
AWS SDK for Go in #jawsmeguro
by
VOYAGE GROUP
AWS SDK for Go in #jawsmeguro
by
Kenta Suzuki
実装(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第32回】
by
Tomoharu ASAMI
More from Masahiro Wakame
PDF
ng-japan 2015 TypeScript+AngularJS 1.3
by
Masahiro Wakame
PDF
TypeScriptは明日から使うべき
by
Masahiro Wakame
PDF
TypeScript 型定義ファイルのある開発 TypeScript勉強会 VSハッカソン倶楽部
by
Masahiro Wakame
PDF
Google Glass XE17版
by
Masahiro Wakame
PDF
Google Glassでできること XE12版 最新開発情報 Mirror API & GDK
by
Masahiro Wakame
PDF
コンパイラ指向ReVIEW
by
Masahiro Wakame
PDF
20ヶ月を取り戻す Dart flight school
by
Masahiro Wakame
PDF
TypeScript 独習会
by
Masahiro Wakame
PDF
Google Glassでできること XE11版 最新開発情報 Mirror API & GDK
by
Masahiro Wakame
PDF
CEATEC Glassware(Google Glassアプリ)開発の指南と開発事例
by
Masahiro Wakame
PDF
ReVIEW & CI - ChefでCI環境構築
by
Masahiro Wakame
PDF
Firefox OS勉強会 2nd TypeScript+AngularJS
by
Masahiro Wakame
PDF
AngularJS+TypeScript - AngularJS 1周年記念勉強会
by
Masahiro Wakame
PDF
Buildinsider OFFLINE TypeScriptの基礎から実践・利用事例まで
by
Masahiro Wakame
PDF
俺とお前とGoogleware
by
Masahiro Wakame
PDF
Datastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作った
by
Masahiro Wakame
PDF
TypeScript 勉強会
by
Masahiro Wakame
PDF
TypeScript Hands-on
by
Masahiro Wakame
PDF
わかめモナ化LT
by
Masahiro Wakame
PDF
NFC app launcher
by
Masahiro Wakame
ng-japan 2015 TypeScript+AngularJS 1.3
by
Masahiro Wakame
TypeScriptは明日から使うべき
by
Masahiro Wakame
TypeScript 型定義ファイルのある開発 TypeScript勉強会 VSハッカソン倶楽部
by
Masahiro Wakame
Google Glass XE17版
by
Masahiro Wakame
Google Glassでできること XE12版 最新開発情報 Mirror API & GDK
by
Masahiro Wakame
コンパイラ指向ReVIEW
by
Masahiro Wakame
20ヶ月を取り戻す Dart flight school
by
Masahiro Wakame
TypeScript 独習会
by
Masahiro Wakame
Google Glassでできること XE11版 最新開発情報 Mirror API & GDK
by
Masahiro Wakame
CEATEC Glassware(Google Glassアプリ)開発の指南と開発事例
by
Masahiro Wakame
ReVIEW & CI - ChefでCI環境構築
by
Masahiro Wakame
Firefox OS勉強会 2nd TypeScript+AngularJS
by
Masahiro Wakame
AngularJS+TypeScript - AngularJS 1周年記念勉強会
by
Masahiro Wakame
Buildinsider OFFLINE TypeScriptの基礎から実践・利用事例まで
by
Masahiro Wakame
俺とお前とGoogleware
by
Masahiro Wakame
Datastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作った
by
Masahiro Wakame
TypeScript 勉強会
by
Masahiro Wakame
TypeScript Hands-on
by
Masahiro Wakame
わかめモナ化LT
by
Masahiro Wakame
NFC app launcher
by
Masahiro Wakame
GoCon2016 spring 自作Webフレームワーク uconを作った話
1.
自作Webフレームワーク uconを作った話 わかめ まさひろ
2.
わかめ まさひろ @vvakame TypeScript Masahiro
Wakame DefinitelyTyped appengine/go photo from golang.org/doc/gopher/
3.
GoogleAppEngine/Go 神 いわゆる GOD
4.
諸君、私はappengine/goが好きだ • 2008年4月 始まる •
サーバレスアーキテクチャ • 2011年5月 Go対応始まる • 2015年7月 Go, GAになる • 2016年4月 Go 1.6対応 1.9.35→❌ 1.9.36を使おう!
5.
Eric Schmidt said. https://www.youtube.com/watch?v=HgWHeT_OwHc&t=1461 GCP
Next 2016 Day 1 Keynote
6.
GAE用ライブラリ作ってます • testerator github.com/favclip/testrator •
UnitTest高速化 • qbg github.com/favclip/qbg • Datastore用TypeSafeクエリビルダ • smg github.com/favclip/smg • Search API用TypeSafeラッパ productionで利用中!
7.
GoCon 2015 Summer •
appengine専用じゃないけど • jwg github.com/favclip/jwg • genbase github.com/favclip/genbase • GoCon 2015で話をしました! • SlideShare goo.gl/45lZDK
8.
gb • gb • getgb.io/ •
gb keeps the peace of our project🌹 • gb gae • github.com/PalmStoneGames/gb-gae
9.
Google API Discovery
Service 誰か知ってる?
10.
APIs Explorer is
神 https://developers.google.com/apis-explorer/
11.
APIs Explorer • 誰でも簡単に使える •
実際のAPIが叩かれる • 結果を共有しやすい • コードからUIが生成されている
12.
Cloud Endpoints • appengine専用の仕組み •
cloud.google.com/endpoints/ • 自前APIでAPIs Explorer使える • APIの構造がわかる! • 実例がわかる!(DevTool) • UIを省く極道管理画面も!
13.
周辺ツールも充実 • クライアントライブラリの自動生成 • golangだとこの辺全部そう •
github.com/google/google-api-go- client • TypeScript用型定義の生成 • www.npmjs.com/package/gapidts
14.
but…
15.
Googleの闇の領域 ユーザ GAE闇 path mapping request
format Version切替後reqをなかった事に custom domain不可
16.
go-endpoints • CloudEndpoints用framework • github.com/GoogleCloudPlatform/ go-endpoints •
Service & Method の組み合わせで定義 • w http.ResponseWriterが取れない • CloudEndpoints的には不要なので…
17.
評価 • 細かい事を気にしなければかなり良い • カスタムドメイン不可がやはり辛い •
デバッグ不可能な闇の領域が辛い • ちょいちょいそこが不安定な気が… • 拡張性が低い • 横断的な処理を入れにくい…
18.
僕達が必要なもの
19.
Alt Cloud Endpoints •
APIs Explorer的なものが欲しい! • サバクラの意思疎通が楽 • デバッグが楽 • コード→仕様が良い • 仕様→コード は努力が必要(努力やだ • クライアントコードの生成 • 変わったら壊れてほしい
20.
代替ツールの検討
21.
各ツールの評価 • RAML • API
Blueprint (apiary.io • JSON Schema v4 • Swagger • gRPC
22.
✨swagger✨ • Swaggerが一番良さそう! • 個人の見解です •
Open API Initiative発足 • Swagger仕様をbaseに • 長いものには巻かれたい • Qiitaに少し書きました goo.gl/BLS3uH
23.
既存GoなSwagger実装の話 最初からswagger対応 の物を選ぶと楽そう
24.
既存Go実装の比較 • go-swagger • goswagger.io/ •
type safeじゃない • yvasiyarov/swagger • github.com/yvasiyarov/swagger • comment baseでつらい • type safeじゃない
25.
既存Go実装の比較 • go-restful • github.com/emicklei/go-restful/ •
type safeじゃない • goa • goa.design/ • type safeじゃない • DSLがヤバイ
26.
既存Go実装の比較 • grpc-gateway • github.com/gengo/grpc-gateway •
gRPCのJSONなreverse proxy • いつのまにかswagger対応してた • appengineだと❌
27.
既存Webフレームワーク
28.
重要なポイント • net/httpに近いほうがわかりやすい • あまりに独自っぽいのはちょっと… •
go-endpointsからの移行 • しばらくCloudEndpointsと両立したい • コード上の互換性があると嬉しい… • swagger-uiが使える
29.
既存フレームワーク調べた • なるべくnet/httpに近い • revel→❌ •
なるべくCloudEndpointsのまま • net/http→❌ • goji→❌ • Swagger対応! • martini→❌
30.
結論 •自分でつくろう 趣味に走ったわけではないです
31.
自分で作る話
32.
前提 • appengine縛りにはしない • とはいえappengineで使えないと困る •
net/httpに近いAPI • 柔軟性 • go-endpointsとの互換性 • swaggerはopt-in やっていく
33.
ucon https://github.com/favclip/ucon
34.
名付け親 某a2cさん martiniとか ginとかに 対抗して
35.
名付け親 某a2cさん uconと 名付けよう! In japan, ucon
(= turmeric) is to be effective in hangover.
36.
決めた後 某a2cさん 💩 ←ゆるさない!!
37.
仕様紹介
38.
まずgo-endpoints s := &fooService{} api,
err := endpoints.RegisterService(s, "foo", "v1", "Foo API", true) if err != nil { panic(err.Error()) } info := api.MethodByName("Get").Info() info.HTTPMethod, info.Path, info.Desc = “GET", "/foo/{id}", “Fooを1件取得する" … type IntIDRequest struct { ID int64 `json:"id,string"` } func (s *fooService) Get(r *http.Request, req *IntIDRequest) (*FooJSON, error) { … }
39.
まずgo-endpoints s := &fooService{} api,
err := endpoints.RegisterService(s, "foo", "v1", "Foo API", true) if err != nil { panic(err.Error()) } info := api.MethodByName("Get").Info() info.HTTPMethod, info.Path, info.Desc = “GET", "/foo/{id}", “Fooを1件取得する" … type IntIDRequest struct { ID int64 `json:"id,string"` } func (s *fooService) Get(r *http.Request, req *IntIDRequest) (*FooJSON, error) { … } Handler Response Setup
40.
まずgo-endpoints s := &fooService{} api,
err := endpoints.RegisterService(s, "foo", "v1", "Foo API", true) if err != nil { panic(err.Error()) } info := api.MethodByName("Get").Info() info.HTTPMethod, info.Path, info.Desc = “GET", "/foo/{id}", “Fooを1件取得する" … type IntIDRequest struct { ID int64 `json:"id,string"` } func (s *fooService) Get(r *http.Request, req *IntIDRequest) (*FooJSON, error) { … } Request Response 闇の領域でもろもろ変換されてる
41.
ucon Features • net/http
との類似性 • Routing • Method, Path Matching • Middleware • Bubble • Dependency Injection • Plugin
42.
API likes net/http ucon.HandleFunc("GET",
"/", func(w http.ResponseWriter, r *http.Request) {})
43.
API likes net/http ucon.HandleFunc("GET",
"/", func(w http.ResponseWriter, r *http.Request) {})
44.
Routing ucon.HandleFunc(“*", “/“, … ucon.HandleFunc(“OPTIONS",
“/“, … ucon.HandleFunc(“GET", “/“, … ucon.HandleFunc(“POST", “/“, … ucon.HandleFunc(“GET", “/api/user“, … ucon.HandleFunc(“GET", “/api/user/me“, … ucon.HandleFunc(“GET", “/api/user/{id}“, …
45.
Routing rule • METHODが一致する •
* 指定も可 厳密一致優先 • Request Pathが一致する • 複数候補ある場合より長い節一致 • Request GET /api/user/123 • 🌟 GET /api/user/{id} • ❌ GET /api/user • 先登録優先
46.
Middleware • 1 request毎の処理に介入 •
JavaでいうServletFilter • ASP.NET MVCでいうFilter • Logging, DI, CORS用Header, error→JSON変換 etc, etc…
47.
Middleware Middleware Middleware Middleware Handler ServeHTTP DI Cache-Control Cookie appengine.Context etc, etc… CORS
Header Path, Query, Body → JSON *http.Request http.ResponseWriter
48.
Middleware type MiddlewareFunc func(b
*Bubble) error type Bubble struct { R *http.Request W http.ResponseWriter Context context.Context RequestHandler interface{} ArgumentTypes []reflect.Type Arguments []reflect.Value Returns []reflect.Value } func (b *Bubble) Next() error { … } func (b *Bubble) do() error { hv := reflect.ValueOf(b.handler()) … b.Returns = hv.Call(b.Arguments) return nil } var httpReqType = reflect.TypeOf((*http.Request)( var httpRespType = reflect.TypeOf((*http.Response func HTTPRWDI() MiddlewareFunc { return func(b *Bubble) error { for idx, argT := range b.ArgumentTypes { if argT == httpReqType { b.Arguments[idx] = reflect.ValueOf(b.R) continue } if argT == httpRespType { b.Arguments[idx] = reflect.ValueOf(b.W) continue } } return b.Next() } }
49.
built-in middleware • HTTPRWDI •
*http.Request, http.ResponseWriterのDI • NetContextDI • net/contextのContextをDI
50.
built-in middleware • RequestObjectMapper •
path parameter, query paramter, post bodyをObjectに変換しDI • ResponseMapper • HandlerがreturnしたObjectやerrorを JSONに変換
51.
Plugin • プロセス起動時1回だけ動作 • 全Handlerの走査 •
Handler→Plugin間の値の伝達機構 • swaggerはplugin • 全Handlerの情報から処理 • swagger.json出力用Handlerの追加
52.
Plugin type pluginContainer struct
{ base interface{} } type HandlersScannerPlugin interface { HandlersScannerProcess(m *ServeMux, rds []*RouteDefinition) error } type RouteDefinition struct { Method string PathTemplate *PathTemplate HandlerContainer HandlerContainer } func (m *ServeMux) Prepare() { for _, plugin := range m.plugins { used := false if sc := plugin.HandlersScanner(); sc != nil { err := sc.HandlersScannerProcess(m, m.router.handlers) if err != nil { panic(err) } used = true } if !used { panic(fmt.Sprintf("unused plugin: %#v", plugin)) } } }
53.
Plugin type pluginContainer struct
{ base interface{} } type HandlersScannerPlugin interface { HandlersScannerProcess(m *ServeMux, rds []*RouteDefinition) error } type RouteDefinition struct { Method string PathTemplate *PathTemplate HandlerContainer HandlerContainer } func (m *ServeMux) Prepare() { for _, plugin := range m.plugins { used := false if sc := plugin.HandlersScanner(); sc != nil { err := sc.HandlersScannerProcess(m, m.router.handlers) if err != nil { panic(err) } used = true } if !used { panic(fmt.Sprintf("unused plugin: %#v", plugin)) } } }
54.
swagger plugin usage swPlugin
:= swagger.NewPlugin(…) ucon.Plugin(swPlugin) s := &fooService{} tag := swPlugin.AddTag(&swagger.Tag{Name: "Foo", Description: ""}) var info *swagger.HandlerInfo info = swagger.NewHandlerInfo(s.List) ucon.Handle("GET", "/api/foo/{id}", info) info.Description, info.Tags = "Fooを1件取得する", []string{tag.Name} … type IntIDRequest struct { ID int64 `json:"id,string"` } func (s *fooService) Get(r *http.Request, req *IntIDRequest) (*FooJSON, error) { … }
55.
go-endpoints(再掲 s := &fooService{} api,
err := endpoints.RegisterService(s, "foo", "v1", "Foo API", true) if err != nil { panic(err.Error()) } info := api.MethodByName("Get").Info() info.HTTPMethod, info.Path, info.Desc = “GET", "/foo/{id}", “Fooを1件取得する" … type IntIDRequest struct { ID int64 `json:"id,string"` } func (s *fooService) Get(r *http.Request, req *IntIDRequest) (*FooJSON, error) { … }
56.
コード規模の話 • 本体 1329行 •
ls | grep .go | grep -v _test.go | xargs wc -l • swaggerプラグイン 1138行 • find ./swagger -type f | grep .go | grep -v sample | grep -v _test.go | xargs wc -l
57.
利用事例
58.
利用サイト • favclip • 技術書典
応募サイト • 怖くてOSSにでけんかったすまんな… • Topgate社内では今後使っていくはず…
59.
swagger関連ツール • swagger-uiの話 • Go用クライアントライブラリの話 •
TypeScript用型定義ファイル生成の話
60.
求む!
61.
求む! • 利用してみてブログ書く • 利用してみて質問する •
利用してみて… 自分が使えるようになると 満足するタイプ
62.
We are hiring
63.
We are hiring
1 • 開発:テレビ朝日 • jwg, genbase 他 必要に応じて製造 • http://www.favclip.com/ • appengine/go開発者絶賛募集中!
64.
We are hiring
2 • Topgate社も絶賛募集中です • appengineできる人 • HTML, CSS, JS得意な人 • その他
65.
雑談
66.
https://github.com/golang/proposal/blob/master/ design/15292-generics.md
67.
👍for Web app
Download