åå¿é²
æ¸ããããæ¸ãããã¨ããªãã®ã§ããã¹ã¯ãããã«æ§ãã¦ããã¡ã¢ããã¡ãã«ãä¿åããæå³åãã§æ稿ãã¾ãã
ï¼ï¼æ¹è¡ã®è¡ãéãã空ç½è¡ãåé¤
VS Codeã使ã£ã¦ãã¦ãã³ã¼ãã®æå¾ã®è¡ããã®ç¡é§ãªç©ºç½è¡ãè©°ãã¦ãããè¨å®ã¯ããã©ã«ãã§ã¤ãã¦ãããã¨æãã¾ãããã³ã¼ãã®éä¸ã®ããããæ¹è¡ã®è¡ãéãã空ç½è¡ã¯åé¤ãã¦ããã¾ããã
ããã§ã§ãã対å¦ã¯ãç½®ãæãã§åé¤ããæ¹æ³ã§ãã
æ¤ç´¢ã§æ£è¦è¡¨ç¾ã使ç¨ãã¦ç½®ãæããã¾ãã
空ç½è¡åé¤ã^\nãã§æ¤ç´¢ãã¦ç½®ãæã
æ¹è¡ãåé¤ã\nãã§æ¤ç´¢ãã¦ç½®ãæã
ï¼ï¼flaskã§ä¾åç°å¢ããã°ããï¼åï¼ã¤ã³ã¹ãã¼ã«ãã
ä»®æ³ç°å¢ãããã£ãå ´åãflaskã³ãã³ããflaskãè¦ã¤ããããªããªã£ã¦ãã¾ãå ´åãããã¾ãã
venvã®åæ§ç¯ããããããã®ã¯ããã©ãã§ãã
ã«ã¼ãã«requirements.txtãç¨æãã¦ããã
ä¸èº«ã¯ä»¥ä¸ã®ãããªãããã§ã
flask==3.0.3 python-dotenv==1.0.1 requests==2.32.3
pip installã®-rãªãã·ã§ã³ã§ã¤ã³ã¹ãã¼ã«
pip install -r requirements.txt
ï¼ï¼Pythonããé¢ãã¦ä»ã®è¨èªãããã£ã¦ããã¨ãFlaskã®ã³ãã³ããå¿ãã¦ãã¾ãã¾ãã
flask --app api.index run --debug
flask --app api.index --debug run
ä¸è¨ãªã©ã§ããã°æ£è§£ãªã®ã§ãããããç解ãã¦ããªãã£ããããæãåºããªããééã£ãã³ãã³ããã¿ã¤ããã¦ãã¾ããã
flask --app run api.index --debug
ãããªãããã«ééãã¨ãã¼ã«ã«ãµã¼ãåä½ãã¾ããã
ã¿ã¼ããã«ããflask --helpã§ç¢ºèªã
Usage: flask [OPTIONS] COMMAND [ARGS]...
--appã¯flaskã®ãªãã·ã§ã³
runã¯flaskã®ã³ãã³ã
--debug㯠runã®ãªãã·ã§ã³ï¼flaskã®ãªãã·ã§ã³ã§ãããï¼
ãªã®ã§ãæ£ããç解ãã¦ããã°ééããã¨ã¯ãªãã§ããï¼
ï¼ï¼Goã§ãã¹ãããã»ã©ã®ã³ã¼ãæ¸ãã¦ãã¾ããã
go test ./ãç¸å¯¾ã§ã¢ã¸ã¥ã¼ã«ãæå®ãã¢ã¸ã¥ã¼ã«ã®ã«ã¬ã³ãã§
go testãã¢ã¸ã¥ã¼ã«ã®ã«ã¬ã³ãã§ã¯ããã§ok
go test -vã詳細表示
go test -v -run TestXxxãTestXxxãæå®ãã¦å®è¡ã-vã¯ãªãã¦ããã
go test -v -run "Xxx$"ãXxxã§çµãããã¹ãã®ã¿å®è¡ã-vã¯ãªãã¦ããã
ï¼ï¼è¤æ°ã®main()ã®å¯¾å¿
å¦ç¿ã§ã³ã¼ãã試ãã¦ã¿ããã¨ããªã©ãè¤æ°ã®main()ããããªãã§ã
ãã¡ã¤ã«ã®æåã«ã
// go:build ignore
ã¨ãã¦ããã°ãå®è¡ã¯ã§ããããã«ãªãã¾ãã
èªåã¯è¤æ°è©¦ããããã¦ããã¨ãã¯ãå¥ã®ãã£ã¬ã¯ããªã«å
¥ãã¦ãã¾ãã
ããã§ãªãã¨ãã¨ãã£ã¿ä¸ã§è¦åãªã©ã®è¡¨ç¤ºããããããªãã¾ãããã
å ´åã«ãã£ã¦ã¯å¥ã®ãã£ã¬ã¯ããªã§ã¯é½åããããã®ããï¼
ä»ã®èªåã«ã¯ãããããã¾ããã
è¿æ³
ãã°ããã¯ãã³ãã³ãã©ã¤ã³ãã¼ã«ãä½ãããä¸å¿ã§ãGoè¨èªããã¦ãã¾ããã
ãã¬ã¼ã ã¯ã¼ã¯ã使ã£ã¦ä½ããããã«ã¯ãªãã¾ããããæ¨æºã©ã¤ãã©ãªã®flagã®ã¿ã§ãã»ã¼åæ©è½ã§å®æã¾ã§ä½ãã¾ããã
ä¸æ¦ãå
¬éã¾ã§å®éã«è©¦ãã¾ããããå¦ç¿ã¬ãã«ãªã®ã§ç¾å¨ã¯å
¬éã¯ãã¦ãã¾ããã
ã³ãã³ãã©ã¤ã³ãã¼ã«ãä½æãããã¨ã¯Goå
¥éã®ããå¦ç¿ææã ã¨æãã¾ããã
ä¸é£ã®Goã§ã®éçºã®æ
£ä¾ãå¦ã¹ã¾ãã
ã³ã¼ãã«é¢ãã¦ã¯ãç¹ã«Goããããã¨ããªãããããã¾ãããã
ãã®å¾ãä½ãä½ãã°ããã ãããã¨ãã¢ããã¼ã·ã§ã³ãåãã¾ããã
ãã¤ãFlaskã¯ããããã£ã¦ããã®ã§ãã¾ãPythonã«æ»ã£ã¦ãã¾ãã
ãã¡ããpythonã¨ãããFlaskãããã¬ã¼ã ã¯ã¼ã¯ãããã£ã¦ããæãã§ãããã©ã
ããã°ã©ãã³ã°ï¼ãã¸ã¥ã¢ã«è¡¨ç¾ãªå¶ä½ãã§ããããã«ãªããã¨ãç®æ¨ãªãã§ãããæ°å¦ã®å¾©ç¿ã6å¹´åï¼ããã¾ãããã¾ã ã¾ã é ã¼ã¼ã¼ãã§ãï¼ï¼