{"id":572,"date":"2022-02-08T19:55:55","date_gmt":"2022-02-08T16:55:55","guid":{"rendered":"http:\/\/atonko.ru\/?p=572"},"modified":"2022-03-18T17:35:13","modified_gmt":"2022-03-18T14:35:13","slug":"%d1%81%d0%b0%d0%b9%d1%82-%d0%bd%d0%b0-golang-%d0%b0%d0%b2%d1%82%d0%be%d1%80%d0%b8%d0%b7%d0%b0%d1%86%d0%b8%d1%8f-%d1%87%d0%b0%d1%81%d1%82%d1%8c-1","status":"publish","type":"post","link":"https:\/\/alextonkonogov.ru\/?p=572","title":{"rendered":"\u0421\u0430\u0439\u0442 \u043d\u0430 Golang. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f. \u0427\u0430\u0441\u0442\u044c 1"},"content":{"rendered":"\n<p>\u041f\u043e \u043f\u0440\u043e\u0441\u044c\u0431\u0430\u043c \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 (\u0430 \u043e\u043d\u0438 \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c :D), \u044f \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0441\u043e\u0437\u0440\u0435\u043b \u0432\u044b\u0434\u0430\u0442\u044c \u0432\u0430\u043c \u043f\u0440\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435. \u042d\u0442\u0430 \u0442\u0435\u043c\u0430, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b. \u041c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0438 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0431\u0443\u0434\u0435\u043c \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041d\u0430\u0441 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0441 \u0432\u0430\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0437\u043d\u0430\u043d\u0438\u044f \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0443\u0440\u043e\u043a\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u0443\u044e \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0446\u0438\u0442\u0430\u0442\u043a\u0443 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/li><li>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043d\u0430\u0447\u043d\u0435\u043c \u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u0441\u0430\u0439\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c (\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f).<\/li><li>\u0412 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0440\u0430\u043d\u0435\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u043b\u043e\u0433\u0438 \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 (\u043a\u0435\u0448).<\/li><li>\u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c (\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f).<\/li><\/ul>\n\n\n\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0411\u0414 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 PostgreSQL (\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0448\u0430\u0433 \u0441 \u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439). \u041f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0442\u0430\u043c \u043e\u0434\u043d\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">create table if not exists motivations (\n\tid      bigint primary key generated always as identity,\n\tcontent varchar(999) not null,\n\tauthor \tvarchar(999) not null\n);\ninsert into motivations (content, author) VALUES\n\t('\u0410 \u0435\u0441\u043b\u0438 \u0442\u044b \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d \u0432 \u0441\u0435\u0431\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u0412\u0435\u0434\u044c \u0435\u0441\u043b\u0438 \u0442\u044b \u0432 \u0441\u0435\u0431\u044f \u043d\u0435 \u0432\u0435\u0440\u0438\u0448\u044c, \u043a\u0442\u043e \u0436\u0435 \u043f\u043e\u0432\u0435\u0440\u0438\u0442?', '\u041a\u0442\u043e-\u0442\u043e \u0443\u043c\u043d\u044b\u0439'),\n\t('\u0411\u0435\u0437 \u0438\u0434\u0435\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u0432\u0435\u043b\u0438\u043a\u043e\u0433\u043e! \u0411\u0435\u0437 \u0432\u0435\u043b\u0438\u043a\u043e\u0433\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e\u0433\u043e.', '\u0413\u044e\u0441\u0442\u0430\u0432 \u0424\u043b\u043e\u0431\u0435\u0440'),\n\t('\u0411\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0443\u0447\u0438\u0448\u044c\u0441\u044f \u0432 \u0442\u0440\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u2014 \u0434\u043e 7 \u043b\u0435\u0442, \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u043d\u0433\u0430\u0445, \u0438 \u043a\u043e\u0433\u0434\u0430 \u0436\u0438\u0437\u043d\u044c \u0437\u0430\u0433\u043d\u0430\u043b\u0430 \u0442\u0435\u0431\u044f \u0432 \u0443\u0433\u043e\u043b.', '\u0421\u0442\u0438\u0432\u0435\u043d \u041a\u043e\u0432\u0438'),\n\t('\u0412 \u0432\u0430\u0448\u0435\u043c \u043f\u043e\u0434\u0441\u043e\u0437\u043d\u0430\u043d\u0438\u0438 \u0441\u043a\u0440\u044b\u0442\u0430 \u0441\u0438\u043b\u0430, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u0438\u0440.', '\u0423\u0438\u043b\u044c\u044f\u043c \u0414\u0436\u0435\u0439\u043c\u0441'),\n\t('\u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u043d\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u00ab\u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u00bb.', '\u041d\u0430\u043f\u043e\u043b\u0435\u043e\u043d \u0411\u043e\u043d\u0430\u043f\u0430\u0440\u0442'),\n\t('\u0412\u0430\u0436\u043d\u043e \u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043b\u0430\u043d\u0442 \u043d\u0430\u043c \u0434\u0430\u0451\u0442\u0441\u044f \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u2013 \u0438 \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u0446\u0435\u043d\u043e\u0439 \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0447\u0435\u0433\u043e-\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.', '\u041c\u0430\u0440\u0438 \u041a\u044e\u0440\u0438'),\n\t('\u0412\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e, \u043d\u0435 \u0442\u0440\u0430\u0442\u044c\u0442\u0435 \u0435\u0433\u043e, \u0436\u0438\u0432\u044f \u0447\u0443\u0436\u043e\u0439 \u0436\u0438\u0437\u043d\u044c\u044e', '\u0421\u0442\u0438\u0432 \u0414\u0436\u043e\u0431\u0441'),\n\t('\u0412\u0435\u043b\u0438\u043a\u0438 \u0442\u0435, \u043a\u0442\u043e \u0432\u0438\u0434\u0438\u0442, \u0447\u0442\u043e \u043c\u0438\u0440\u043e\u043c \u043f\u0440\u0430\u0432\u044f\u0442 \u043c\u044b\u0441\u043b\u0438.', '\u0420\u0430\u043b\u044c\u0444 \u042d\u043c\u0435\u0440\u0441\u043e\u043d'),\n\t('\u0412\u0435\u043b\u0438\u043a\u0438\u0435 \u0434\u0443\u0448\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0432\u043e\u043b\u0435\u0439, \u0441\u043b\u0430\u0431\u044b\u0435 \u0436\u0435 \u0438\u043c\u0435\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044f.', '\u041a\u0438\u0442\u0430\u0439\u0441\u043a\u0430\u044f \u043f\u043e\u0441\u043b\u043e\u0432\u0438\u0446\u0430'),\n\t('\u0412\u0435\u043b\u0438\u043a\u0438\u0435 \u0443\u043c\u044b \u0441\u0442\u0430\u0432\u044f\u0442 \u043f\u0435\u0440\u0435\u0434 \u0441\u043e\u0431\u043e\u0439 \u0446\u0435\u043b\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043b\u044e\u0434\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0441\u0432\u043e\u0438\u043c \u0436\u0435\u043b\u0430\u043d\u0438\u044f\u043c.', '\u0412\u0430\u0448\u0438\u043d\u0433\u0442\u043e\u043d\u0433 \u0418\u0440\u0432\u0438\u043d\u0433'),\n\t('\u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0442\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0440\u043e\u0437\u0430 \u0438\u043c\u0435\u0435\u0442 \u0448\u0438\u043f\u044b, \u044f \u0440\u0430\u0434\u0443\u044e\u0441\u044c \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u0440\u0435\u0434\u0438 \u0448\u0438\u043f\u043e\u0432 \u0440\u0430\u0441\u0442\u0435\u0442 \u0440\u043e\u0437\u0430.', '\u0416\u043e\u0437\u0435\u0444 \u0416\u0443\u0431\u0435\u0440'),\n\t('\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0435 \u0434\u0435\u043b\u0430\u0439 \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u0435\u0437 \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u0438 \u0446\u0435\u043b\u0438. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043d\u0435 \u0434\u0435\u043b\u0430\u0439 \u043d\u0438\u0447\u0435\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u043d\u0435 \u043a\u043b\u043e\u043d\u0438\u043b\u043e\u0441\u044c \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u0443 \u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430.', '\u041c\u0430\u0440\u043a \u0410\u0432\u0440\u0435\u043b\u0438\u0439'),\n\t('\u0412\u043e\u0437\u043d\u0438\u043a\u0448\u0438\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0437\u043e\u0442\u043b\u0430\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0410 \u0442\u043e \u0432\u0441\u0435 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442. \u0417\u0430\u0445\u043e\u0442\u0435\u043b \u2013 \u0441\u0434\u0435\u043b\u0430\u043b, \u0447\u0435\u0433\u043e \u0442\u044f\u043d\u0443\u0442\u044c, \u0436\u0438\u0437\u043d\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0430. \u0417\u0434\u0435\u0441\u044c \u0438 \u0441\u0435\u0439\u0447\u0430\u0441!', '\u041c\u0438\u0445\u0430\u0438\u043b \u0412\u0435\u043b\u043b\u0435\u0440'),\n\t('\u0412\u043e\u0438\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442, \u0430 \u0433\u043b\u0443\u043f\u0435\u0446 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0443\u0435\u0442.', '\u041c\u0438\u0440\u043d\u044b\u0439 \u0432\u043e\u0438\u043d'),\n\t('\u0412\u043e\u0438\u043d \u043d\u0435 \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043b\u044e\u0431\u0438\u0442. \u041e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043b\u044e\u0431\u043e\u0432\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442.', '\u041c\u0438\u0440\u043d\u044b\u0439 \u0432\u043e\u0438\u043d'),\n\t('\u0412\u043e\u043f\u0440\u043e\u0441 \u043d\u0435 \u0432 \u0442\u043e\u043c, \u043a\u0442\u043e \u043c\u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442, \u0430 \u0432 \u0442\u043e\u043c, \u043a\u0442\u043e \u0441\u043c\u043e\u0436\u0435\u0442 \u043c\u043d\u0435 \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c.', '\u0410\u0439\u043d \u0420\u044d\u043d\u0434'),\n\t('\u0412\u0441\u0435 \u0434\u0435\u043b\u043e \u0432 \u043c\u044b\u0441\u043b\u044f\u0445. \u041c\u044b\u0441\u043b\u044c \u2014 \u043d\u0430\u0447\u0430\u043b\u043e \u0432\u0441\u0435\u0433\u043e. \u0418 \u043c\u044b\u0441\u043b\u044f\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c. \u0418 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0434\u0435\u043b\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f: \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 \u043c\u044b\u0441\u043b\u044f\u043c\u0438.', '\u041b\u0435\u0432 \u0422\u043e\u043b\u0441\u0442\u043e\u0439'),\n\t('\u0412\u0441\u0435 \u0434\u0435\u0442\u0438 - \u0445\u0443\u0434\u043e\u0436\u043d\u0438\u043a\u0438. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0445\u0443\u0434\u043e\u0436\u043d\u0438\u043a\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0442\u044b \u0432\u044b\u0440\u043e\u0441.', '\u041f\u0430\u0431\u043b\u043e \u041f\u0438\u043a\u0430\u0441\u0441\u043e'),\n\t('\u0412\u0441\u0435 \u043f\u043e\u0431\u0435\u0434\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u0431\u0435\u0434\u044b \u043d\u0430\u0434 \u0441\u0430\u043c\u0438\u043c \u0441\u043e\u0431\u043e\u0439.', '\u041b\u0435\u043e\u043d\u0438\u0434 \u041b\u0435\u043e\u043d\u043e\u0432'),\n\t('\u0412\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0439\u0442\u0435 \u0441\u0430\u043c\u044b\u0439 \u0442\u0440\u0443\u0434\u043d\u044b\u0439 \u043f\u0443\u0442\u044c - \u043d\u0430 \u043d\u0435\u043c \u0432\u044b \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u0435 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043e\u0432.', '\u0428\u0430\u0440\u043b\u044c \u0434\u0435 \u0413\u043e\u043b\u043b\u044c');<\/code><\/pre>\n\n\n\n<p>\u0418 \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"914\" src=\"https:\/\/atonko.ru\/wp-content\/uploads\/2022\/02\/db-1-1024x914.png\" alt=\"\" class=\"wp-image-577\" srcset=\"https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/db-1-1024x914.png 1024w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/db-1-300x268.png 300w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/db-1-768x686.png 768w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/db-1.png 1364w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435!<\/p>\n\n\n\n<p>\u0412 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 internal \u0438 \u0432 \u043d\u0435\u0439 repository. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0439\u043b storage.go \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"go\" class=\"language-go\">package repository\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"net\"\n\t\"time\"\n\t\"github.com\/jackc\/pgx\/v4\/pgxpool\"\n)\n\nfunc InitDBConn(ctx context.Context) (dbpool *pgxpool.Pool, err error) {\n\turl := \"postgres:\/\/postgres:password@localhost:5432\/postgres?sslmode=disable\"\n\tcfg, err := pgxpool.ParseConfig(url)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"failed to parse pg config: %w\", err)\n\t\treturn\n\t}\n\tcfg.MaxConns = int32(5)\n\tcfg.MinConns = int32(1)\n\tcfg.HealthCheckPeriod = 1 * time.Minute\n\tcfg.MaxConnLifetime = 24 * time.Hour\n\tcfg.MaxConnIdleTime = 30 * time.Minute\n\tcfg.ConnConfig.ConnectTimeout = 1 * time.Second\n\tcfg.ConnConfig.DialFunc = (&amp;net.Dialer{\n\t\tKeepAlive: cfg.HealthCheckPeriod,\n\t\tTimeout:   cfg.ConnConfig.ConnectTimeout,\n\t}).DialContext\n\tdbpool, err = pgxpool.ConnectConfig(ctx, cfg)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"failed to connect config: %w\", err)\n\t\treturn\n\t}\n\treturn\n}<\/code><\/pre>\n\n\n\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n\n\n\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0436\u0435 \u043f\u0430\u043f\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0435 \u0434\u0432\u0430 \u0444\u0430\u0439\u043b\u0430: repository.go \u0438 motivation.go<\/p>\n\n\n\n<p>\u041a\u043e\u0434 \u0434\u043b\u044f repository.go<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"go\" class=\"language-go\">package repository\n\nimport (\n\t\"github.com\/jackc\/pgx\/v4\/pgxpool\"\n)\n\ntype Repository struct {\n\tpool *pgxpool.Pool\n}\n\nfunc NewRepository(pool *pgxpool.Pool) *Repository {\n\treturn &amp;Repository{pool: pool}\n}<\/code><\/pre>\n\n\n\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u0443\u043b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0441 \u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n\n\n\n<p>\u041a\u043e\u0434 \u0434\u043b\u044f motivation.go<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"go\" class=\"language-go\">package repository\n\nimport (\n\t\"context\"\n\t\"fmt\"\n)\n\ntype Motivation struct {\n\tId      int    `db:\"id\"`\n\tContent string `db:\"content\"`\n\tAuthor  string `db:\"author\"`\n}\n\nfunc (r *Repository) GetRandomMotivation(ctx context.Context) (m Motivation, err error) {\n\trow := r.pool.QueryRow(ctx, `select * from motivations order by random() limit 1`)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"failed to query data: %w\", err)\n\t\treturn\n\t}\n\terr = row.Scan(&amp;m.Id, &amp;m.Content, &amp;m.Author)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"failed to query data: %w\", err)\n\t\treturn\n\t}\n\treturn\n}<\/code><\/pre>\n\n\n\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 \u0431\u0430\u0437\u044b \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u043e\u0439 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u0438.<\/p>\n\n\n\n<p>\u0423\u0440\u043e\u0432\u043d\u0435\u043c \u0432\u044b\u0448\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 application \u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0435 application.go,  \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043e\u043f\u0438\u0448\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"go\" class=\"language-go\">package application\n\nimport (\n\t\"context\"\n\t\"html\/template\"\n\t\"net\/http\"\n\t\"path\/filepath\"\n\t\"github.com\/jackc\/pgx\/v4\/pgxpool\"\n\t\"github.com\/julienschmidt\/httprouter\"\n\t\"github.com\/alextonkonogov\/atonko-authorization\/internal\/repository\"\n)\n\ntype app struct {\n\tctx    context.Context\n\trepo   *repository.Repository\n}\n\nfunc (a app) Routes(r *httprouter.Router) {\n\tr.ServeFiles(\"\/public\/*filepath\", http.Dir(\"public\"))\n\tr.GET(\"\/\", a.StartPage)\n}\n\nfunc (a app) StartPage(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {\n\tmotivation, err := a.repo.GetRandomMotivation(a.ctx)\n\tif err != nil {\n\t\thttp.Error(rw, err.Error(), http.StatusBadRequest)\n\t\treturn\n\t}\n\tlp := filepath.Join(\"public\", \"html\", \"motivation.html\")\n\ttmpl, err := template.ParseFiles(lp)\n\tif err != nil {\n\t\thttp.Error(rw, err.Error(), http.StatusBadRequest)\n\t\treturn\n\t}\n\terr = tmpl.ExecuteTemplate(rw, \"motivation\", motivation)\n\tif err != nil {\n\t\thttp.Error(rw, err.Error(), http.StatusBadRequest)\n\t\treturn\n\t}\n}\n\nfunc NewApp(ctx context.Context, dbpool *pgxpool.Pool) *app {\n\treturn &amp;app{ctx, repository.NewRepository(dbpool)}\n}<\/code><\/pre>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0442\u043e \u0432 application.go \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 StartPage \u043c\u044b \u0441\u0441\u044b\u043b\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0444\u0430\u0439\u043b\u0438\u043a &#8220;motivation.html&#8221;, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u043f\u0443\u0442\u0438 &#8220;public\/html\/motivation.html&#8221;. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">{{define \"motivation\"}}\n&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n    &lt;meta charset=\"UTF-8\">\n    &lt;title>Motivations&lt;\/title>\n&lt;\/head>\n&lt;body>\n    &lt;div>\n        \"{{.Content}}\" - {{.Author}}\n    &lt;\/div>\n&lt;\/body>\n&lt;\/html>\n{{end}}<\/code><\/pre>\n\n\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0432 main.go:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"go\" class=\"language-go\">package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"net\/http\"\n\t\"github.com\/julienschmidt\/httprouter\"\n\t\"github.com\/alextonkonogov\/atonko-authorization\/internal\/application\"\n\t\"github.com\/alextonkonogov\/atonko-authorization\/internal\/repository\"\n)\n\nfunc main() {\n\tctx := context.Background()\n\tdbpool, err := repository.InitDBConn(ctx)\n\tif err != nil {\n\t\tlog.Fatalf(\"%w failed to init DB connection\", err)\n\t}\n\tdefer dbpool.Close()\n\ta := application.NewApp(ctx, dbpool)\n\tr := httprouter.New()\n\ta.Routes(r)\n\tsrv := &amp;http.Server{Addr: \"0.0.0.0:8080\", Handler: r}\n\tfmt.Println(\"It is alive! Try http:\/\/localhost:8080\")\n\tsrv.ListenAndServe()\n}<\/code><\/pre>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 go run main.go, \u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"204\" src=\"https:\/\/atonko.ru\/wp-content\/uploads\/2022\/02\/image-3-1024x204.png\" alt=\"\" class=\"wp-image-595\" srcset=\"https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-3-1024x204.png 1024w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-3-300x60.png 300w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-3-768x153.png 768w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-3.png 1026w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u043c \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u0443\u044e \u0446\u0438\u0442\u0430\u0442\u043a\u0443:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/atonko.ru\/wp-content\/uploads\/2022\/02\/image-1024x300.png\" alt=\"\" class=\"wp-image-582\" srcset=\"https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-1024x300.png 1024w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-300x88.png 300w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-768x225.png 768w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image.png 1473w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u0422\u0435\u043a\u0443\u0449\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"673\" src=\"https:\/\/atonko.ru\/wp-content\/uploads\/2022\/02\/image-4.png\" alt=\"\" class=\"wp-image-596\" srcset=\"https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-4.png 865w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-4-300x233.png 300w, https:\/\/alextonkonogov.ru\/wp-content\/uploads\/2022\/02\/image-4-768x598.png 768w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p>\u0421\u043e\u0441\u0442\u0430\u0432 go.mod:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"go\" class=\"language-go\">module github.com\/alextonkonogov\/atonko-authorization\ngo 1.15\nrequire (\n\tgithub.com\/jackc\/pgx\/v4 v4.15.0\n\tgithub.com\/julienschmidt\/httprouter v1.3.0\n)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Pull request \u0441 \u043a\u043e\u0434\u043e\u043c: <a href=\"https:\/\/github.com\/alextonkonogov\/atonko-authorization\/pull\/1\">https:\/\/github.com\/alextonkonogov\/atonko-authorization\/pull\/1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u043e \u043f\u0440\u043e\u0441\u044c\u0431\u0430\u043c \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 (\u0430 \u043e\u043d\u0438 \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c :D), \u044f \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0441\u043e\u0437\u0440\u0435\u043b \u0432\u044b\u0434\u0430\u0442\u044c \u0432\u0430\u043c \u043f\u0440\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435. \u042d\u0442\u0430 \u0442\u0435\u043c\u0430, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-572","post","type-post","status-publish","format-standard","hentry","category-golang"],"_links":{"self":[{"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=\/wp\/v2\/posts\/572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=572"}],"version-history":[{"count":1,"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=\/wp\/v2\/posts\/572\/revisions"}],"predecessor-version":[{"id":753,"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=\/wp\/v2\/posts\/572\/revisions\/753"}],"wp:attachment":[{"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alextonkonogov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}