{"id":266521,"date":"2015-10-22T18:18:48","date_gmt":"2015-10-22T14:18:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=266521"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=266521","title":{"rendered":"\u0418\u0437\u0443\u0447\u0430\u0435\u043c net\/context \u0432 Go"},"content":{"rendered":"<p>       \u041d\u0435 \u0441\u0435\u043a\u0440\u0435\u0442, \u0447\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043d\u0438\u0448\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Go \u044d\u0442\u043e \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b: \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u044b, \u0431\u0435\u043a\u0435\u043d\u0434\u044b, \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0422\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432\u0435\u0441\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u043d\u043e \u043e\u0434\u0438\u043d \u0430\u0441\u043f\u0435\u043a\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0442\u0435\u043c\u043d\u044b\u043c \u043f\u044f\u0442\u043d\u043e\u043c \u2014 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u043e\u0442 \u0430\u0441\u043f\u0435\u043a\u0442 \u043f\u043e\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0439 \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u0432\u0430\u0436\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/2ef\/8bf\/eaf\/2ef8bfeaf57045b3ae30b5474a6412d3.png\"\/><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442?<\/h4>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u2014 \u0447\u0442\u043e \u044d\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0437\u0430 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u0442\u0430\u043a\u043e\u0435, \u00ab\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u00bb? \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c, \u043f\u0440\u043e\u0441\u0442\u0438\u0442\u0435 \u0437\u0430 \u0442\u0430\u0432\u0442\u043e\u043b\u043e\u0433\u0438\u044e, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u0431 \u043e\u0431\u044a\u0435\u043a\u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0433\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 API. \u041f\u043e\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438 API \u2014 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 middleware, \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u0430\u043a\u0430\u0434\u0436\u0438 \u0438 \u0441\u043b\u043e\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439, \u043d\u043e \u0441\u0430\u043c\u043e \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u00ab\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u00bb \u043d\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0435\u0447\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e \u043d\u0438\u0445.<\/p>\n<p>  \u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u2014 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0437 JWT-\u0442\u043e\u043a\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043b\u043e\u0433 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  \u042d\u0442\u0430 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u043b\u044f \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0435\u0441\u0442\u044c \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445 \u2014 \u0432 C# \u044d\u0442\u043e <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.web.httpcontext(v=vs.110).aspx\">HttpContext<\/a>, \u0432 Java-\u0432\u043e\u0432\u0441\u043a\u043e\u043c Netty \u2014 <a href=\"http:\/\/netty.io\/4.0\/api\/io\/netty\/channel\/ChannelHandlerContext.html\">ChannelHandlerContext<\/a>, \u0432 \u043f\u0438\u0442\u043e\u043d\u0432\u0441\u043a\u043e\u043c Twisted \u2014 <a href=\"https:\/\/twistedmatrix.com\/documents\/current\/api\/twisted.python.context.html\">twisted.python.context<\/a> \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<h4>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u0432 Go<\/h4>\n<p>  \u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Go \u0435\u0441\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 <a href=\"https:\/\/golang.org\/pkg\/net\/http\/\">HTTP \u0441\u0442\u0435\u043a<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u0435 \u0431\u043e\u044f\u0441\u044c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430_10000_\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439\">\u00ab\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b 10\u041a \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439\u00bb<\/a>, \u0438 \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <a href=\"https:\/\/golang.org\/pkg\/net\/http\/#Handler\">Handler<\/a>. \u041d\u043e \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u043b\u044f http-\u0445\u0435\u043d\u0434\u043b\u0435\u0440\u043e\u0432 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043d\u0435\u0442.<\/p>\n<p>  \u041d\u043e \u0443 Go, \u043f\u043e\u043c\u0438\u043c\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0435\u0441\u0442\u044c \u043e\u0442 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 Go \u0438 <a href=\"https:\/\/github.com\/golang\/go\/wiki\/SubRepositories\">\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u043d\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 Go, \u0438 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u0436\u0435\u0441\u0442\u043a\u043e\u0433\u043e \u043e\u0431\u0435\u0449\u0430\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u0430\u043a \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435. \u042d\u0442\u043e \u0432\u0441\u0435 \u043f\u0430\u043a\u0435\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u0435\u0436\u0430\u0442 \u0432 <b>golang\/x\/<\/b>. \u0421\u0440\u0435\u0434\u0438 \u043d\u0438\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u0432\u043d\u043e \u0435\u0441\u0442\u044c \u043f\u0430\u043a\u0435\u0442 <b>net\/context<\/b>, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0442\u0443 \u0441\u0430\u043c\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0438 \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0438 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c. \u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438, \u044d\u0442\u043e\u0442 \u043f\u0430\u043a\u0435\u0442 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f,<a href=\"https:\/\/godoc.org\/golang.org\/x\/net\/context?importers\"> \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e GoDoc<\/a>, \u0432 1560 \u043f\u0430\u043a\u0435\u0442\u0430\u0445.<\/p>\n<p>  \u041e\u0442\u0447\u0430\u0441\u0442\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u043e\u0433\u043e \u0437\u043e\u043e\u043f\u0430\u0440\u043a\u0430 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0435\u0448\u0430\u043b \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e-\u0441\u0432\u043e\u0435\u043c\u0443.<\/p>\n<h4>\u0417\u043e\u043e\u043f\u0430\u0440\u043a \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432<\/h4>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043b\u043e\u0432\u043e \u00ab\u0437\u043e\u043e\u043f\u0430\u0440\u043a\u00bb \u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0442\u0440\u0438\u0440\u0443\u044e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u0442. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 net\/http \u0445\u043e\u0440\u043e\u0448 \u043a\u0430\u043a \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442, \u043d\u043e \u043a\u0430\u043a-\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441, \u0432\u044b \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0435 \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u2014 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0440\u043e\u0443\u0442\u0438\u043d\u0433 \u0441 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u043e\u0439, \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0435 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435, \u0438 \u044d\u0442\u043e \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043a\u0438\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u2014 \u043c\u043d\u043e\u0433\u0438\u043c \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0431\u0443\u0434\u0435\u0442 \u043d\u0443\u0436\u0435\u043d \u0438 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e \u0434\u0443\u0448\u0435. \u041d\u043e \u0432 \u0446\u0435\u043b\u043e\u043c, \u043e\u0431\u044b\u0447\u043d\u043e \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u0438 \u043e\u043d\u0438 \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f, <a href=\"https:\/\/github.com\/vishr\/go-http-routing-benchmark\">\u0441\u043e\u0440\u0435\u0432\u043d\u0443\u044f\u0441\u044c \u0432 zero-memory allocations \u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438<\/a>. \u0421\u0435\u0439\u0447\u0430\u0441, \u043f\u0430\u043b\u044c\u043c\u0430 \u043f\u0435\u0440\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u043f\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438, \u0432\u0440\u043e\u0434\u0435 \u043a\u0430\u043a \u0443 <a href=\"https:\/\/github.com\/gin-gonic\/gin\">gin-gonic<\/a>.<\/p>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043b \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u043f\u043e-\u0441\u0432\u043e\u0435\u043c\u0443. <a href=\"https:\/\/github.com\/gorilla\/context\">GorillaToolkit<\/a> \u0434\u0435\u0440\u0436\u0438\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043d\u0435\u043c\u0443 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438. <a href=\"https:\/\/godoc.org\/github.com\/zenazn\/goji\/web#C\">Goji<\/a> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0445\u0440\u0430\u043d\u044f\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u043f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. <a href=\"https:\/\/github.com\/gocraft\/web\">gocraft\/web<\/a> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 reflection. \u0423 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e Gin \u2014 <a href=\"https:\/\/github.com\/gin-gonic\/gin\/blob\/master\/context.go\">Context<\/a> \u0432\u043e\u043e\u0431\u0449\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432\u0441\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b. \u0412 <a href=\"https:\/\/godoc.org\/github.com\/labstack\/echo#Context\">echo<\/a> \u043d\u0430 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 Context \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0432\u0435\u0441\u0438\u043b\u0438 \u0432\u0441\u0451 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u043d\u043e \u0443 \u0432\u0441\u0435\u0445 \u0443 \u043d\u0438\u0445 \u043e\u0434\u0438\u043d \u043c\u0438\u043d\u0443\u0441 \u2014 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0443. \u041a\u0430\u043a \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0435\u0441\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0435 \u0438 \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 http-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440<\/h4>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u0430:<\/p>\n<pre><code class=\"go\">package main  import ( \t&quot;net\/http&quot; )  func handler(w http.ResponseWriter, r *http.Request) { \tw.Write([]byte(&quot;Hello World&quot;)) }  func main() { \thttp.HandleFunc(&quot;\/&quot;, handler) \thttp.ListenAndServe(&quot;:1234&quot;, nil) } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">$ curl http:\/\/localhost:1234 Hello World <\/code><\/pre>\n<p>  \u041d\u043e \u0442\u0443\u0442 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u0443\u044e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e \u043f\u0438\u043d-\u043a\u043e\u0434\u0443, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 middleware \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e http.HandleFunc:<\/p>\n<pre><code class=\"go\">func needPin(h http.HandlerFunc) http.HandlerFunc { \treturn func(w http.ResponseWriter, r *http.Request) { \t\tif r.FormValue(&quot;pin&quot;) != &quot;9999&quot; { \t\t\thttp.Error(w, &quot;wrong pin&quot;, http.StatusForbidden) \t\t\treturn \t\t} \t\th(w, r) \t} } ... http.HandleFunc(&quot;\/&quot;, needPin(handler)) ... <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">$ curl http:\/\/localhost:1234 wrong pin $ curl http:\/\/localhost:1234?pin=9999 Hello World <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0438\u043d \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437 SQL-\u0431\u0430\u0437\u044b, \u0430 \u043d\u0435 \u0445\u0430\u0440\u0434\u043a\u043e\u0434\u0438\u0442\u044c. \u041e\u043a\u0435\u0439, \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e *sql.DB:<\/p>\n<pre><code class=\"go\">func needPin(h http.HandlerFunc) http.HandlerFunc { \treturn func(w http.ResponseWriter, r *http.Request) { \t\tvar pin string \t\tif err := db.QueryRow(&quot;SELECT pin FROM pins&quot;).Scan(&pin); err != nil { \t\t\thttp.Error(w, &quot;database error&quot;, http.StatusInternalServerError) \t\t\treturn \t\t} \t\t... <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">$ sqlite3 pins.db SQLite version 3.8.4.3 2014-04-03 16:53:12 Enter &quot;.help&quot; for usage hints. sqlite&gt; CREATE TABLE pins(pin STRING); sqlite&gt; INSERT INTO pins(pin) VALUES (&quot;9999&quot;); sqlite&gt; ^D <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"go\">package main  import ( \t&quot;database\/sql&quot; \t_ &quot;github.com\/mattn\/go-sqlite3&quot; \t&quot;net\/http&quot; )  var ( \tdb  *sql.DB \terr error )  func handler(w http.ResponseWriter, r *http.Request) { \tw.Write([]byte(&quot;Hello World&quot;)) }  func needPin(h http.HandlerFunc) http.HandlerFunc { \treturn func(w http.ResponseWriter, r *http.Request) { \t\tvar pin string \t\tif err := db.QueryRow(&quot;SELECT pin FROM pins&quot;).Scan(&pin); err != nil { \t\t\thttp.Error(w, &quot;database error&quot;, http.StatusInternalServerError) \t\t\treturn \t\t} \t\tif r.FormValue(&quot;pin&quot;) != pin { \t\t\thttp.Error(w, &quot;wrong pin&quot;, http.StatusForbidden) \t\t\treturn \t\t} \t\th(w, r) \t} }  func main() { \tif db, err = sql.Open(&quot;sqlite3&quot;, &quot;.\/pins.db&quot;); err != nil { \t\tpanic(err) \t} \tdefer db.Close() \thttp.HandleFunc(&quot;\/&quot;, needPin(handler)) \thttp.ListenAndServe(&quot;:1234&quot;, nil) } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u0434\u0430\u043b\u044c\u0448\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430\u0448\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0441\u0442\u0438:<\/p>\n<ul>\n<li>\u0430 \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u043f\u0438\u043d-\u043a\u043e\u0434\u043e\u043c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 syslog?<\/li>\n<li>\u0430 \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c IP \u0430\u0434\u0440\u0435\u0441?<\/li>\n<li>\u0430 \u043c\u043e\u0436\u043d\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 IP \u0434\u0435\u043b\u0430\u0442\u044c \u0448\u0430\u0440\u0434\u0438\u043d\u0433 \u0438 \u0431\u0435\u0433\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0431\u0430\u0437\u044b?<\/li>\n<li>\u0430 \u043c\u043e\u0436\u043d\u043e &#8230;?<\/li>\n<\/ul>\n<p>  \u00ab\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e\u00bb, \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u0432\u044b \u0438 \u043f\u0438\u0448\u0435\u0442\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0430\u0441\u043a\u0430 \u0441\u0432\u043e\u0439 middleware, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0438\u0445 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0438. \u0415\u0441\u0442\u044c \u0434\u0430\u0436\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u043a\u0430\u0434\u0436\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/github.com\/justinas\/alice\">Alice<\/a>. \u041d\u043e \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437 authMiddleware \u0432 logMiddleware? \u0410 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0451 \u0431\u0435\u0433\u0430\u0442\u044c \u0432 <a href=\"http:\/\/vaultproject.io\">Vault<\/a> \u0437\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u043e\u043b\u044f\u043c\u0438, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0442\u043e\u043a\u0435\u043d \u0438\u0437 \u0441\u0435\u0441\u0441\u0438\u0438? \u0410 \u043a\u0430\u043a \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0443?<\/p>\n<p>  \u0412\u043e\u0442 \u0442\u0443\u0442 \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u041a\u0430\u0436\u0434\u0430\u044f middleware-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u0430\u043b\u044c\u0448\u0435. \u0412 \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432\u044b \u0432\u043e\u043b\u044c\u043d\u044b \u0437\u0430\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u2014 \u0441\u0442\u0430\u0442\u0443\u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432\u044b\u0442\u0430\u0449\u0435\u043d\u043d\u0443\u044e \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 ID \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0442\u0440\u0435\u043a\u0438\u043d\u0433\u0430 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e context.Context \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u043a\u0430\u043a middleware, \u0442\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c). \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043c\u043e\u0436\u043d\u043e Context \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043f\u043e\u043b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043d\u043e \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a Context \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u2014 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>  \u041d\u043e <i>net\/context<\/i> \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u044d\u0442\u043e \u0438 \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430\u043c\u0438 \u0438 \u043e\u0442\u043c\u0435\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435.<\/p>\n<h4>net\/context \u0438\u0437\u043d\u0443\u0442\u0440\u0438<\/h4>\n<p>  API \u0440\u0430\u0431\u043e\u0442\u044b \u0441 net\/context \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u043e\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u044c\u0442\u0435 \u0433\u043e\u0442\u043e\u0432\u044b \u043a \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u044e \u0432\u043d\u0430\u0447\u0430\u043b\u0435.<\/p>\n<p>  \u0422\u0443\u0442 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0435\u0449\u0451, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0432 Go \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 \u043e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0430\u044f \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u043e\u0434\u043d\u0443 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u043b\u0438 \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430\u0432\u0435\u0440\u0445. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0440\u0430\u0437\u043d\u0435\u0441\u0435\u043d\u043d\u044b\u0445 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u043a\u0430\u0434\u0436\u0438, \u0442\u0430\u043a \u0438 \u0446\u0435\u043b\u044b\u0435 \u043a\u0430\u0441\u043a\u0430\u0434\u044b \u043d\u043e\u0432\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0438 \u043a\u0430\u043d\u0430\u043b\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0438\u0445 \u043a\u0430\u043d\u0430\u043b\u044b. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0447\u0435\u0442\u043a\u0438\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e middleware, \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0430\u043a\u0430\u0434\u0436\u0430, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0447\u0442\u043e-\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0437\u043d\u0430\u0442\u044c \u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0435, \u0438 \u0447\u0442\u043e-\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u043d\u0430\u0434 \u043d\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b net\/context \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <b>\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c\u0438<\/b> \u0438 \u0438\u043c\u0435\u044e\u0442 \u0434\u0440\u0435\u0432\u043e\u0434\u0432\u0438\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, <a href=\"https:\/\/godoc.org\/golang.org\/x\/net\/context\">\u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a> \u043f\u0430\u043a\u0435\u0442\u0430 net\/context \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u0442\u0435\u043c. \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0438\u0437 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e, \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0439 \u00ab\u043f\u043e\u0434\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u00bb:<\/p>\n<pre><code class=\"go\">func Background() Context func TODO() Context func WithCancel(parent Context) (ctx Context, cancel CancelFunc) func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) func WithValue(parent Context, key interface{}, val interface{}) Context <\/code><\/pre>\n<p>  \u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e context.Context \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c, \u0438 \u043f\u0430\u043a\u0435\u0442 net\/context \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043b\u0438\u0448\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0439, \u043d\u043e \u0432\u044b \u0432\u043e\u043b\u044c\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u043a\u0430\u043a\u043e\u0439 \u0443\u0433\u043e\u0434\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"go\">type Context interface {     Deadline() (deadline time.Time, ok bool)     Done() &lt;-chan struct{}     Err() error     Value(key interface{}) interface{} } <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u044f \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0432\u0438\u0434\u0430\u043c\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432:<\/p>\n<ul>\n<li><b>context.Background()<\/b> \u2014 \u044d\u0442\u043e \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0435\u0442 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u0438\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u043c\u0435\u043d\u044b; \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e Background() \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043e\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<br \/>  \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 camilstore:<br \/> \n<pre><code class=\"go\">client := oauth2.NewClient(context.Background(), google.ComputeTokenSource(&quot;&quot;)) <\/code><\/pre>\n<\/li>\n<li><b>context.TODO()<\/b> \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0442\u043e\u0436\u0435 \u043f\u0443\u0441\u0442\u043e\u0439, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u044f\u0441\u043d\u043e \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0435\u0449\u0451 \u043d\u0435 \u0431\u044b\u043b\u0430 \u043e\u0442\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0435\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u0418\u043c\u044f TODO \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u043a\u043e\u0434\u0430 \u043c\u043e\u0433\u043b\u0438 \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u043b\u0438\u043d\u0442\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u0435\u0449\u0435 \u043d\u0435\u0442 \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445, <a href=\"https:\/\/twitter.com\/Sajma\/status\/494161985219465217\">\u043d\u043e \u0435\u0441\u0442\u044c \u0432 Google \u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c<\/a>.<\/li>\n<li><b>context.WithCancel(parent Context) (ctx Context, cancel CancelFunc)<\/b> \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043f\u0438\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 <i>parent<\/i> \u0441 \u043d\u043e\u0432\u044b\u043c \u043a\u0430\u043d\u0430\u043b\u043e\u043c <i>Done<\/i> \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e CanceFunc, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<br \/> \n<pre><code class=\"go\">func handler(w http.ResponseWriter, r *http.Request) {     \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441 \u043e\u0442\u043c\u0435\u043d\u043e\u0439     ctx, cancel = context.WithCancel(context.Background())     defer cancel()      \/\/ \u0436\u0434\u0435\u043c \u043e\u0434\u043d\u0443 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 Done, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442     go func() {         time.Sleep(1 * time.Second)         ctx.Done &lt;- struct{}     }()         \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441     res, err:= startLongQuery(ctx, w)     if err != nil {         http.Error(w, &quot;cancelled&quot;, http.StatusInternalError)         return     }     \/\/ ...encode res to json     w.Write(encodedResult) }  func startLongQuery(ctx context.Context, w http.ResponseWriter) (*Result, error) {     resCh, transport := runLongQueryToJavaService(someArgs)     select {     case &lt;-ctx.Done():          \/\/ \u0434\u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0441\u044f \u043e\u0442\u043c\u0435\u043d\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443         transport.CancelRequest(req)         &lt;-resCh         return nil, ctx.Err()     case result := &lt;-resCh:          \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0442\u0432\u0435\u0442 \u0440\u0430\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u043a\u0440\u044b\u043b\u0441\u044f Done, \u0432\u0441\u0435 \u043e\u043a          return Result{result}, nil     } } <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0440\u043e\u0447\u0438\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439, \u0438 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u0432 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435, \u043d\u043e \u0438\u0434\u0435\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u0430. <br \/>  \u041f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 Cancel \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d, \u0441\u043a\u0430\u0436\u0435\u043c, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u2014 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0430\u043c\u043e\u0439 \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438, \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u043e\u0442\u043c\u0435\u043d\u044f\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0437\u0440\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/li>\n<li><b>context.WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) \u0438 context.WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc)<\/b> \u2014 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e WithCancel(), \u043d\u043e \u0441\u0430\u043c\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0442 Done \u043f\u043e\u0441\u043b\u0435 \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u0438\u043b\u0438 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0434\u0435\u0434\u043b\u0430\u0439\u043d\u0430. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, WithTimeout \u2014 \u044d\u0442\u043e WithDeadline \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c time.Now().Add(timeout).\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043d\u044f\u043b\u0438, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 WithCancel, \u0442\u043e \u0441 \u044d\u0442\u0438\u043c\u0438 \u0434\u0432\u0443\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c. \u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0448\u0435 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u0441\u044f \u043d\u0430 \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u0447\u0435\u043a, \u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"go\">    timeout, err := time.ParseDuration(req.FormValue(&quot;timeout&quot;))     if err == nil {         ctx, cancel = context.WithTimeout(context.Background(), timeout)     } <\/code><\/pre>\n<p>  \u0447\u0442\u043e\u0431\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0436\u0434\u0430\u0442\u044c \u0434\u043e\u043b\u0433\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/li>\n<li><b>context.WithValue(parent Context, key interface{}, val interface{}) Context<\/b> \u2014 \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0447\u0443\u0442\u044c \u0432\u044b\u0448\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u0427\u0443\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e context.WithValue<\/h4>\n<p>  \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0432\u044b\u0448\u0435 net\/context \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0430\u043f\u044b \u0438\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0441\u0432\u043e\u0435\u0439 \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u043e\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b. \u041e\u0434\u0438\u043d \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043d\u0435\u0441\u0435\u0442 \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043b\u044e\u0441 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041a\u0430\u043a \u043a\u043b\u044e\u0447 \u0442\u0430\u043a \u0438 \u0441\u0430\u043c\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u2014 \u043a\u043b\u044e\u0447 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0435\u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438\/API, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"go\">package userIP \/\/ \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 type key int \/\/ \u043a\u043b\u044e\u0447 \u0434\u043b\u044f IP \u0430\u0434\u0440\u0435\u0441\u0430. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e\u0442 \u043f\u0430\u043a\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0435\u0449\u0435 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043a\u043b\u044e\u0447\u0438, \u044d\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043d\u0442\u0430\u043d\u0442\u044b. const userIPKey key = 0 <\/code><\/pre>\n<p>  \u0421\u0430\u043c \u0436\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c (https:\/\/github.com\/golang\/net\/blob\/master\/context\/context.go#L433):<\/p>\n<pre><code class=\"go\">type valueCtx struct { \tContext \tkey, val interface{} }  \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f Value \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 func (c *valueCtx) Value(key interface{}) interface{} { \tif c.key == key { \t\treturn c.val \t} \treturn c.Context.Value(key) } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u0440\u0438 \u043b\u044e\u0431\u043e\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, Value() \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0432\u0432\u0435\u0440\u0445 \u043f\u043e \u0434\u0435\u0440\u0435\u0432\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442 \u043d\u0443\u0436\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u041d\u0443, \u0438\u043b\u0438 \u0432\u0435\u0440\u043d\u0435\u0442 nil, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Value() \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 (Context, \u043a\u0430\u043a \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0430, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0438 \u0434\u043b\u044f Background-\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0442\u043e\u0436\u0435).<\/p>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0430\u043a\u0435\u0442\u0430, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u043c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0438\u043c:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\">\/\/ Package userip provides functions for extracting a user IP address from a \/\/ request and associating it with a Context. package userip  import ( \t&quot;fmt&quot; \t&quot;net&quot; \t&quot;net\/http&quot;  \t&quot;golang.org\/x\/net\/context&quot; )  \/\/ FromRequest extracts the user IP address from req, if present. func FromRequest(req *http.Request) (net.IP, error) { \tip, _, err := net.SplitHostPort(req.RemoteAddr) \tif err != nil { \t\treturn nil, fmt.Errorf(&quot;userip: %q is not IP:port&quot;, req.RemoteAddr) \t}  \tuserIP := net.ParseIP(ip) \tif userIP == nil { \t\treturn nil, fmt.Errorf(&quot;userip: %q is not IP:port&quot;, req.RemoteAddr) \t} \treturn userIP, nil }  \/\/ The key type is unexported to prevent collisions with context keys defined in \/\/ other packages. type key int  \/\/ userIPkey is the context key for the user IP address.  Its value of zero is \/\/ arbitrary.  If this package defined other context keys, they would have \/\/ different integer values. const userIPKey key = 0  \/\/ NewContext returns a new Context carrying userIP. func NewContext(ctx context.Context, userIP net.IP) context.Context { \treturn context.WithValue(ctx, userIPKey, userIP) }  \/\/ FromContext extracts the user IP address from ctx, if present. func FromContext(ctx context.Context) (net.IP, bool) { \t\/\/ ctx.Value returns nil if ctx has no value for the key; \t\/\/ the net.IP type assertion returns ok=false for nil. \tuserIP, ok := ctx.Value(userIPKey).(net.IP) \treturn userIP, ok } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0427\u0442\u043e \u0438 \u043a\u0430\u043a \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u2014 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0439 ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441 \u043c\u0430\u0441\u0441\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438, \u0442\u0430\u043a \u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u0440\u043e\u0434\u0435 sql.DB \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h4>\u041f\u043b\u044e\u0448\u043a\u0438<\/h4>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0440\u0443\u0436\u0438\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0441 \u043a\u043e\u0434\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u043c net\/context.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0449\u0435\u0433\u043e gorilla\/context: <a href=\"http:\/\/blog.golang.org\/context\/gorilla\/gorilla.go\">blog.golang.org\/context\/gorilla\/gorilla.go<\/a><\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0442\u043c\u0435\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435, tomb: <a href=\"http:\/\/blog.golang.org\/context\/tomb\/tomb.go\">blog.golang.org\/context\/tomb\/tomb.go<\/a><\/p>\n<p>  \u0418\u043b\u0438 \u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/godoc.org\/golang.org\/x\/net\/trace\">net\/trace<\/a>, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u043b\u044f \u0442\u0440\u0435\u0439\u0441\u0438\u043d\u0433\u0430 \u0436\u0438\u0437\u043d\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0441\u0442\u0438\u043b\u0435 Dapper. \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 context.WithValue(ctx, trace) \u0438 \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0440\u043e\u0436\u0434\u0435\u043d\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c ID \u0442\u0440\u0435\u0439\u0441\u0430, \u0430 \u0443\u0436\u0435 \u043a\u043e\u0434 net\/trace \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0440\u0435\u0439\u0441\u0430\u0445 \u043d\u0430 \u0432\u0435\u0431 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u043e \u043f\u0443\u0442\u0438 <i>\/debug\/requests<\/i> \u0438 <i>\/debug\/events<\/i>.<\/p>\n<p>  \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u044b\u0433\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u0435\u0441\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0449\u0430\u0435\u0442\u0441\u044f \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0438\u043b\u0438 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c net\/context. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043a\u043e\u0434\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 Google \u043d\u0430 Go, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0443\u0436\u0435 \u043e\u043a\u043e\u043b\u043e 10+\u043c\u043b\u043d \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430, \u0432\u0435\u0437\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 context.Context. \u041d\u043e\u0432\u044b\u0439 RPC-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a <a href=\"http:\/\/grpc.io\">gRPC<\/a> \u043d\u0430 Protobuf3, \u043a\u043e\u0433\u0434\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u0434\u043b\u044f Go, \u0442\u0430\u043a\u0436\u0435 \u0432\u0435\u0437\u0434\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 context.Context.<\/p>\n<h4>\u041f\u043b\u0430\u043d\u044b \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435<\/h4>\n<p>  \u0412\u043e\u0442 \u0432 \u0442\u0443\u0442 \u0438\u0434\u0435\u0442<a href=\"https:\/\/groups.google.com\/forum\/#!topic\/golang-dev\/cQs1z9LrJDU\"> \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435<\/a> \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043f\u043b\u0430\u043d\u043e\u0432 net\/context, \u0438, \u0432\u043f\u043e\u043b\u043d\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0447\u0442\u043e context \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0432 Go 1.7. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437, \u043d\u043e, \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0435\u0441\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0440\u0443\u043a\u0443 \u043d\u0430 \u043f\u0443\u043b\u044c\u0441\u0435.<\/p>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0441\u0430\u043c\u043e \u0441\u043e\u0431\u043e\u0439, \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430, \u0438 \u0432\u0435\u0449\u0435\u0439 \u0432\u0440\u043e\u0434\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 http \u0438 ctxhttp \u043d\u0435 \u0431\u0443\u0434\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434\u043e\u0432\u0443\u044e \u0431\u0430\u0437\u0443 (\u0445\u043e\u0442\u044f \u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/godoc.org\/golang.org\/x\/net\/context\/ctxhttp\">ctxhttp<\/a> \u0441\u0435\u0439\u0447\u0430\u0441, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442). \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432 http.Request \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u0435 Context, \u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u0438\u0434\u0443\u0442 \u043a \u043a\u0430\u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0451 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443.<\/p>\n<p>  \u0421\u043b\u043e\u0432\u043e net \u0438\u0437 net\/context, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u043f\u0430\u0434\u0435\u0442.<\/p>\n<h4>\u0421\u0441\u044b\u043b\u043a\u0438<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u043e\u0447\u0435\u043d\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438:<\/p>\n<p>  \u0425\u043e\u0440\u043e\u0448\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u0445 \u0432 \u0431\u043b\u043e\u0433\u0435 Go \u2014 <a href=\"http:\/\/blog.golang.org\/context\">blog.golang.org\/context<\/a><br \/>  \u0414\u043e\u043a\u043b\u0430\u0434 \u043d\u0430 GothamGo 2014 \u043f\u0440\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u2014 <a href=\"https:\/\/vimeo.com\/115309491\">vimeo.com\/115309491<\/a><br \/>  \u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e http.Handler \u0438 net\/context \u2014 <a href=\"https:\/\/joeshaw.org\/net-context-and-http-handler\/\">joeshaw.org\/net-context-and-http-handler<\/a><br \/>  \u0414\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u0430\u0439\u0434\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0433\u043e \u0434\u043e\u043a\u043b\u0430\u0434\u0430 \u043d\u0430 \u0442\u0435\u043c\u0443 net\/context \u2014 <a href=\"http:\/\/go-talks.appspot.com\/github.com\/guregu\/slides\/kami\/kami.slide#1\">go-talks.appspot.com\/github.com\/guregu\/slides\/kami\/kami.slide#1<\/a><br \/>  \u0421\u0442\u0430\u0442\u044c\u044f \u043e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0445 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430\u0445 \u0438 \u043e\u0442\u043c\u0435\u043d\u0430\u0445 \u0432 Go \u2014 <a href=\"http:\/\/blog.golang.org\/pipelines\">blog.golang.org\/pipelines<\/a><br \/>  \u041e\u0431\u0437\u043e\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445 \u2014 <a href=\"https:\/\/www.nicolasmerouze.com\/share-values-between-middlewares-context-golang\/\">www.nicolasmerouze.com\/share-values-between-middlewares-context-golang<\/a><br \/>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 net\/context \u2014 <a href=\"https:\/\/github.com\/golang\/net\/tree\/master\/context\">github.com\/golang\/net\/tree\/master\/context<\/a>               <\/p>\n<div class=\"clear\"><\/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=\"http:\/\/habrahabr.ru\/post\/269299\/\"> http:\/\/habrahabr.ru\/post\/269299\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041d\u0435 \u0441\u0435\u043a\u0440\u0435\u0442, \u0447\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043d\u0438\u0448\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Go \u044d\u0442\u043e \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b: \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u044b, \u0431\u0435\u043a\u0435\u043d\u0434\u044b, \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0422\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432\u0435\u0441\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u043d\u043e \u043e\u0434\u0438\u043d \u0430\u0441\u043f\u0435\u043a\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0442\u0435\u043c\u043d\u044b\u043c \u043f\u044f\u0442\u043d\u043e\u043c \u2014 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u043e\u0442 \u0430\u0441\u043f\u0435\u043a\u0442 \u043f\u043e\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0439 \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u0432\u0430\u0436\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/2ef\/8bf\/eaf\/2ef8bfeaf57045b3ae30b5474a6412d3.png\"\/>  <\/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-266521","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/266521","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=266521"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/266521\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}