Server Side Framework Slimaneの紹介

Server Side Framework Slimaneの紹介

ポテトチップス#30で発表した資料です。

9ebab3d4f66a62a859ad238e7e97597f?s=128

Yuki Takei

June 23, 2016
Tweet

Transcript

  1. 1.

    S e r v e r S i d e

    S w i f t F r a m e S l i m a n e ͷ ঺ հ 2 0 1 6 J u n 2 3 p o t a t o t i p s 3 0 Yu k i Ta k e i
  2. 3.

    n o p p o M a n ͜ ͱ

    ɺ ෢ Ҫ ༏ ݾ ͱ ਃ ͠ · ͢ɻ
  3. 5.
  4. 7.
  5. 8.
  6. 10.

    ๻ ͕ ։ ൃ ͯ͠ ͍ Δ S w i

    f t 3 ͷ WA F / H T T P S e r v e r h t t p s : / / g i t h u b . c o m / n o p p o M a n / S l i m a n e • 100%ඇಉظ(libuvϕʔεͷϥϯλΠϜɻlibuv͸node.jsͷ৺ଁ) • ExpressΛΠϯεύΠΞ(Ϟδϡʔϧࢦ޲) • Stand alone HTTP Server • ߴ଎ (node.jsͷ5ഒɺRevel(GO)ͷ2ഒ) • Open-SwiftʹଌͬͨAPIσβΠϯ • Ϛϧνϓϩηε؀ڥʹ΋ରԠ(Cluster/WorkerɻipcͰࢠϓϩηεͱ௨৴) • CoreFoundationʹґଘ͠ͳ͍
  7. 11.

    S w i f t y - L i b

    u v S U V S K E LT O N S L I M A N E SlimaneͷϨΠϠʔ OS App libuvͷSwiftόΠϯσΟϯά ඇಉظωοτϫʔΫϓϥοτϑΥʔϜ TCPɺUDPɺProcessɺ FIleSystemɺDNS etc… SuvϕʔεͷHTTPαʔόʔ HTTPϓϩτίϧͷύʔζ ΞϓϦέʔγϣϯϑϨʔϜϫʔΫ system callɺevent loop
  8. 12.

    import Slimane let app = Slimane() // Register a middleware

    app.use { req, next, completion in print("[pid:\(Process.pid)]\t\(Time())\t\(req.path ?? "/")") next(to: req, result: completion) } // Routing app.get("/") { req, responder in responder { Response(body: "Welcome Slimane!") } } try! app.listen(port: 3000) // Server is listening at 0.0.0.0:3000 ΞϓϦέʔγϣϯͷىಈίʔυ
  9. 14.

    $ n p m i - g s l i

    m a n e - c l i
  10. 16.

    S l i m a n e ͸ F W

    ࣗ ମ ͸ খ ͞ ͍Ͱ ͢ ͕ɺ ༷ ʑ ͳ Ϟ δϡ ʔϧ Λ ૊ Έ ߹ Θ ͤ ͯ Ξ ϓ Ϧ έ ʔ γ ϣ ϯ Λ ߏ ங Ͱ ͖ · ͢ɻ
  11. 17.

    S e s s i o n M i d

    d l e w a re https://github.com/slimane-swift/SessionMiddleware ηογϣϯػೳΛఏڙɻ RedisΛSessionσʔλͷετΞઌʹઃఆՄೳ https://github.com/slimane-swift/SessionRedisStore
  12. 18.

    B o d y P a r s e r

    ( m i d d l e w a re ) https://github.com/slimane-swift/BodyParser JSONɺFormDataͷύʔζػೳΛఏڙ
  13. 22.

    Q W F u t u re https://github.com/slimane-swift/QWFuture IOΛϒϩοΫ͢Δؔ਺΍ɺΠϕϯτϧʔϓΛࢭΊͯ͠·͏Α͏ ͳॏ͍ॲཧΛ͢ΔࡍʹɺผεϨουͰॲཧΛ࣮ߦͯ͠ऴΘͬͨ

    ΒϝΠϯϧʔϓʹ໭͢ͱ͍ͬͨॲཧΛߦ͏ࡍʹར༻ɻ ʢGCDͷdispatch_asyncΈ͍ͨͳ΋ͷΛFutureΛѻ͏Α͏ͳΠ ϯλʔϑΣʔεͰఏڙ͍ͯ͠Δ΋ͷʣ
  14. 25.

    ί ϯ τ Ϧ Ϗ ϡ ʔ λ ʔ ื

    ू ͠ ͯ ͓ Γ · ͢ ʂ ʂ ʂ https://slimane-swift-slackin.herokuapp.com/ Slack channel͸ͪ͜Β