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
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
Spatial Rendering for Apple Vision Pro
warrenm
0
120
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.7k
testcontainers のススメ
sgash708
1
120
Jakarta EE meets AI
ivargrimstad
0
260
return文におけるstd::moveについて
onihusube
1
1.2k
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
280
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
270
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
600
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
290
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
490
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
RailsConf 2023
tenderlove
29
940
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Producing Creativity
orderedlist
PRO
342
39k
A better future with KSS
kneath
238
17k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
The Invisible Side of Design
smashingmag
298
50k
Building Your Own Lightsaber
phodgson
103
6.1k
Agile that works and the tools we love
rasmusluckow
328
21k
BBQ
matthewcrist
85
9.4k
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?