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

Parsing case study in Go / Go Conference mini 2023 Winter IN KYOTO

Parsing case study in Go / Go Conference mini 2023 Winter IN KYOTO

Ken’ichiro Oyama

December 01, 2023
Tweet

More Decks by Ken’ichiro Oyama

Other Decks in Technology

Transcript

  1. Parsing case study in Go
    খࢁ݈Ұ࿠ / GMO PEPABO inc.
    2023.12.2 Go Conference mini 2023 Winter IN KYOTO
    1

    View full-size slide

  2. ࣗݾ঺հ
    ٕज़෦ɹٕज़ج൫νʔϜ
    2018೥ த్ೖࣾ
    খࢁ ݈Ұ࿠ Ken’ichiro Oyama
    গ࣮͠༻తͰখ͞ͳOSSΛॻ͘ͷ͕झຯɻ
    ● GitHub : k1LoW
    ● Twitter : @k1LoW
    2

    View full-size slide

  3. GMOϖύϘʹ͍ͭͯ
    3
    https://pepabo.com

    View full-size slide

  4. ΞδΣϯμ
    • ຊηογϣϯʹ͓͚Δύʔε
    • έʔεελσΟʢέʔεͱ࣮૷ͱֶͼʣ
    • ͓ΘΓʹ
    4

    View full-size slide

  5. 5
    ຊηογϣϯʹ͓͚Δύʔε

    View full-size slide

  6. 6
    ຊηογϣϯʹ͓͚Δύʔε
    ύʔε
    • ຊηογϣϯʹ͓͚Δύʔεͱ͸ʮจࣈྻ΍όΠτྻ͔Βҙຯͷ͋Δߏ଄ԽσʔλΛநग़͠׆༻
    ͢Δ͜ͱʯΛࢦ͢ɻҰൠతͳʮύʔεʯͷఆٛΑΓ΋গ͠޿͍ղऍɻ
    • จࣈྻ΍όΠτྻ … string, []byte, io.Reader
    • ߏ଄Խσʔλ … struct, map, slice, chan
    • ຊηογϣϯͰ͸σγϦΞϥΠζ΍σίʔυ΋ؚΉʢͳͷͰɺ͋·Γʮύʔεʯͷఆٛʹͩ͜ΘΒͳ͍Ͱ΋Β͑Δͱ
    خ͍͠Ͱ͢🙏 ʣɻ

    View full-size slide

  7. 7
    ຊηογϣϯʹ͓͚Δύʔε
    ύʔε
    • ύʔεΛʮࣈ۟ղੳʯͱʮߏจղੳʯʹ෼͚ͯߟ͑Δɻ
    • ࣈ۟ղੳ͚ͩΛ׆༻͢Δ΋ͷ΋ύʔεʹؚΊΔɻ
    • ຊηογϣϯʹ͓͚Δʮࣈ۟ղੳʯͱʮߏจղੳʯ΋ҰൠΑΓগ͠޿ٛͷఆٛɻ
    • ࣈ۟ղੳ … จࣈྻ΍όΠτྻΛཁૉʢτʔΫϯʣͷྻʹ෼ղ͢Δ
    • ߏจղੳ … τʔΫϯྻΛҙຯΛ൓өͨ͠ߏ଄ʹม׵͢Δ

    View full-size slide

  8. έʔεελσΟ
    8

    View full-size slide

  9. 9
    README.mdͷ
    Ұ෦͚ͩࠩ͠ସ͑Δ

    View full-size slide

  10. 10
    README.mdͷҰ෦͚ͩࠩ͠ସ͑Δ
    github.com/k1LoW/repin
    • README.mdͳͲɺෳ਺ߦʹΘͨΔจࣈྻͷҰ෦͚ͩΛࠩ͠ସ͑ΔͨΊͷπʔϧ/ϥΠϒϥϦ
    • ։࢝ΩʔϫʔυͱऴྃΩʔϫʔυΛࢦఆ͢ΔͱͦͷΩʔϫʔυؒͷจࣈྻΛࠩ͠ସ͑Δ
    • ྫ: ։࢝Ωʔϫʔυ ```console ɺऴྃΩʔϫʔυ ``` ʹͯ͠ίϚϯυͷϔϧϓͷग़
    ྗΛ࠷৽ʹࠩ͠ସ͑
    • ॲཧͷಛ௃
    • ͻͱ͔ͨ·Γͷෳ਺ߦͷจࣈྻΛೖྗͱͯͦ͠ͷ్தͷจࣈྻΛࠩ͠ସ͑Δ
    • ෳ਺ߦΛ·ͱΊͯॲཧ͢Δඞཁ͕͋Δ
    • ܾ·ͬͨߏจͱ͍ͬͨ΋ͷ͸ͳ͍

    View full-size slide

  11. 11
    README.mdͷҰ෦͚ͩࠩ͠ସ͑Δ
    ύʔεͷ࣮૷
    • ࣈ۟ղੳΛbufio.ScannerͰ࣮૷
    • ಠࣗbufio.SplitFuncΛॻ͘͜ͱͰΩʔϫʔυ֎ͱΩʔϫʔυؒͰ෼ׂ
    • ࣈ۟ղੳ݁ՌΛ Scan() Ͱड͚औ͍ͬͯ͘ʢ []string ʣ
    • ॱ൪ʹΩʔϫʔυ֎ -> Ωʔϫʔυؒ -> Ωʔϫʔυ֎ -> …
    • ͋ͱ͸Ωʔϫʔυؒͷจࣈྻ͚ͩࠩ͠ସ͑ͭͭ૊Έཱͯͯग़ྗ͢Δ͚ͩ

    View full-size slide

  12. 12
    README.mdͷҰ෦͚ͩࠩ͠ସ͑Δ
    bufio.SplitFunc
    • bufio.Scanner.Split() Ͱઃఆ͢Δ͜ͱͰScan()ͷڍಈΛม͑Δ͜ͱ͕Ͱ͖Δ

    View full-size slide

  13. 13
    ඪ४ग़ྗʹྲྀΕ͍ͯΔϩάΛ
    ύΠϓͰड͚औͬͯ৭෇͚͢Δ

    View full-size slide

  14. 14
    ඪ४ग़ྗʹྲྀΕ͍ͯΔϩάΛύΠϓͰड͚औͬͯ৭෇͚͢Δ
    github.com/k1LoW/colr
    • ඪ४ೖྗʹྲྀΕΔϩάʹରͯ͠ࢦఆͨ͠จࣈྻʹϚονͨ͠Β͚ͦͩ͜৭෇͚Λ͢Δπʔϧ
    • ϩά ”Error” ΍ “status:500” ͳͲΛڧௐ͢Δ͜ͱͰϩάΛΈ΍͘͢͢ΔͨΊͷ΋ͷ
    • tail -F /var/log/nginx/access.log | colr POST GET 404 500 search
    • ॲཧͷಛ௃
    • ೖྗ͸ऴ୺͕ෆ໌ͷετϦʔϜɻॱ࣍ॲཧ͍ͯ͘͠ඞཁ͕͋Δ
    • ୯ʹ৭෇͚ͳͷͰɺϩάͷߏจΛߟྀ͢Δඞཁ͸ͳ͍ɻ1ߦͮͭॲཧͯ͠ྑ͍ɻ

    View full-size slide

  15. 15
    ඪ४ग़ྗʹྲྀΕ͍ͯΔϩάΛύΠϓͰड͚औͬͯ৭෇͚͢Δ
    ύʔεͷ࣮૷
    • ࢦఆͨ͠จࣈྻ ( args ) ʹϚονͨ͠Β͚ͦͩ͜৭෇͚Λ͢Δ
    • ೖྗ͸os.Stdin ( io.Reader )
    • ग़ྗ͸ chan string
    • ࣈ۟ղੳ͍ͭͰʹ৭෇͚͢Δ

    View full-size slide

  16. 16
    ඪ४ग़ྗʹྲྀΕ͍ͯΔϩάΛύΠϓͰड͚औͬͯ৭෇͚͢Δ
    ύʔεͷ࣮૷ʢHandle(context.Context, io.Reader) <-chan stringʣ
    • bufio.NewReader(os.Stdin) ->
    ReadString(‘\n’)Ͱߦ୯Ґʹ෼ׂ
    • ߦ͝ͱʹ৭෇͚ ( Paint() )
    • ಺෦͸࣮࣭strings.ReplaceAll
    • ৭෇͚݁ՌΛ chan stringʹྲྀ͢
    • ʢ࣮͸ʣp.Handle()͕ඪ४ग़ྗΛड͚औͬ
    ͯ΋ྑ͍
    • ʢ࣮͸ʣchan []byte Ͱ΋ྑ͍

    View full-size slide

  17. 17
    VIEWςʔϒϧͰ࢖༻͞Ε͍ͯΔ
    ςʔϒϧͷҰཡΛऔಘ͢Δ

    View full-size slide

  18. 18
    VIEWςʔϒϧͰ࢖༻͞Ε͍ͯΔςʔϒϧͷҰཡΛऔಘ͢Δ
    github.com/k1LoW/tbls
    • σʔλϕʔεͷεΩʔϚΛ΋ͱʹυΩϡϝϯτΛੜ੒ͯ͘͠ΕΔπʔϧ
    • VIEWςʔϒϧΛߏ੒͍ͯ͠ΔςʔϒϧͷҰཡΛυΩϡϝϯτʹදࣔ͢Δػೳ͕͋Δ
    • Ұ෦ͷσʔλϕʔεγεςϜͷΈରԠ
    • ॲཧͷಛ௃
    • VIEWςʔϒϧͷDDLʢCREATE VIEW xxxx ASʣ͸σʔλϕʔεγεςϜ͔ΒऔಘͰ͖Δ
    • ςʔϒϧҰཡ͕ཉ͍͚ͩ͠

    View full-size slide

  19. 19
    VIEWςʔϒϧͰ࢖༻͞Ε͍ͯΔςʔϒϧͷҰཡΛऔಘ͢Δ
    ύʔεͷ࣮૷
    • ʮSQLΛSQLͱ͔ͯͬ͠͠Γʢࣈ۟/ߏจʣղੳ͢Δඞཁ͸ͳ͍ʯ
    • ࣈ۟ղੳΛbufio.ScannerͰ࣮૷
    • ΫΥʔτΛؾʹ͠ͳ͕ΒτʔΫϯʹ෼ׂ͢Δ͚ͩ

    View full-size slide

  20. 20
    VIEWςʔϒϧͰ࢖༻͞Ε͍ͯΔςʔϒϧͷҰཡΛऔಘ͢Δ
    ςʔϒϧ໊ͷ൑ఆ
    • “FROM” ͔ “JOIN” ͷ࣍ͷτʔΫϯ͕ςʔϒϧ໊
    ͱ͍͏൑ఆͰे෼
    • ಺ɺ“WITH” Ͱఆٛ͞ΕͨҰ࣌తͳςʔϒ
    ϧ໊͚ͩআ͘
    • VIEWςʔϒϧͷDDLͷಛ௃Λཧղ͓͚ͯ͠͹શ
    ͯΛτʔΫϯ൑ผ͢Δඞཁ͸ͳ͍

    View full-size slide

  21. 21
    σʔλϕʔεʹྲྀΕΔ
    ύέοτΛղੳͯ͠
    ߏ଄ԽΫΤϦϩάΛ࡞Δ

    View full-size slide

  22. 22
    σʔλϕʔεʹྲྀΕΔύέοτΛղੳͯ͠ߏ଄ԽΫΤϦϩάΛ࡞Δ
    github.com/k1LoW/tcpdp
    • σʔλϕʔεʹྲྀΕΔύέοτΛղੳͯ͠σʔλϕʔεͷߏ଄ԽΫΤϦϩάΛ࡞੒͢Δπʔϧ
    • 3ύλʔϯʹରԠ
    1. ΫϥΠΞϯτͱσʔλϕʔεͷؒʹTCPϓϩΩγαʔόͱͯ͠ىಈ
    2. libpcapΛ࢖ͬͯtcpdumpͱಉ͡࢓૊ΈͰύέοτΛΩϟϓνϟ͢Δ
    3. tcpdump͕μϯϓͨ͠pcapϑΝΠϧΛղੳ͢Δ
    • ॲཧͷಛ௃
    • ෳ਺ͷΫϥΠΞϯτ͔Βͷ઀ଓ͕͋Δ
    • 1ͭͷTCPύέοτʹΫΤϦ͕ऩ·Δͱ͸ݶΒͳ͍
    • σʔλϕʔεϓϩτίϧҙຯͷ͋Δ௨৴͸ΫϥΠΞϯτ-αʔόؒͰԿճ͔ԟ෮͢Δ
    • 3ύλʔϯͷύέοτऔಘʹରԠ͢Δඞཁ͕͋Δ͕ύʔεॲཧ͸ڞ௨Խ͍ͨ͠

    View full-size slide

  23. 23
    σʔλϕʔεʹྲྀΕΔύέοτΛղੳͯ͠ߏ଄ԽΫΤϦϩάΛ࡞Δ
    ύʔεͷ࣮૷
    • TCP઀ଓ͝ͱʹࣈ۟ղੳ͕ඞཁ
    • ࣍ͷTCPύέοτΛ଴ͭͨΊʹύέοτσʔλͷόοϑΝϦϯά͕ඞཁ
    • 3ύλʔϯʹରԠ͢ΔͨΊɺೖྗ͸ѻ͍΍͍͢ []byte ʹͳΔ
    • ύέοτ͔Βҙຯͷ͋Δ୯ҐͰͷ []byte औಘͱσʔλϕʔεϓϩτίϧʹԊͬͨղੳ͕ಉ࣌ʹਐ
    ΉΠϝʔδ

    View full-size slide

  24. 24
    σʔλϕʔεʹྲྀΕΔύέοτΛղੳͯ͠ߏ଄ԽΫΤϦϩάΛ࡞Δ
    ύέοτͷόοϑΝϦϯά
    • ύέοτ͔Βҙຯͷ͋Δ୯ҐͰͷ []byte औಘ
    • ҙຯͷ͋ΔαΠζ·ͰόοϑΝϦϯάͯ͠
    ·ͱΊͯdumperʢσʔλϕʔεϓϩτίϧ
    ղੳثʣʹ౉͢
    • TCP઀ଓͷ։࢝λΠϛϯάͰ key Λੜ੒ͯ͠ɺͦ
    ΕͧΕͰόοϑΝϦϯά

    View full-size slide

  25. 25
    σʔλϕʔεʹྲྀΕΔύέοτΛղੳͯ͠ߏ଄ԽΫΤϦϩάΛ࡞Δ
    ύέοτͷղੳ
    • ߏจղੳ͸ͻͨ͢Β []byte Λσʔλϕʔεϓ
    ϩτίϧʹԊͬͯղੳ͍ͯ͘͠ͷΈ

    View full-size slide

  26. 26
    ͜͜·Ͱͷֶͼ

    View full-size slide

  27. 27
    ͜͜·Ͱͷֶͼ
    ࣈ۟ղੳ͸έʔεʹΑͬͯ͸ࡶʹͰ͖Δ
    • ೖྗΛઌ಄͔ΒॱʹಡΈࠐΜͰ͍͘ͷ͕ϕʔγοΫͳख๏
    • τʔΫϯʹ෼ׂ͢ΔͨΊʹ͸ઌಡΈͯ͠͸͡ΊͯτʔΫϯछผΛ൑ఆͰ͖Δ͜ͱ͕ଟ͍
    • ઌಡΈʹٻΊΒΕΔཁ͕݅ෳࡶͰ͋Ε͹͋Δ΄Ͳࣈ۟ղੳͷ࣮૷͕೉͘͠ͳΔʢײ૝ʣ
    • ҰํͰ
    • έʔεʹΑͬͯ͸εϖʔε۠੾ΓͰτʔΫϯʹ෼ׂͰ͖ΔͳΒॳख strings.Split ͰࡁΉ৔߹
    ΋͋Δ
    • έʔεʹΑͬͯ͸શͯͷจࣈྻΛτʔΫϯʹ͢Δඞཁ͸ͳ͍ʢۭന΍վߦΛແࢹ͢Δͷͱ
    ಉ͡ʣ

    View full-size slide

  28. 28
    ͜͜·Ͱͷֶͼ
    ࣈ۟ղੳʹ͸ଟஈ΍ฒߦͷબ୒ࢶ͕͋Δ
    • ٻΊΔτʔΫϯྻΛಘΔ·ͰͷղੳॲཧΛଟஈʹ͢Δͱ࣮૷͠΍͍͢৔߹͕͋Δ
    • ߦʹΑͬͯτʔΫϯ͕෼ׂ͞ΕΔ͜ͱ͕อূ͞ΕΔ৔߹͸ʮ·ͣߦ͝ͱʯʮͦͯ͠ߦ୯Ґ
    Ͱղੳʯʹଟஈʹ͢ΔͳͲ
    • ฒߦͯ͠ղੳͯ͠ෳ਺or୯Ұͷߏ଄ԽσʔλΛಘΔ৔߹΋͋Δʢྫ: ϚϧνύʔτΞοϓϩʔυʣ
    • ʮଟஈʯ΍ʮฒߦʯ͕͠΍͍࣮͢૷Λ৺͕͚Δͱɺඞཁͳ࣌ʹchannel΍goroutineΛ࢖͍ɺॲཧ
    ޮ཰Λ্͛Δ͜ͱ΋Ͱ͖Δ

    View full-size slide

  29. 29
    ͜͜·Ͱͷֶͼ
    bufio.ScannerʢVS bufio.Reader VS []rune VS []byteʣ
    • Ұ౓ʹಡΈࠐΉόΠτ਺ͷ্ݶ͕Θ͔͍ͬͯΔ৔߹ʢ΋͘͠͸͋Δఔ౓খ͍͞ͱΘ͔͍ͬͯΔ৔
    ߹ʣbufio.Scannerͷ࢖͍উख͕ྑ͍
    • ؆қͳτʔΫϯ෼ׂʹ͓͍ͯ͸bufio.SplitFuncͷ֦ு͕ޮ͘
    • ಡΈࠐΉόΠτ਺ͷ্ݶ͕Θ͔͍ͬͯΔͳΒ͹ bufio.Scanner.Buffer() Ͱ্ݶΛઃఆͰ͖Δ
    • ಡΈࠐΉόΠτ਺͕Θ͔Βͳ͍৔߹ʢେ͖͘ͳΔՄೳੑ͕େ͖͍৔߹ʣ͸ bufio.Reader
    • จࣈͱͯ͠ύʔε͢Δ৔߹͸[]runeͰʢྫ: github.com/goccy/go-yaml/scannerʣ
    • ϓϩτίϧͷϔομͳͲαΠζ͕໌Β͔ͳ΋ͷͷ৔߹͸[]byteͰ

    View full-size slide

  30. 30
    ֤छίʔυΧόϨοδϨϙʔτ͔Β
    ৘ใΛऔಘ͢Δ

    View full-size slide

  31. 31
    ֤छίʔυΧόϨοδϨϙʔτ͔Β৘ใΛऔಘ͢Δ
    github.com/k1LoW/octocov
    • ίʔυΧόϨοδΛऩूɾϨϙʔτ͢Δπʔϧ
    • πʔϧͷಛੑ্ɺαϙʔτ͢ΔΧόϨοδϑΥʔϚοτ͸ଟ͚Ε͹ଟ͍΄Ͳྑ͍
    • v0.54.6Ͱͷαϙʔτ … Go coverageɺLCOVɺSimpleCovɺCloverɺCoberturaɺJaCoCo
    • ॲཧͷಛ௃
    • େ఍1ͭͷϑΝΠϧ
    • ΋ͱ΋ͱΧόϨοδϨϙʔτϑΝΠϧ͸ϚγϯϦʔμϒϧͳߏ଄ʹͳ͍ͬͯΔ

    View full-size slide

  32. 32
    ֤छίʔυΧόϨοδϨϙʔτ͔Β৘ใΛऔಘ͢Δ
    ύʔεͷ࣮૷
    • ޿͘஌ΒΕͨϚγϯϦʔμϒϧͳϑΥʔϚοτͳͷͰࣈ۟ղੳ͔Βߏจղੳͷ్த·Ͱύοέʔ
    δͷར༻ͳͲͰγϣʔτΧοτͰ͖Δ
    • SimpleCov … JSON
    • CloverɺCoberturaɺJaCoCo … XML
    • Go coverage … ͢Ͱʹύοέʔδ͕ఏڙ͞Ε͍ͯΔʢgolang.org/x/tools/coverʣ
    • LCOV … ಠ࣮ࣗ૷

    View full-size slide

  33. 33
    ֤छίʔυΧόϨοδϨϙʔτ͔Β৘ใΛऔಘ͢Δ
    ΧόϨοδϑΥʔϚοτͷύʔε
    • XML΍JSONͰߏ଄ԽͰ͖Ε͹ͦΕΛΧόϨοδ
    ϑΥʔϚοτͷ࢓༷ʹ߹ΘͤͯɺΧόϨοδͷߏ଄ʹ
    Ϛοϐϯά͢Ε͹ྑ͍
    • ʢಠ࣮ࣗ૷ͱ͸ݴ͑ʣLCOV΋ϚγϯϦʔμϒϧʹ
    ͳ͍ͬͯΔͷͰࣈ۟ղੳ͸ bufio.Scanner Ͱे෼ରԠ
    Ͱ͖Δɻͦͷ͋ͱ͸ଞͷΧόϨοδϑΥʔϚοτͱಉ
    ͡ɻ

    View full-size slide

  34. 34
    YAMLϑΝΠϧͷҰ෦Ͱ
    ม਺ల։Λ͢Δ

    View full-size slide

  35. 35
    YAMLϑΝΠϧͷҰ෦Ͱม਺ల։Λ͢Δ
    github.com/k1LoW/expand
    • YAMLϑΝΠϧͷҰ෦Ͱม਺ల։Λ͢ΔػೳΛ࡞Δ͜ͱ͕Ͱ͖ΔϥΠϒϥϦ
    • ؀ڥม਺ల։ͱ͔ɺGitHub ActionsͷWorkflow YAMLͷΑ͏ͳม਺ల։ͱ͔
    • ॲཧͷಛ௃
    • ม਺ల։ͨ͋͠ͱͷߏจղੳ͸YAMLύʔαʔʹ೚͍ͤͨ
    • env DEBUG=true ͷจࣈྻ true Λͦͷ··YAMLύʔαʔʹ౉ͯ͠bool஋ͱ͍ͨ͠
    • JSONΛ౉ͨ͠ΒYAMLͷߏจͱͯ͠ల։͞Εͯཉ͍͠
    • ͱ͸͍͑ɺల։ͨ͠஋ͷߏ଄Ͱల։લͷYAMLͷߏจ໦͕ݩͱେ͖ͣ͘ΕΔΑ͏ͳ࣮૷Ͱ
    ͸͋ͬͯ͸͍͚ͳ͍ʢ text/template ͳͲʹΑΔม਺ల։Ͱ͸೉͍͠ͱ൑அ ʣ

    View full-size slide

  36. 36
    YAMLϑΝΠϧͷҰ෦Ͱม਺ల։Λ͢Δ
    ύʔεͷ࣮૷
    • YAMLจࣈྻͷࣈ۟ղੳΛઐ༻ͷύοέʔδʢgithub.com/goccy/go-yaml/lexerʣʹ೚ͤɺਖ਼͘͠
    ෼ղ͞ΕͨτʔΫϯ͝ͱʹม਺ల։ॲཧΛ࣮૷͢Δ
    • τʔΫϯ͝ͱͰ͋Ε͹ݩͷߏ଄่͕ΕΔՄೳੑ͕খ͍͞
    • ม਺ల։ޙͷτʔΫϯΛ࠶౓YAMLͷจࣈྻʹ໭͢ʢ͜͜·Ͱ͕expandͷػೳʣ
    • ͦͯ͠࠶౓YAMLύʔαʔͰύʔεͤ͞Δ

    View full-size slide

  37. 37
    YAMLϑΝΠϧͷҰ෦Ͱม਺ల։Λ͢Δ
    ύʔεͷ࣮૷ʢReplaceYAMLʣ
    • lexer.Tokenize()ͰτʔΫϯྻΛಘͯஔ׵ՄೳͳτʔΫϯ͝ͱʹrepFnͰஔ׵Λ͢Δ
    • ஔ׵ޙͷτʔΫϯΛݩͷYAMLจࣈྻʹ૊ΈཱͯΔ

    View full-size slide

  38. 38
    ੜ੒͞ΕͨGoͷίʔυΛ
    ͞Βʹॻ͖׵͑Δ

    View full-size slide

  39. 39
    ੜ੒͞ΕͨGoͷίʔυΛ͞Βʹॻ͖׵͑Δ
    github.com/k1LoW/sqlc-go-one-or-fail
    • sqlcʢsqlc-goʣͰੜ੒͞ΕͨGoͷίʔυΛ͞Βʹॻ͖׵͑Δπʔϧ
    • :one Ͱੜ੒͞ΕͨΫΤϦϝιουͷॲཧΛ0ߦͷ͚࣌ͩͰͳ͘1ߦΑΓଟ͘ͷߦΛऔಘͰ͖
    ͨ৔߹΋Τϥʔʹ͢ΔΑ͏ʹमਖ਼͢Δʢ1ߦऔಘ͔͠ڐ༰͠ͳ͍Α͏ʹ͢Δʣ
    • ॲཧͷಛ௃
    • ର৅͸Goͷίʔυ
    • ੜ੒͞ΕͨGoͷίʔυͳͷͰੜ੒͞Εͨίʔυʹύλʔϯ͕͋Δ

    View full-size slide

  40. 40
    ੜ੒͞ΕͨGoͷίʔυΛ͞Βʹॻ͖׵͑Δ
    ύʔεͷ࣮૷
    • GoͷίʔυΛGoͷίʔυͱͯ͠มߋՕॴΛಛఆ͢Δ
    • GoͷASTͷύοέʔδʢgo/astɺgolang.org/x/tools/go/ast/astutilʣΛ׆༻
    • มߋՕॴͷAST͔Βඞཁͳ৘ใΛൈ͖ग़্ͨ͠Ͱɺࠩ͠ସ͑ΔASTΛੜ੒ͯࠩ͠͠ସ͑ɻ

    View full-size slide

  41. 41
    ੜ੒͞ΕͨGoͷίʔυΛ͞Βʹॻ͖׵͑Δ
    ύʔεͷ࣮૷ʢRewrite(ctx context.Context, p string, w io.Writer) errorʣ
    • astutil.Apply() Λ࢖ͬͯ௚઀ASTΛࠩ͠ସ͑
    ͍ͯΔ
    • ੜ੒͞ΕͨGoͷίʔυͳͷͰɺ͋Δఔ౓
    ϧʔϧԽ͞Ε͍ͯΔͨΊɺࠩ͠ସ͑ର৅Λ
    ಛఆ͢ΔͨΊͷ൑ఆ৚݅΋ͦ͜·Ͱ࡞Γࠐ
    Ήඞཁ͕ͳ͍

    View full-size slide

  42. 42
    ͜͜·Ͱͷֶͼ

    View full-size slide

  43. 43
    ຊηογϣϯʹ͓͚Δύʔε
    ߏจղੳ͕ඞཁͩͬͨΓৄࡉͳࣈ۟ղੳ͕ඞཁͳύʔε͸࣮૷ίετ͕ߴ͍
    • ղੳ͍ͨ͠ߏจʹΑ࣮ͬͯ૷͕େ͖͘ҟͳΔʢͦΕ͸ͦ͏ʣ
    • ϓϩάϥϛϯάݴޠ΍ͦΕʹྨ͢Δ΋ͷ͸ந৅ߏจ໦ʢASTʣʹͳΔ͜ͱ͕ଟ͍
    • ͦΕʹྨ͢Δ΋ͷ … JSON΍YAML͸ͦͷ࠷ͨΔྫ
    • ߏจղੳͷख๏͸ଟ͘ఏҊ͞Ε͍ͯΔ
    • ʢಛʹAST͕ඞཁͳϨϕϧͷʣύʔαΛಠࣗʹ։ൃ͢Δͷ͸͔ͳΓίετ͕ߴ͍ͨΊɺαʔυ
    ύʔςΟ΋ؚΊద੾ͳύοέʔδʹ೚ͤΔͷ͕ྑ͍

    View full-size slide

  44. 44
    ͦͷଞ:
    ύοέʔδΛ׆༻͍ͯ͠Δ
    έʔε

    View full-size slide

  45. 45
    ͦͷଞ: ύοέʔδΛ׆༻͍ͯ͠Δέʔε
    έʔε͝ͱʹ׆༻͍ͯ͠Δศརύοέʔδ
    • .ssh/config Λ࢖༻ͨ͠SSH઀ଓʢgithub.com/k1LoW/sshcʣ
    • ssh_configͷύʔε … github.com/kevinburke/ssh_config
    • .protoϑΝΠϧͷύʔεͱͦΕΛར༻ͨ͠gRPC௨৴ʢgithub.com/k1LoW/grpcstubʣ
    • .protoϑΝΠϧͷύʔε … github.com/bufbuild/protocompile
    • OpenAPI SpecʹΑΔHTTPϦΫΤετ/ϨεϙϯεͷόϦσʔγϣϯʢgithub.com/k1LoW/runnʣ
    • OpenAPIυΩϡϝϯτͷύʔε … github.com/getkin/kin-openapi
    • άϧʔϐϯάͰ͖ΔProcess exporter for Prometheusʢgithub.com/k1LoW/grouped_process_exporterʣ
    • /procʢprocfsʣ ͷύʔε … github.com/prometheus/procfs

    View full-size slide

  46. • ຊηογϣϯͰ͸ʮύʔεʯͷ࣮૷ʹ͍༷ͭͯʑͳέʔεΛ঺հͨ͠ɻ
    • ࠓճ͸ΑΓଟ͘ͷέʔεΛ঺հ͢Δ͜ͱͰԿ͔͠Βͷؾ͖͕ͮಘΒΕΕ͹ͱ͍͏ظ଴Λࠐ
    Ίͯߏ੒ͨ͠ɻ
    • Ұݴʹʮύʔεʯͱ͍ͬͯ΋έʔε͝ͱʹಛ௃͕͋Γɺ࣮૷ํ๏͕͋Δɻ
    • ҰํͰέʔεΛ၆ᛌͯ͠ΈΔͱڞ௨͍ͯ͠Δύʔλϯ΋͋ΔΑ͏ʹݟ͑Δɻ
    • ύʔεύοέʔδΛఏڙͯ͘͠Ε͍ͯΔOSSϝϯςφͷํʹ͸ײँ͔͠ͳ͍ɻ
    • ֤έʔεͷ۩ମతͳ࣮૷Λ֬ೝ͍ͨ͠৔߹ɺ঺հͨ͠έʔε͸શͯOSSʹͳ͍ͬͯΔͷͰɺ֤Ϧ
    ϙδτϦͰࢀরՄೳʢPull Request଴ͬͯ·͢ʂʣɻ
    47
    ͓ΘΓʹ
    ͓ΘΓʹ

    View full-size slide

  47. Thank You!
    Thank You!
    48

    View full-size slide