ä»åãäŸå€ã§ã¯ãããŸããã§ãããããããäœæããŠããæ°ã«å ¥ãã®æ ç»ããã¬ãçªçµãæ倧éã®å¿«é©ããšæå°éã®åŽåã§èŠèŽã§ããããã«ããé³å£°æŒæã®ããã€ãã®ããŒãžã§ã³ã§ã³ã³ãã³ããæäŸããããšãã§ããŸããã ããã«èšã£ãŠãã£ãã ãããŠä»ã人ã®éã®å人ããæ°ã«å ¥ãã®ã·ã§ãŒããŠãŒã¶ãŒã«åãã§æäŸããŠãããšãããããã®äœæã«äŒŽããã®ãç§ã®åé¡ç¹ãããã³ãããã®è§£æ±ºæ¹æ³ã«ã€ããŠã話ããããšæããŸãã æåã®ç« ã§ã¯ãPHPéçºè ã®ç®ãéããŠGoã«ã€ããŠã2çªç®ã®ç« ã§ã¯Kinopoiskã解æããããã®ZenãèŠã€ããããšã«ã€ããŠã3çªç®ã§ã¯ææžåãããŠããªãæ©èœTelegraphã«ã€ããŠèª¬æããŸãã
1. $ alexander-> useLanguageïŒGOLANGïŒ;
ç§ã®ååã¯ã¢ã¬ã¯ãµã³ããŒã21æ³ã§ãã ç§ã¯Webéçºã«æºãã£ãŠãããã»ãšãã©ã®å ŽåãPHPã䜿çšããŠããŸãã
ææææ
PHPã¯å€¢ã®ãããªèšèªãšã¯èšããŸããã ä»ã®èšèªãšåæ§ã圌ã«ã¯é·æãšçæããããŸãã ããããç§ã¯PHPã«ããããããŠããããšã«æ°ã¥ãå§ããŸãã-ãã®èšèªã®éçºã¯æ¬¡ç¬¬ã«éå±ã«ãªãããã®åäŸã®çã¿ã¯åæ§ã®åŒæ°ããšãåæ§ã®é¢æ°ã®ããã§ãããé åºã¯ç°ãªããå¿ ãããäºæž¬å¯èœãªåäœã§ã¯ãªãããã¡ãã匱ãåä»ãã§ãã ãã®ããã次ã®è£œåã§ã¯Golangã䜿çšããããšã«ããŸããã ç§ãå§ãããšããç§ã¯åœŒã«ã€ããŠãããç¥ã£ãŠããŸããïŒ
- 匷ãåä»ã
- ããã»ã©å€ããªãããŒã¯ãŒã
- ãŽã«ãŒãã³ã¯ãããã«äœ¿ãã䟿å©ãªäžŠååŠçã§ã
- 圌ãã¯ãèšèªã¯ã·ã³ãã«ã§äºæž¬å¯èœã§ãããšèšããŸãã
ãŸããç§ã¯éå±ããGolangæ¬ãããã£ãããšããããŸãã æåã¯ãã¹ãŠãéåžžã«çããã£ã...ãŸããæåã®3-5æéã ã¯ããèšèªã®å ¥åã¯éåžžã«ç°¡åã§ãã éæ³ã®æ¬ åŠãšããŒã¯ãŒãã®è±å¯ãããããŠäºæž¬å¯èœãªåäœã¯ãããªãã¯ãããŸã-ããªãããã§ã«ããã°ã©ãã³ã°èšèªã«ç²ŸéããŠãããªãã確ãã«Goãžã®æ²¡å ¥ã¯ããã»ã©æéãããããŸããã éèŠãªçºèšã¯æ¬¡ã®ãšããã§ãã1ããŒãžã®ããŒãžã3幎éæžããŠãããã§çµéšãçµãã£ãããç§ã®èšèãåãæ»ããŸãã èšèªã®äºæž¬å¯èœæ§ãšå³å¯ãªã¿ã€ãã³ã°ã«ãããèµ·åãšãã§ãã¯ã®ããã«ãã€ããªãã³ã³ãã€ã«ããã«éåžžã«å€§éã®ã³ãŒããæžãããšãã§ããŸãã ãã¡ãããå®è¡æãšã©ãŒã¯ãããŸãããPHPã®åŸã¯æ°é®®ãªç©ºæ°ã§ãããåç¥ã®ããã«ãç§ã¯èªåã§ééããç¯ããŸãããããšã©ãŒã¯æããã§ã¯ãããŸããã
Golangã§ã³ãŒããç·šæãããšããã¹ãŠãç°¡åã«ãªããŸãããããã«ãã£ã¬ã¯ããªããããåæã«åå空éã§ããããŸãã ããã«ãã¹ãŠãä¿ç®¡ããŠãã ãããã ãããŠ...ããã¯åäœããŸãã éçºãšãµããŒãããšãŠãç°¡åãªã®ã§ã幞çŠã®æ¶ã湧ãåºãŸãã æ£çŽã«èšããšããã®ã¢ãããŒãã§ãããžã§ã¯ããã©ãã ã倧ããããããšãã§ãããããããŸããã ããã€ãã®å€§ããªã©ã€ãã©ãªã®ãªããžããªã調ã¹ãŸãã-æ£æ°ã«èŠããŸããããµããŒãã«ã€ããŠè©±ãããšã¯ã§ããŸããã 䞻芳çã«ã¯ãPHPã§åããµã€ãºã®ã³ãŒãããŒã¹ãç¶æããã®ã¯Goãããå°é£ã§ãã
å ¬å¹³ã«èšããšãé åïŒã¹ã©ã€ã¹ïŒã䜿çšãã䟿å©ã§æçœãªäœæ¥ã¯ãGoã«ã€ããŠã§ã¯ãããŸããã
//... s.KeyBoard = [][]string{} s.KeyBoard = append(s.KeyBoard, []string{}) s.KeyBoard[0] = append(s.KeyBoard[0], s.text.GetAction(locale, "view-prev")) //...
Golangã®èŠ³ç¹ããã¯ããã¹ãŠãè«ççã«èŠããŸããã人éã®èŠ³ç¹ããã¯å°ãå¥åŠã§ãã ãã®ãããã¯ã«ã€ããŠã¯ã ããã§è©³ãã説æããŸã ã
ãŸããGolangã§ã®äžŠåäœæ¥ã«ã¯ãŽã©ã³ïŒã¹ã¬ããïŒã䜿çšãããŸãããPHPã§ã¯ãã©ãŒã¯ïŒããã»ã¹ïŒã䜿çšããã®ãäžè¬çã§ãã ç§ã®ãããžã§ã¯ãã«ã¯ãŽã«ãŒãã³ãé©çšã§ããå Žæã¯å€ããããŸããã ãã ãããããã䜿çšãããŠããå Žåã¯ãéåžžã«è«ççã§ã·ã³ãã«ã«èŠãããããåå²ç¹ã«æ»ãæ°ãããŸããã ãã©ãŒã¯ã¯ç¬ç«ããããã»ã¹ã§ãããããéåžžããµãŒãããŒãã£ïŒRedisãŸãã¯MemcacheïŒã䜿çšããŠçžäºã«éä¿¡ããŸãã Golangã®åæ§ã®åé¡ã¯ããã£ãã«ã®å©ããåããŠè§£æ±ºãããŸã-ç®±ããåºããŠã¢ã¯ã»ã¹ã§ããèšèªã®äžéšã§ãã èããŠã¿ãŠãã ããïŒ ããã«äœ¿ãã䞊åäœæ¥ãããã«ã¯åæã®ãµããŒãã ç§ã¯ããã倢èŠãŠãããŸããã§ããã çŸä»£ã®ããã¯ãšã³ãéçºã«ããã䞊åäœæ¥ã®ã¿ã¹ã¯ã¯äžè¬çã§ãããããPHPã«ããŸãå€ããèŠæ±ãããšã¯æããªãã ãŸããGolangã¯äººé¡ã®ãã¹ãŠã®åé¡ã®äžèœè¬ã§ãããšã¯èšããããããŸããããPHPã§éçºããçµéšã®åŸãGoã§åæ§ã®åé¡ã解決ããããšã¯ãçµæ以å€ã«åã³ã§ããããŸãã
2. Alexander.NeedInfoïŒïŒ
ããæç¹ã§ããããã€ã¹ã¯ããæ ç»æ å ±ãååŸããããã«äœ¿çšããŠããAPIã¯çµäºããŸããã
ãããŠãã©ããããæ°žé ã«ã
Kinopoiskç¬èªã®ããŒãµãŒãäœæããããšã決å®ãããŸããïŒKinopoiskããŒã ã®ã¡ã³ããŒã¯ãã¹ãªãããæããªãã§ããããªãã¯APIãäœæããããšããå§ãããŸãïŒã
v1-ããŒã³ããŒããŒ
æåã®å®è£ ã¯åçŽã§é¡ã倧ããã£ã-åäžã®PHPã¹ã¯ãªããããããžã§ã¯ãã«èœã¡çããŸããããã®ã¹ã¯ãªããã«ã¢ã¯ã»ã¹ãããšããã¥ãŒããã©ã³ãã ãããã·ãµãŒããŒã®ã¢ãã¬ã¹ãååŸãããããçµãŠæ ç»ã®ããã«Kinopoiskã«ç§»åããŸããã 解æèªäœã¯PHPã§ãè¡ãããŸããã å€ç¬ãªããŒããŒã¯ã¯ãããŒã䜿çšããªãã£ãããããããã€ã¹ã¯ã¯1åã®ãªã¯ãšã¹ãã§ãã¹ãŠã®ã¢ãã¬ã¹ãçŠæ¢ããŸããïŒãã£ããã£ã衚瀺ãå§ããŸããïŒãããã¹ãŠã®ãããã·ãµãŒããŒãé«éã§ã¯ãããŸããã§ããã
Cookieã®ãµããŒããå®è£ ããæåŸã«å¯ŸåŠããããã§ãã ãã ããCookieããµããŒãããŠããŠããKinopoiskã¯ãã©ãŠã¶ã§è¡šç€ºãããããé »ç¹ã«ãã£ããã£ã衚瀺ããŸãã ãããã¯ã©ã€ã¢ã³ãã§ã®js-codeå®è¡ã®ãããªåãããå§ããŠããããšã«æ°ã¥ããã®ã§ãKinopoiskã®è§£æããã®ä¿è·ã詳现ã«èª¿æ»ããªãããšã«ããŸããã
v2-ãã«ã¯ã©ã€ã¢ã³ã
ããŒãµãŒã®æ¬¡ã®ããŒãžã§ã³ã¯Goã®WebãµãŒããŒã§ãGETèŠæ±ã§å¿ èŠãªãã©ã¡ãŒã¿ãŒãšéä¿¡ãããã ãŒããŒIDã䜿çšããŠPhantomJSãèµ·åããŸãã ããŸããããŸããã ãããã·ãµãŒããŒã¯äžèŠã«ãªããIPãããããã€ã¹ã¯ã«çŽæ¥è¡ããŸããã ã»ãã·ã§ã³ãµããŒãããã«ãã©ãŠã¶ããããŠäžè¬çã«ããã¹ãŠã䟿å©ã§ããã ããããããã¯éåžžã«é ãã£ãã PhantomJSã¯ãå¿ èŠãªãã¹ãŠã®JSã³ãŒããããŒãããŠå®è¡ããããã«ããã¹ãŠã®éçããŒã¿ãæ£çŽã«åŸ ã¡ãŸããã é ããšããäºå®ã«å ããŠããªãœãŒã¹ã®ç¹ã§éåžžã«é«äŸ¡ã§ããã 1ããŒãžã®è§£æã«ã¯100ã150 MBã®RAMãå¿ èŠã§ããã ãã®ããŒãžã§ã³ã®é ãæãããçç±ã¯ãPhantomJSã®äžå®å®ããšãã®äžå®å®ãªåäœã§ã-ããšãã°ããã®ããã»ã¹ã¯åžžã«çµäºãããå®è¡äžã®ããã»ã¹ã«ãã³ã°ãããŸãŸã§ãã¡ã¢ãªã解æŸããŸããã§ããã PhantomJSã®ããŸããŸãªããŒãžã§ã³ãè©Šããèµ·åãéå§ããWebãµãŒããŒã䜿çšããŠèåŸã®ããã»ã¹ãçµäºããããšããŸããããçµæã¯åžžã«åãã§ãããã¯ããåäœããŸããããã¡ãã䟿å©ã§ããã貪欲ã§äžå®å®ã§ãã
v99
Kinopoiskã解æããããã®èæ¯ãæ¢ãéçšã§ãç§ãäœæããããŸããŸãªããŒãµãŒãšãã®ä¿®æ£ã®ããŒãžã§ã³ã®æ°ãææ¡ã§ããŸããã§ããã ãã®çµæã次ã®ããŒãžã§ã³ã99çªç®ã«åŒã³åºããŸããã 99çªç®ã®ããŒãžã§ã³ã¯PHPã§äœæãããŸããã ç§ã¯GuzzleïŒPHPçšã®HTTPã¯ã©ã€ã¢ã³ãïŒã䜿çšããã»ãã·ã§ã³ããµããŒããããŠãŒã¶ãŒã®ãã©ãŠã¶ãŒã®åäœãšå¯èœãªéãé¡äŒŒããããã«ããŸããã JSã®ãµããŒããæåŠããŸããã CAPTCHAããã¡ãã衚瀺ãããŸãããããŒãµãŒã®æåã®ããŒãžã§ã³ãããã¯ããã«å°ãªããååãšããŠããã®ãªãã·ã§ã³ã¯å¿«é©ãšåŒã°ããŸãã ãã®ããŒãžã§ã³ã§ã¯ãåæ¢ããŸããã
ãŸããç§ã¯Kinopoiskã®ãªã¯ãšã¹ãã§ãã®APIãžã®ã¢ã¯ã»ã¹ãæäŸã§ããããšãç¥ã£ãŠããŸããããã®ãªãã·ã§ã³ãèæ ®ããŸããã§ããïŒã¢ã¯ã»ã¹ããã£ããšããŠãããã€ã§ãã¢ã¯ã»ã¹ã奪ãããå¯èœæ§ããããããæœåšçãªé害ãã€ã³ãã«ãªãå¯èœæ§ããããŸãã
3. Video.PublishïŒïŒ
Kinopoiskãšã®æŠäºã®åŸãç§ã¯ãŠãŒã¶ãŒã«ãããªãžã®ãªã³ã¯ãæäŸããæºåãã§ããŠããããããåçããå Žæããªãã£ããšããç¶æ³ã«ãããŸããïŒTelegram Bot APIã¯ãªã³ã¯ã§ãããªã衚瀺ãã䟿å©ãªæ©èœãæäŸããŸãããããã¡ã€ã³ãç»é²ããããŒãµãŒã§ããã以å€ã®ãã®ããã¹ãããŸããããŠãç§ã¯çµ¶å¯Ÿã«åç·ã®éçºã«é¢äžããããããŸããã§ããã
ã©ãããïŒ
ãããªãã©ããã«å ¬éããŸãã å°ãèããåŸãç§ã¯é»ä¿¡ããã©ãããã«å®å šã«åæ Œã§ãããšæ±ºããŸããã Telegramããèšäºãå ¬éããããã«äºå®äžäœ¿çšãããŠãããµã€ãã§ããïŒ å¿ èŠãªãã®ïŒ 1ã€ã®åé¡-åç §ã«ããåç»ã®æçš¿ã¯ã§ããŸããïŒYouTubeãŸãã¯Vimeoãé€ãïŒã
ãããŠèŠãã°ïŒ
ããŒãžäžã§ãããã¯ãã©ãã ãç°¡åãã€åçã«äœæãããããèŠãŠããã¿ã³ã1ã€æŒãã ãã§èšäºãå ¬éããããšãæããçåã«æã人ãããŸãã ç¹ã«ãã³ã³ãã³ããå ¬éããå Žæãæ¢ããŠããå Žåã 調ã¹ãããšã«ããŸããã
ãããŠãç§ã¯äœãèŠãŸãããïŒ
[{ "tag": "p", "children": ["Story"] }, { "tag": "p", "children": [{ "tag": "br" } ] }, { "tag": "figure", "children": [{ "tag": "div", "attrs": { "class": "figure_wrapper" }, "children": [{ "tag": "img", "attrs": { "src": "/file/a2e8087fbc53679c14fa1.jpg" } } ] }, { "tag": "figcaption", "children": ["Pff"] } ] }, { "tag": "p", "children": [{ "tag": "br" } ] } ]
POSTåŸã®ãªã¯ãšã¹ãã«ã¯JSONãå«ãŸããŠããŸãããããã¯HTMLããŒã¯ã¢ããã«çãããããšã«äŒŒãŠããŸãã ãããŠãç§ãã¡ãæã£ãŠããæ§é ã«åŸã£ãŠããããªã¿ã°ãè¿œå ããŠã¿ãŸããããïŒ ãã å°ãã®å¿èãšãããååŸ...
æ§é
[{ "tag": "p", "children": ["Story"] }, { "tag": "p", "children": [{ "tag": "br" } ] }, { "tag": "figure", "children": [{ "tag": "div", "attrs": { "class": "figure_wrapper" }, "children": [{ "tag": "img", "attrs": { "src": "/file/a2e8087fbc53679c14fa1.jpg" } } ] }, { "tag": "figcaption", "children": ["Pff"] } ] }, { "tag": "p", "children": [{ "tag": "video", "attrs": { "src": "https://www.w3schools.com/html/mov_bbb.mp4" } } ] } ]
äžèšã®æ§é ã䜿çšããŠç·šéã®ããã«POSTãªã¯ãšã¹ããå®è¡ãããšã åç §ã«ãã£ãŠä»»æã®ãããªããããªã±ãŒã·ã§ã³ã«è¿œå ãããŸã ã å¿ èŠãªãã®ã
ãããããªãã£ã
ãã¹ãŠãæ©èœããåé¡ã¯ãããŸããã åé¡ã¯ãã»ãšãã©ã®å±æ§ããµããŒããããŠããªãããšã§ããã€ãŸããåå¹ããããªã®ãã¹ã¿ãŒãªã©ãå¿ããããšãã§ããŸãã ã€ãŸãããããããšããäœãããã«ããã®ãããšããã«ããŽãªãã解決çãçãŸããŸããã èãçŽãããšãªãããã¬ãŒã€ãŒãæ§æã§ããããã«ããããã«XSSã䜿çšããããšã«ããŸããã ããããããã®å Žæã®ã©ããã§éåžžã®éçºã¯çµäºããŸãããæ€éããå Žæã¯ãããŸããã§ããããããªã®å ¬éãæŽçããå¿ èŠããããŸããã ãµãŒãããŒãã£ã®ã³ãŒããããŒãžã«å°å ¥ããããã®ããŸããŸãªãªãã·ã§ã³ãè©ŠããŠã¿ãŸããããç»åã䜿çšããŠãããã¹ãŠãç¡é§ã«ãªããTelegraphã¯è±éçã«çãæ®ããŸããã ããããç§ã¯æ å ±ã»ãã¥ãªãã£ã®åéã®å°é家ã§ã¯ãããŸããã ãããããã£ãšæéãè²»ãããããXSS for Telegraphã®åäœããŒãžã§ã³ãèŠã€ããŠããããæä»çã«ãã¬ãŒã€ãŒã®ã«ã¹ã¿ãã€ãºã«äœ¿çšããã§ãããããç§ã¯ãã®ãã³ãã£ãŒãèŸããŸããã ã³ã³ãã³ããå ¬éããããã«ããã«ããã€ãã®ãµã€ããè©ŠããŸããããã©ãã§ãäœããæ¬ èœããŠããããäœããæ©èœããŸããã§ããã ãããã£ãŠãç§ã¯ãŸã ç§ã®åŽã«ãããªãã¬ãŒã€ãŒãå®è£ ããŸãã...
ãã ããããã¯ãŸã£ããå¥ã®è©±ã§ãã
PS Telegraphã®éçºè ããã®èšäºãèªãã§ããå ŽåïŒãã®ãããªæ©èœãå©çšå¯èœã§ãããããã€ã³ã¿ãŒãã§ã€ã¹ãåç §ããŠãããªã®å ¬éãè¿œå ããŠãã ããã