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
GoでWeb APIを作る - JSON Hyper-Schemaからいろいろ生成する
Search
tutuming
August 24, 2015
Programming
16
2.9k
GoでWeb APIを作る - JSON Hyper-Schemaからいろいろ生成する
2015.08.24 リブセンス様社内勉強会LT資料
tutuming
August 24, 2015
Tweet
Share
More Decks by tutuming
See All by tutuming
NSQのご紹介
tutuming
1
1.4k
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
690
Quine, Polyglot, 良いコード
qnighy
4
650
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
受け取る人から提供する人になるということ
little_rubyist
0
250
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
250
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.2k
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Rails Girls Zürich Keynote
gr2m
94
13k
How to Ace a Technical Interview
jacobian
276
23k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Done Done
chrislema
181
16k
Transcript
GoͰWeb APIΛ࡞Δ JSON Hyper-Schema͔Β͍Ζ͍Ζੜ͢Δ @tutuming
ࣗݾհ • แ • @tutuming • גࣜձࣾ WACUL CTO
We are hiring!
ԿΛ࡞͍ͬͯΔ͔ • AIΞφϦετ • Google Analytics ࿈ܞ • ࣗಈղੳ •
αΠτͷ՝Λݟ͚ͭΔ We are hiring!
AIΞφϦετͷߏ • όοΫΤϯυ Go, MongoDB, Elasticsearch • ϑϩϯτΤϯυ TypeScript (CoffeeScript)
, AngularJS
Go ͬͯΔਓ !?
ࠓ͍͑ͨ͜ͱ REST API ΛGoͰ։ൃ͢Δͱ͖ • APIυΩϡϝϯτ • ܕఆٛ • όϦσʔγϣϯ
• ϋϯυϥͷͻͳܗ ͍Ζ͍Ζࣗಈੜ͢ΔͱḿΔΑ
Why Go? • εέʔϧ͢ΔΈ -> gorutine, channel • ੩తܕ͚ ->
มߋʹର͢Δ҆৺ײ • ίϯύΠϧҰॠ -> εΫϦϓτݴޠΈ͍ͨʹಈ͔ͤΔ • ϘτϜΞοϓͷจԽ
REST API with Go ΠϯλʔϑΣΠε(JSONͱͷϚοϐϯά)ఆٛͷͭΒΈ map[string]interface{} // ͓खܰ <-> ܕͷϝϦοτͳ͠
struct ఆٛ // ݎ࿚ <-> खͰॻ͘ͷ͠ΜͲ͍
ੜͨ͠Β͑͑Μ • JSON Hyper-Schema • http://json-schema.org/latest/json-schema- hypermedia.html • JSONͷܕఆٛɺόϦσʔγϣϯఆٛ •
+ Http্ͷϦιʔεఆٛ = REST ͜ΕͰʂ
͡ΌʔΜ schema.json ॻ͘ͷͭΒͨΜ 1ϑΝΠϧ 4000ߦ
prmd by heroku • https://github.com/interagent/prmd • YAMLͰ ෳϑΝΠϧʹ͚ͯཧͰ͖Δ • ->
1ͭͷschema.json ʹcombine • schema.json ͔Β υΩϡϝϯτੜͰ͖Δ
શମߏ
JSON ܕఆٛ
Go struct ੜ
Validator ੜ https://github.com/wcl48/valval
Ϧιʔεఆٛ
endpoint Έੜ ্ͷؔΛड͚औͬͯ ύϥϝʔλͷόϦσʔγϣϯ JSONͷੜͳͲΛߦ͏ॲཧΛroterʹઃఆ // GETύϥϝʔλ // PaymentͷϦετΛฦ͢
APIมߋϑϩʔ • YAMLॻ͘ • ఆٛɾυΩϡϝϯτੜ • ίϯύΠϧΤϥʔ͢ • ϩδοΫ࣮ •
ςετॻ͘
ར༻ऀͷ • υοτΛଧͬͨΒิ͕ग़ΔͷͰɺ伳ḜԌ͕࣏Γ·ͨ͠ (29ࡀ உੑ) • ܕ͕͋ΔͱϦϦʔεޙ҆৺ͯ͠Ε·͢ (29ࡀ உੑ) •
υΩϡϝϯτͱ࣮͕ҧ͏ͬͯԥΒΕͳ͘ͳͬͨ (29ࡀ உੑ) • ੜࣦഊͨ͠ͱ͖ͷΤϥʔ͕Θ͔Γʹ͍͘ (29ࡀ உੑ)
·ͱΊ • Go ྑ͍ݴޠ ͚ͩͲ • Web API ࡞Δͱ͖ɺJSONͷܕఆٛͭΒ͍ •
ಛʹϦϦʔεޙมߋଟ͍ • JSON Hyper-Schema Λ prmd ͳͲͷิॿπʔϧͰੜͯ͠ • υΩϡϝϯτɺܕఆٛɺόϦσʔλɺϋϯυϥͷͻͳܗΛੜ͢Δ ͱ • ͱͯޮతɺݎ࿚ͳ։ൃαΠΫϧ͕Ͱ͖͕͋ΔͷͰ͓͢͢Ί
Thank you! Any questions?