Upgrade to Pro — share decks privately, control downloads, hide ads and more …

net/httpでつくるHTTPルーター自作入門

bmf_san
November 13, 2021
350

 net/httpでつくるHTTPルーター自作入門

bmf_san

November 13, 2021
Tweet

Transcript

  1. net/httpͰͭ͘Δ
    HTTPϧʔλʔࣗ࡞ೖ໳
    @bmf_san

    Go Conference 2021 Autumn

    View full-size slide

  2. • Kenta Takeuchi

    • @bmf_san

    • גࣜձࣾϚΫΞέ/Re-ArchitectureνʔϜ

    • ֤छΤϯδχΞืूதͰ͢ʂ
    ࣗݾ঺հ

    View full-size slide

  3. ࠓ೔࿩͢͜ͱ
    GoͰඪ४ύοέʔδ͚ͩΛ࢖ͬͯɺ

    HTTPϧʔλʔΛࣗ࡞͢Δ࿩

    View full-size slide

  4. ͜Μͳํʹ
    • Goͷॳֶऀ

    • GoͰԿ͔࡞ͬͯΈ͍ͨਓ

    • ݴޠ໰ΘͣHTTPϧʔλʔΛ࡞ͬͯΈ͍ͨਓ

    View full-size slide

  5. ࣗ࡞ͯ͠ΈΔͱɾɾ
    • net/httpͷཧղΛਂΊΔ͖͔͚ͬʹ

    • ΞϧΰϦζϜͱσʔλߏ଄ΛֶͿ͖͔͚ͬʹ

    • ੈͷதͷHTTPϧʔλʔͷߏ଄͕େମ෼͔ΔΑ͏ʹ

    • ࣗ࡞ͷϧʔλʔͰΞϓϦΛ࡞ΕΔΑ͏ʹ

    View full-size slide

  6. લఏ
    • Goͷجຊతͳจ๏ͷཧղ

    • Կ͔͠ΒͷHTTPϧʔλʔΛ࢖ͬͨ͜ͱ͕͋Δ

    View full-size slide

  7. ໨࣍
    • HTTPϧʔλʔͱ͸Կ͔

    • HTTPϧʔλʔͷσʔλߏ଄

    • net/httpʹ͍ͭͯ஌͓͖͍ͬͯͨ͜ͱ

    • ࣮૷ͷ঺հ

    View full-size slide

  8. HTTPϧʔλʔͱ͸
    • ϦΫΤετ͞ΕΔURLͱϨεϙϯεͷॲཧΛ݁ͼ͚ͭΔ

    View full-size slide

  9. HTTPϧʔλʔͷσʔλߏ଄
    • ϦΫΤετ͞ΕΔURLͱϨεϙϯεͷॲཧ
    Λ݁ͼ͚ͭΔ

    URLͱॲཧ͕Ϛοϐϯά͞Εͨ

    σʔλ͕ඞཁ

    View full-size slide

  10. HTTPϧʔλʔͷσʔλߏ଄
    • URLͷ֊૚ → ໦ߏ଄ͱͯ͠දݱ

    View full-size slide

  11. • ໦ʹϊʔυΛ௥Ճ͢Δ㲈ϧʔτͷఆٛ

    • ໦͔ΒϊʔυΛ୳ࡧ͢Δ㲈ϧʔςΟϯά
    HTTPϧʔλʔͷσʔλߏ଄

    View full-size slide

  12. net/httpʹ͍ͭͯ஌͓͖͍ͬͯͨ͜ͱᶃ
    • ʮϚϧνϓϨΫαʯͱʮϋϯυϥʯ

    • ϚϧνϓϨΫα

    • ϦΫΤετͷURLΛొ࿥ࡁΈͷύλʔϯͱরΒ͠߹Θͤ
    ͯɺ࠷΋Ϛον͢ΔϋϯυϥΛݺͼग़͢

    • ϋϯυϥ

    • ϦΫΤετʹԠͨ͡ॲཧΛฦ͢

    View full-size slide

  13. net/httpʹ͍ͭͯ஌͓͖͍ͬͯͨ͜ͱᶄ
    • ϚϧνϓϨΫα

    • Ͳ͜ͰɺͲͷΑ͏ʹϋϯυϥΛొ࿥͍ͯ͠Δͷ͔

    • Ͳ͜ͰɺͲͷΑ͏ʹURLͱύλʔϯͷϚονϯάΛߦ͍ͬͯ
    Δ͔

    • ϋϯυϥ

    • ͲͷΑ͏ʹϋϯυϥΛ࣮૷͢Δͷ͔

    • HandleɺHandlerɺHandleFuncɺHandlerFuncΛ஌Δ

    • ຬ͍ͨͨ͠ΠϯλʔϑΣʔε͸Կ͔

    View full-size slide

  14. • ͜ͷܗͷHTTPαʔόʔͷίʔυΛಡΈղ͘ͷ͕͓͢͢Ί
    ίʔυϦʔσΟϯά

    View full-size slide

  15. • ϝιουϕʔεͷϧʔτఆٛΛαϙʔτ͚ͨͩ͠ͷ؆қతͳϧʔλʔͷ࣮૷

    • ґଘ͸ඪ४ύοέʔδͷΈ
    ࣮૷
    https://github.com/bmf-san/introduction-to-golang-http-router-made-with-net-http/

    View full-size slide

  16. Github
    https://github.com/bmf-san/goblin

    View full-size slide

  17. ؔ࿈ϦϯΫ
    ݻఆπΠʔτʹͿΒԼ͛ͯ͋Γ·͢

    View full-size slide

  18. ͋Γ͕ͱ͏Go͍͟·ͨ͠ʂ

    View full-size slide