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

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

0c9a69560f916778b569086d792680bb?s=47 bmf_san
November 13, 2021
88

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

0c9a69560f916778b569086d792680bb?s=128

bmf_san

November 13, 2021
Tweet

Transcript

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

  2. • Kenta Takeuchi • @bmf_san • גࣜձࣾϚΫΞέ/Re-ArchitectureνʔϜ • ֤छΤϯδχΞืूதͰ͢ʂ ࣗݾ঺հ

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

  4. ͜Μͳํʹ • Goͷॳֶऀ • GoͰԿ͔࡞ͬͯΈ͍ͨਓ • ݴޠ໰ΘͣHTTPϧʔλʔΛ࡞ͬͯΈ͍ͨਓ

  5. ࣗ࡞ͯ͠ΈΔͱɾɾ • net/httpͷཧղΛਂΊΔ͖͔͚ͬʹ • ΞϧΰϦζϜͱσʔλߏ଄ΛֶͿ͖͔͚ͬʹ • ੈͷதͷHTTPϧʔλʔͷߏ଄͕େମ෼͔ΔΑ͏ʹ • ࣗ࡞ͷϧʔλʔͰΞϓϦΛ࡞ΕΔΑ͏ʹ

  6. લఏ • Goͷجຊతͳจ๏ͷཧղ • Կ͔͠ΒͷHTTPϧʔλʔΛ࢖ͬͨ͜ͱ͕͋Δ

  7. Zenn Book

  8. ໨࣍ • HTTPϧʔλʔͱ͸Կ͔ • HTTPϧʔλʔͷσʔλߏ଄ • net/httpʹ͍ͭͯ஌͓͖͍ͬͯͨ͜ͱ • ࣮૷ͷ঺հ

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

  10. HTTPϧʔλʔͷσʔλߏ଄ • ϦΫΤετ͞ΕΔURLͱϨεϙϯεͷॲཧ Λ݁ͼ͚ͭΔ URLͱॲཧ͕Ϛοϐϯά͞Εͨ σʔλ͕ඞཁ

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

  12. • ໦ʹϊʔυΛ௥Ճ͢Δ㲈ϧʔτͷఆٛ • ໦͔ΒϊʔυΛ୳ࡧ͢Δ㲈ϧʔςΟϯά HTTPϧʔλʔͷσʔλߏ଄

  13. net/httpʹ͍ͭͯ஌͓͖͍ͬͯͨ͜ͱᶃ • ʮϚϧνϓϨΫαʯͱʮϋϯυϥʯ • ϚϧνϓϨΫα • ϦΫΤετͷURLΛొ࿥ࡁΈͷύλʔϯͱরΒ͠߹Θͤ ͯɺ࠷΋Ϛον͢ΔϋϯυϥΛݺͼग़͢ • ϋϯυϥ

    • ϦΫΤετʹԠͨ͡ॲཧΛฦ͢
  14. net/httpʹ͍ͭͯ஌͓͖͍ͬͯͨ͜ͱᶄ • ϚϧνϓϨΫα • Ͳ͜ͰɺͲͷΑ͏ʹϋϯυϥΛొ࿥͍ͯ͠Δͷ͔ • Ͳ͜ͰɺͲͷΑ͏ʹURLͱύλʔϯͷϚονϯάΛߦ͍ͬͯ Δ͔ • ϋϯυϥ

    • ͲͷΑ͏ʹϋϯυϥΛ࣮૷͢Δͷ͔ • HandleɺHandlerɺHandleFuncɺHandlerFuncΛ஌Δ • ຬ͍ͨͨ͠ΠϯλʔϑΣʔε͸Կ͔
  15. • ͜ͷܗͷHTTPαʔόʔͷίʔυΛಡΈղ͘ͷ͕͓͢͢Ί ίʔυϦʔσΟϯά

  16. • ϝιουϕʔεͷϧʔτఆٛΛαϙʔτ͚ͨͩ͠ͷ؆қతͳϧʔλʔͷ࣮૷ • ґଘ͸ඪ४ύοέʔδͷΈ ࣮૷ https://github.com/bmf-san/introduction-to-golang-http-router-made-with-net-http/

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

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

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