{"id":302769,"date":"2020-04-29T21:00:36","date_gmt":"2020-04-29T21:00:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=302769"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=302769","title":{"rendered":"\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 Go. \u0427\u0430\u0441\u0442\u044c 1"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/499732\/\">\u0412\u043e\u0442 \u0443\u0436\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u043c\u0435\u0441\u044f\u0446\u0430 \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u0432\u0430\u043b \u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0437\u0430\u0449\u0438\u0442\u044b \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0433\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0444\u0435\u0440\u0430\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u0430\u00bb. <br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u044f \u043d\u0430\u0447\u0438\u043d\u0430\u043b, \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u043e\u043f\u0438\u0448\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/319\/86b\/9a5\/31986b9a5079081f4eb87335330d119c.jpg\" alt=\"image\"><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0433\u043e\u0434\u0443 \u043d\u0430 \u0445\u0430\u043a\u0430\u0442\u043e\u043d\u0435 \u0426\u0438\u0444\u0440\u043e\u0432\u043e\u0439 \u043f\u0440\u043e\u0440\u044b\u0432 \u043f\u043e\u0434\u043a\u0438\u043d\u0443\u043b\u0438 \u0438\u0434\u0435\u044e, \u0447\u0442\u043e\u0431\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u0446\u0438\u0444\u0440\u043e\u0432\u043e\u0439 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043a\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0435\u0441\u0442\u0440\u043e\u0432, \u0442\u0430\u043a \u0436\u0435 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0431\u044b\u043b \u0432\u044b\u0434\u0430\u043d \u0433\u0440\u0430\u043d\u0442 \u0424\u043e\u043d\u0434\u043e\u043c \u0441\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438\u043d\u043d\u043e\u0432\u0430\u0446\u0438\u044f\u043c (\u043e \u0433\u0440\u0430\u043d\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043c\u043d\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u0434\u043b\u044f \u0442\u0435\u0445 \u043a\u0442\u043e \u0441\u0442\u0430\u0440\u0442\u0430\u043f\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c), \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e-\u043f\u043e\u0440\u044f\u0434\u043a\u0443. <\/p>\n<p>  \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Go, \u0430 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u0438 \u2014 LevelDB.<br \/>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u0441\u0435\u0440\u0432\u0435\u0440 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 TCP \u0438 WebSocket \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u0430, \u0432 \u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0438 \u043a\u043e\u043c\u043c\u0430\u043d\u0434 \u0438\u0437 JavaScript, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440. <\/p>\n<p>  \u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d \u043d\u0443\u0436\u0435\u043d \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0431\u043c\u0435\u043d\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430\u043c\u0438 \u0438 \u0437\u0430\u043a\u0430\u0437\u0447\u0438\u043a\u0430\u043c\u0438, \u043b\u0438\u0431\u043e \u0438 \u0442\u0435\u043c\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043b\u0438\u0446\u0435. \u0414\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u0440\u0443\u0433-\u0434\u0440\u0443\u0433\u0443 \u0442\u0430\u043a\u0438\u0435 \u043d\u0435 \u0441\u043f\u0435\u0448\u0430\u0442. \u041d\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u00ab\u0447\u0435\u043a\u043e\u0432\u0443\u044e \u043a\u043d\u0438\u0436\u043a\u0443\u00bb \u0441\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0440\u0443\u0442\u0438\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0438. \u0411\u0430\u0439\u0442-\u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043a\u0430\u043a \u0438 \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0443 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432\u043e \u0432\u0445\u043e\u0434\u0430\u0445 \u0438 \u0432\u044b\u0445\u043e\u0434\u0430\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 (\u0441\u0430\u043c\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0441\u0438\u0434\u044f\u0442 \u0432 \u0431\u043b\u043e\u043a\u0430\u0445, \u0431\u043b\u043e\u043a\u0438 \u0432 LevelDB \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 GOB). \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0438 \u0441\u0435\u0440\u0432\u0435\u0440 (\u043e\u043d \u0436\u0435 \u043d\u043e\u0434\u0430). <\/p>\n<p>  \u041f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e, \u0432\u0435\u0441\u044c \u0435\u0433\u043e \u0441\u043c\u044b\u0441\u043b \u0432 \u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443-\u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0435\u0436\u0438\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0431\u044b\u0447\u043d\u043e \u0431\u043b\u043e\u043a\u0430 \u0438\u043b\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u0430 \u0435\u0449\u0435 \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u0435\u043c, \u044d\u0442\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u043e\u0434\u0430 \u0437\u043d\u0430\u043b\u0430 \u043a \u043a\u043e\u043c\u0443 \u043e\u043d\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0438 \u043a\u0430\u043a \u0443 \u043d\u0438\u0445 \u0434\u0435\u043b\u0430 (\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u043e\u0434\u044b \u0435\u0449\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u00ab\u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c\u0438\u00bb \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0438\u0445 IP \u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438).<\/p>\n<p>  \u041f\u0430\u043f\u043a\u0438 (\u0434\u0438\u0440\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043a\u0430\u043a \u0438\u0445 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442 Linux) \u0432 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 Go-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0441 Go-\u043a\u043e\u0434\u043e\u043c \u0438\u0437 \u044d\u0442\u043e\u0439 \u0434\u0438\u0440\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0438\u0448\u0443\u0442 package \u0438\u043c\u044f_\u043f\u0430\u043f\u043a\u0438_\u0433\u0434\u0435_\u0441\u0438\u0434\u0438\u0442_\u044d\u0442\u043e\u0442_\u0444\u0430\u0439\u043b. \u0418\u043d\u0430\u0447\u0435 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043a\u043e\u0440\u043c\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043f\u0430\u043a\u0435\u0442. \u041d\u0443 \u044d\u0442\u043e \u0434\u043b\u044f \u0437\u043d\u0430\u044e\u0449\u0438\u0445 \u044d\u0442\u043e\u0442 \u044f\u0437\u044b\u043a \u043d\u0435 \u0441\u0435\u043a\u0440\u0435\u0442. \u0412\u043e\u0442 \u044d\u0442\u0438 \u043f\u0430\u043a\u0435\u0442\u044b: <\/p>\n<ul>\n<li> \u0421\u0435\u0442\u0435\u0432\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 (server, client, protocol)<\/li>\n<li> \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0445\u0440\u0430\u043d\u0438\u043c\u044b\u0445 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (block, transaction)<\/li>\n<li> \u0411\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 (blockchain)<\/li>\n<li> \u041a\u043e\u043d\u0441\u0435\u043d\u0441\u0443\u0441 (consensus)<\/li>\n<li> \u0421\u0442\u0435\u043a\u043e\u0432\u0430\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0448\u0438\u043d\u0430 (xvm)<\/li>\n<li> \u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (crypto, types) \u043f\u043e\u043a\u0430 \u0432\u0441\u0451.<\/li>\n<\/ul>\n<p>  <a href=\"https:\/\/github.com\/Rusldv\/bcstartup\" rel=\"nofollow\">\u0412\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 github<\/a><\/p>\n<p>  \u042d\u0442\u043e \u0443\u0447\u0435\u0431\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0432 \u043d\u0435\u0439 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u0436\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0437\u0430 \u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u0439 \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u0434\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0447\u0442\u043e \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u044f \u0441 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435\u043c \u0443\u0447\u0442\u0443 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u043f\u043e \u043f\u0430\u043a\u0435\u0442\u0430\u043c server \u0438 <i>protocol<\/i>.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 server. <\/p>\n<p>  \u041f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 server \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0440\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 TCP \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 protocol.<\/p>\n<p>  \u041f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u044b: <i>server<\/i>, <i>protocol<\/i>, <i>types<\/i>. \u0412 \u0441\u0430\u043c\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u0435 \u0432 <i>tcp_server.go<\/i> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <i>Serve<\/i>.<\/p>\n<pre><code class=\"go\">type Serve struct { \tPort string \tBufSize int \tST *types.Settings }<\/code><\/pre>\n<p>  \u041e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li> \u0421\u0435\u0442\u0435\u0432\u043e\u0439 \u043f\u043e\u0440\u0442, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/li>\n<li> \u0424\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON<\/li>\n<li> \u0424\u043b\u0430\u0433 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 (\u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u0430)<\/li>\n<\/ul>\n<p>  \u0425\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li> \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 JSON<\/li>\n<li> \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433 \u0440\u0435\u0436\u0438\u043c\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0438: \u0435\u0441\u043b\u0438 \u043e\u043d \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d, \u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d \u043d\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f<\/li>\n<li> \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/li>\n<\/ul>\n<p>  <\/p>\n<h3>Server<\/h3>\n<p>  <\/p>\n<ul>\n<li> \u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442 \u0437\u043f\u0443\u0441\u043a TCP \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c.<\/li>\n<li> \u0412 \u043d\u0435\u043c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 Serve \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u043d\u043e\u043c\u0435\u0440\u0430 \u043f\u043e\u0440\u0442\u0430, \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0443\u0444\u0435\u0440\u0430 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <i>types.Settings<\/i><\/li>\n<li> \u041c\u0435\u0442\u043e\u0434 Run \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 (\u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u0442\u0443, \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 handle \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435)<\/li>\n<li> \u0412 <i>handle<\/i> \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0431\u0443\u0444\u0435\u0440, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 <i>protocol.Choice<\/i><\/li>\n<li> <i>protocol.Choice<\/i> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <i>result<\/i> \u043b\u0438\u0431\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. <i>result<\/i> \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 <i>protocol.Interprete<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <i>intrpr<\/i> \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <i>InterpreteData<\/i>, \u043b\u0438\u0431\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u0431\u043e\u0440\u0430<\/li>\n<li> \u0417\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f switch \u043f\u043e <i>intrpr.Commands[0]<\/i> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e \u0438\u0437: <i>result, inv, error<\/i> \u0438 \u0435\u0441\u0442\u044c \u0441\u0435\u043a\u0446\u0438\u044f <i>default<\/i><\/li>\n<li> \u0412 \u0441\u0435\u043a\u0446\u0438\u0438 <i>result<\/i> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f switch \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e <i>intrpr.Commands[1]<\/i> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <i>bufferlength<\/i> \u0438 <i>version<\/i> (\u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u0435\u0439\u0441\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f)<\/li>\n<\/ul>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438 <i>GetVersion<\/i> \u0438 <i>BufferLength<\/i> \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <i>srvlib.go<\/i> \u043f\u0430\u043a\u0435\u0442\u0430 server. <\/p>\n<pre><code class=\"go\">GetVersion(conn net.Conn, version string)<\/code><\/pre>\n<p>  \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0443\u044e \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 \u0432\u0435\u0440\u0441\u0438\u044e: <\/p>\n<pre><code class=\"go\">conn.Write([]byte(&quot;result:&quot; + version))<\/code><\/pre>\n<p>.<br \/>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f <\/p>\n<pre><code class=\"go\">BufferLength(conn net.Conn, intrpr *protocol.InterpreteData)<\/code><\/pre>\n<p>  \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0431\u043b\u043e\u043a\u0430, \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043b\u0438\u0431\u043e \u0438\u043d\u044b\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li> \u041f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043d\u044f\u0442:\n<pre><code class=\"go\">fmt.Println(&quot;DataType:&quot;, intrpr.Commands[2])<\/code><\/pre>\n<\/li>\n<li> \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <i>intrpr.Body<\/i> \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <i>buf_len<\/i><\/li>\n<li> \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0431\u0443\u0444\u0435\u0440 <i>newbuf<\/i> \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430:\n<pre><code class=\"go\">make([]byte, buf_len)<\/code><\/pre>\n<\/li>\n<li> \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 ok:\n<pre><code class=\"go\">conn.Write([]byte(&quot;result:ok&quot;))<\/code><\/pre>\n<\/li>\n<li> \u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043f\u043e\u043b\u043d\u043e\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430 \u0438\u0437 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430:\n<pre><code class=\"go\">io.ReadFull(conn, newbuf)<\/code><\/pre>\n<p>.<\/li>\n<li> \u0412\u044b\u0432\u043e\u0434\u0438\u0442 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0431\u0443\u0444\u0435\u0440\u0430\n<pre><code class=\"go\">fmt.Println(string(newbuf))<\/code><\/pre>\n<p>  \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0445 \u0431\u0430\u0439\u0442\u043e\u0432 <\/p>\n<pre><code class=\"go\">fmt.Println(&quot;Bytes length:&quot;, n)<\/code><\/pre>\n<\/li>\n<li> \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 ok:\n<pre><code class=\"go\">conn.Write([]byte(&quot;result:ok&quot;))<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>  \u041c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 server \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <i>protocol<\/i>.<\/p>\n<h3>Protocol<\/h3>\n<p>  \u041f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0441\u043b\u0443\u0436\u0438\u0442 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438 \u0441\u0435\u0442\u0435\u0432\u043e\u043c \u043e\u0431\u043c\u0435\u043d\u0435.<\/p>\n<p>  <i>Choice(str string) (string, error)<\/i> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0434\u043b\u044f <i>Interprete<\/i>:<\/p>\n<ul>\n<li> \u0412\u0445\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 head \u0438 body \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <i>ReqParseN2(str)<\/i><\/li>\n<li> head \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0430\u0439\u0441 commands \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ReqParseHead(head)<\/li>\n<li> \u0412 <i>switch(commands[0])<\/i> \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 (<i>cmd, key, address<\/i> \u043b\u0438\u0431\u043e \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0435\u043a\u0446\u0438\u044f <i>default<\/i>)<\/li>\n<li> \u0412 cmd \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f 2 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <i>switch(commands[1]) \u2014 length<\/i> \u0438 <i>getversion<\/i>.<\/li>\n<li> <i>length<\/i> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 <i>commands[2]<\/i> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 <i>datatype<\/i><\/li>\n<li> \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0447\u0442\u043e <i>body<\/i> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\n<pre><code class=\"go\">len(body) &lt; 1<\/code><\/pre>\n<\/li>\n<li> \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043e\u0442\u0432\u0435\u0442:\n<pre><code class=\"go\">&quot;result:bufferlength:&quot; + datatype + &quot;\/&quot; + body<\/code><\/pre>\n<\/li>\n<li> <i>getversion<\/i> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443\n<pre><code class=\"go\">return &quot;result:version\/auto&quot;<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>Interprete<\/h4>\n<p>  \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 InterpreteData \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0439 \u0438\u0437 <i>Choice<\/i> \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <i>InterpreteData<\/i>.<\/p>\n<pre><code class=\"go\">type InterpreteData struct { \tHead string \tCommands []string \tBody string \tIsErr bool \tErrCode int  \tErrMessage string }<\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f <\/p>\n<pre><code class=\"go\">Interprete(str string) (*InterpreteData, error)<\/code><\/pre>\n<p>  \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 <i>result<\/i> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 <i>InterpreteData<\/i>.<\/p>\n<p>  \u0425\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li> \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <i>Choice<\/i> \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442\u0441\u044f head \u0438 body \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <i>ReqParseN2(str)<\/i><\/li>\n<li> head \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <i>ReqParseHead(head)<\/i><\/li>\n<li> \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <i>InterpreteData<\/i> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0433\u043e:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"go\">res := &amp;InterpreteData{ \tHead: head, \tCommands: commands, \tBody: body, } return res, nil<\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 <i>server.go<\/i> \u043f\u0430\u043a\u0435\u0442\u0430 main. <\/p>\n<h3>Client<\/h3>\n<p>  \u041f\u0430\u043a\u0435\u0442 client \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <i>TCPConnect<\/i> \u0438 <i>TCPResponseData<\/i>.<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f <\/p>\n<pre><code class=\"go\">TCPConnect(s *types.Settings, data []byte, payload []byte)<\/code><\/pre>\n<p>  \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li> \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e\n<pre><code class=\"go\">net.Dial(&quot;tcp&quot;, s.Host + &quot;:&quot; + s.Port)<\/code><\/pre>\n<\/li>\n<li> \u041f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 data:\n<pre><code class=\"go\">conn.Write(data)<\/code><\/pre>\n<\/li>\n<li> \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0432\u0435\u0442\n<pre><code class=\"go\">resp, n, _ := TCPResponseData(conn, s.BufSize)<\/code><\/pre>\n<p>  \u0438 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 <\/p>\n<pre><code class=\"go\">fmt.Println(string(resp[:n]))<\/code><\/pre>\n<\/li>\n<li> \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d <i>payload<\/i> \u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0435\u0433\u043e\n<pre><code class=\"go\">conn.Write(payload)<\/code><\/pre>\n<p>  \u0438 \u0442\u0430\u043a\u0436\u0435 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043f\u0435\u0447\u0430\u0442\u0430\u044f \u0435\u0433\u043e \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438<\/li>\n<\/ul>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f<\/p>\n<pre><code class=\"go\"> TCPResponseData(conn net.Conn, bufsiz int) ([]byte, int, error)<\/code><\/pre>\n<p>  \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0431\u0443\u0444\u0435\u0440 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0447\u0438\u0442\u0430\u0435\u0442 \u0442\u0443\u0434\u0430 \u043e\u0442\u0432\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u0431\u0443\u0444\u0435\u0440 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0445 \u0431\u0430\u0439\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<h4>\u041f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 client<\/h4>\n<p>  \u0421\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c \u043d\u043e\u0434, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON, \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0435\u0433\u043e \u0432 payload, \u0444\u043b\u0430\u0433 \u044d\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043d\u043e\u0434\u044b, \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<ul>\n<li> \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e\n<pre><code class=\"go\">st := types.ParseConfig(*config)<\/code><\/pre>\n<\/li>\n<li> \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0444\u043b\u0430\u0433 emu \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f <i>sheduler<\/i><\/li>\n<li> \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0430\u043d \u0444\u043b\u0430\u0433 f \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u043f\u0443\u0442\u0438 \u043a \u0444\u0430\u0439\u043b\u0443, \u0442\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <i>fdb<\/i> \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0443\n<pre><code class=\"go\">client.TCPConnect(st, []byte(CMD_BUFFER_LENGTH + &quot;:&quot; + strconv.Itoa(*t) + &quot;\/&quot; + strconv.Itoa(fdblen)), fdb)<\/code><\/pre>\n<\/li>\n<li> \u0415\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u043d\u0435 \u0437\u0430\u0434\u0430\u043d, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u043b\u0430\u0433\u0430 <i>-d<\/i>:\n<pre><code class=\"go\">client.TCPConnect(st, []byte(*data), nil)<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>  \u0412\u0441\u0435 \u044d\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430. \u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0432 \u0435\u0433\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. <\/p>\n<p>  \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u043e\u0432 \u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, \u0432 3 \u043e WebSocket \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u0437 JavaScript, \u0432 4 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u0434\u0430\u043b\u0435\u0435 \u0441\u0442\u0435\u043a\u043e\u0432\u0430\u044f \u043c\u0430\u0448\u0438\u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u0431\u0430\u0439\u0442\u043a\u043e\u0434 \u0438\u0437 \u0432\u0445\u043e\u0434\u043e\u0432 \u0438 \u0432\u044b\u0445\u043e\u0434\u043e\u0432, \u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044f \u0438 \u043f\u0443\u043b\u044b \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u043e\u0432.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/499732\/\"> https:\/\/habr.com\/ru\/post\/499732\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/499732\/\">\u0412\u043e\u0442 \u0443\u0436\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u043c\u0435\u0441\u044f\u0446\u0430 \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u0432\u0430\u043b \u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0437\u0430\u0449\u0438\u0442\u044b \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0433\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0444\u0435\u0440\u0430\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d\u0430\u00bb. <br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u044f \u043d\u0430\u0447\u0438\u043d\u0430\u043b, \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u043e\u043f\u0438\u0448\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/319\/86b\/9a5\/31986b9a5079081f4eb87335330d119c.jpg\" alt=\"image\">  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-302769","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=302769"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302769\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=302769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=302769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=302769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}