{"id":457499,"date":"2025-04-26T15:00:30","date_gmt":"2025-04-26T15:00:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=457499"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2025-04-26T15:00:30","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=457499","title":{"rendered":"<span>Golang Top 15 \u043e\u0448\u0438\u0431\u043e\u043a<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"bordered full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/84a\/0ee\/835\/84a0ee835baff59560e34993d61e5019.png\" width=\"1024\" height=\"1536\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/84a\/0ee\/835\/84a0ee835baff59560e34993d61e5019.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/84a\/0ee\/835\/84a0ee835baff59560e34993d61e5019.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<div class=\"floating-image\">\n<p>Go \u2013 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e \u0438\u0437-\u0437\u0430 \u043a\u0430\u0436\u0443\u0449\u0435\u0439\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043c\u043d\u043e\u0433\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c \u0432 production. <\/p>\n<p>\u041d\u0438\u0436\u0435 \u0441\u043e\u0431\u0440\u0430\u043d\u044b 15 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043d\u0430 Golang \u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043f\u043e \u0438\u0445 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e.<\/p>\n<\/div>\n<h2>1. \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>\u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0431\u0430\u0433\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">_, err := ioutil.ReadFile(\"config.json\")<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">data, err := ioutil.ReadFile(\"config.json\") if err != nil {     log.Fatal(err) }<\/code><\/pre>\n<h2>2. \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438<\/h2>\n<p>\u0411\u0435\u0441\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0442\u0435\u0447\u043a\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">for i := 0; i &lt; 1000; i++ {     go doSomething() }<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">var wg sync.WaitGroup for i := 0; i &lt; 1000; i++ {     wg.Add(1)     go func() {         defer wg.Done()         doSomething()     }() } wg.Wait()<\/code><\/pre>\n<pre><code class=\"go\">var wg sync.WaitGroup <\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>wg<\/code> \u0442\u0438\u043f\u0430 <code>sync.WaitGroup<\/code> \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Go, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <strong>\u0436\u0434\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/strong>.  <\/p>\n<pre><code class=\"go\">for i := 0; i &lt; 1000; i++ {     wg.Add(1)     go func() {         defer wg.Done()         doSomething()     }() }<\/code><\/pre>\n<p>\u0426\u0438\u043a\u043b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 <strong>1000 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/strong>.<br \/>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p><code>wg.Add(1)<\/code> \u2014 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a <code>WaitGroup<\/code> \u043d\u0430 1: \u00ab\u041e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u00bb.<\/p>\n<\/li>\n<li>\n<p><code>go func() { ... }()<\/code> \u2014 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u043d\u043e\u0432\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435.<\/p>\n<\/li>\n<li>\n<p><code>defer wg.Done()<\/code> \u2014 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a <code>WaitGroup<\/code> \u043d\u0430 1, \u043a\u043e\u0433\u0434\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p><code>doSomething()<\/code> \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0448\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"go\">wg.Wait()<\/code><\/pre>\n<p> \u042d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <strong>\u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 1000 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0443\u0442 <\/strong><code><strong>wg.Done()<\/strong><\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043e \u0438\u0445 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f.  <\/p>\n<h4>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e?<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b <strong>\u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447<\/strong>, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0418\u043d\u0430\u0447\u0435 <code>main()<\/code> \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0443\u0441\u043f\u0435\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<h4>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f:<\/h4>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0442\u0435, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u0440\u0443\u0447\u0438\u043b\u0438 1000 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430\u043c \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u043d\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0443, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u043e\u0444\u0438\u0441. <code>WaitGroup<\/code> \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u0433\u0430\u043b\u043e\u0447\u043a\u0430\u043c\u0438: \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u043c, \u0438 \u0442\u044b \u0436\u0434\u0451\u0448\u044c, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u044f\u0442 \u0433\u0430\u043b\u043e\u0447\u043a\u0438.<\/p>\n<p>\u0411\u0435\u0437 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c \u0438 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c.<\/p>\n<h2>3. \u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 context<\/h2>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 context \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c \u0432 \u043e\u0442\u043c\u0435\u043d\u0435 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">req, _ := http.NewRequest(\"GET\", url, nil) client.Do(req)<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() req, _ := http.NewRequestWithContext(ctx, \"GET\", url, nil) client.Do(req)<\/code><\/pre>\n<p>Context \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 context \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c \u0432 \u043e\u0442\u043c\u0435\u043d\u0435 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>context<\/code> \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u043e \u0432 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445. \u0411\u0435\u0437 context \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0440\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0437\u0430\u0432\u0438\u0441\u0430\u043d\u0438\u044f\u043c, \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043d\u044f\u0442\u044b\u043c\u0438 \u043d\u0430 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<h2>4. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 interface{} \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u0433\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func doSomething(data interface{}) {}<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func doSomething(data string) {}<\/code><\/pre>\n<p>\u0421\u0442\u0440\u043e\u0433\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h2>5. \u041f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u042d\u0442\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0431\u0435\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u044b\u0433\u043e\u0434\u044b.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">buf := make([]byte, 0, 1024)<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">buf := []byte{}<\/code><\/pre>\n<p>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h2>6. \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438<\/h2>\n<p>\u0423\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0443\u0445\u0443\u0434\u0448\u0430\u044e\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0443\u0442\u0435\u0447\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 Go?  <\/strong><\/p>\n<p>\u0425\u043e\u0442\u044f Go \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>\u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430 (GC)<\/strong>, \u044d\u0442\u043e <strong>\u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0442\u0435\u043a\u0430\u0442\u044c<\/strong>. <\/p>\n<p>\u0423\u0442\u0435\u0447\u043a\u0430 \u2014 \u044d\u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u043d\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 (\u043a\u0430\u043a \u0432 C), \u0430 \u0441\u043a\u043e\u0440\u0435\u0435 <strong>\u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b<\/strong>, \u0438 <strong>GC \u0438\u0445 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430 \u043d\u0438\u0445 <strong>\u0432\u0441\u0451 \u0435\u0449\u0451 \u0435\u0441\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438<\/strong>.  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u0447\u0438\u043d \u0443\u0442\u0435\u0447\u0435\u043a<\/h4>\n<ol>\n<li>\n<p><strong>\u0413\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0442\u0441\u044f<\/strong> (\u0437\u0430\u0432\u0438\u0441\u043b\u0438, \u0436\u0434\u0443\u0442 \u043f\u043e \u043a\u0430\u043d\u0430\u043b\u0443).<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u044d\u0448 \u0438\u043b\u0438 map, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0438\u0448\u0443\u0442, \u043d\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043e\u0447\u0438\u0449\u0430\u044e\u0442.<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0440\u0435\u0437\u044b \u0438\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0445 \u0447\u0430\u0441\u0442\u044c.<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0438\u043b\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u0435\u0437 <\/strong><code><strong>Close()<\/strong><\/code>.<\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e?<\/h4>\n<ul>\n<li>\n<p>\u0421\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0443\u0442\u0435\u0447\u043a\u0438 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 CPU (GC \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0447\u0430\u0449\u0435).<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c \u0438\u043b\u0438 \u043a\u0440\u0430\u0448\u0438\u0442\u044c\u0441\u044f \u0438\u0437-\u0437\u0430 OOM (Out of Memory).<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435:<\/p>\n<pre><code class=\"go\">import _ \"net\/http\/pprof\"<\/code><\/pre>\n<p>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435 \u0443\u0442\u0435\u0447\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 pprof.<\/p>\n<h4>\u041a\u0430\u043a \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 pprof<\/h4>\n<p><code>pprof<\/code> \u2014 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 <strong>\u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong> \u0432 Go, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c:<\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0438\u043c\u0430\u0442\u044c <strong>heap-\u043f\u0440\u043e\u0444\u0438\u043b\u0438<\/strong> (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438).<\/p>\n<\/li>\n<li>\n<p>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c <strong>goroutine dump<\/strong> \u2014 \u043a\u0430\u043a\u0438\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432\u0438\u0441\u044f\u0442 \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c <strong>CPU, \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438, \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438<\/strong> \u0438 \u0434\u0440.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/strong> \u0447\u0435\u0440\u0435\u0437 <code>go tool pprof<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p> \u041a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c <code>pprof<\/code>  <\/p>\n<pre><code class=\"go\">mport _ \"net\/http\/pprof\" import \"net\/http\"  func main() {     go func() {         http.ListenAndServe(\"localhost:6060\", nil)     }()     \/\/ \u0442\u0432\u043e\u0439 \u043a\u043e\u0434 }<\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435:  <\/p>\n<pre><code class=\"bash\">http:\/\/localhost:6060\/debug\/pprof\/<\/code><\/pre>\n<p> \u0421\u043d\u044f\u0442\u0438\u0435 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u044f  <\/p>\n<pre><code class=\"bash\">go tool pprof http:\/\/localhost:6060\/debug\/pprof\/heap<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435:<\/p>\n<ul>\n<li>\n<p><code>top<\/code> \u2014 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><code>list SomeFunc<\/code> \u2014 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0433\u0434\u0435 \u0432 <code>SomeFunc<\/code> \u0443\u0442\u0435\u0447\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><code>web<\/code> \u2014 \u043e\u0442\u043a\u0440\u044b\u0442\u044c SVG-\u0433\u0440\u0430\u0444 \u0443\u0442\u0435\u0447\u043a\u0438 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 (\u0435\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d Graphviz).<\/p>\n<\/li>\n<\/ul>\n<p> \u041f\u0440\u0438\u043c\u0435\u0440 \u0443\u0442\u0435\u0447\u043a\u0438:  <\/p>\n<pre><code class=\"go\">func leaky() {     ch := make(chan int)     go func() {         for {             ch &lt;- 1 \/\/ \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442 \u2014 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f         }     }() }<\/code><\/pre>\n<p> \u0422\u0430\u043a\u0430\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u0430\u0435\u0442 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430 \u0438 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c.  <\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0439 \u043a\u0430\u043d\u0430\u043b\u044b, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0444\u0430\u0439\u043b\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 <code>context<\/code> \u0441 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0439 <code>pprof<\/code> \u0432 stress-\u0442\u0435\u0441\u0442\u0430\u0445 \u0438\u043b\u0438 \u043f\u0440\u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435.<\/p>\n<\/li>\n<\/ul>\n<h2>7. \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438<\/h2>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 deadlock \u0438\u043b\u0438 panic.<\/p>\n<p><strong>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u0430\u043d\u0430\u043b\u044b \u0432 Go?  <\/strong><\/p>\n<p>\u041a\u0430\u043d\u0430\u043b\u044b (<code>chan<\/code>) \u0432 Go \u2014 \u044d\u0442\u043e <strong>\u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438<\/strong> \u043c\u0435\u0436\u0434\u0443 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043a \u0434\u0440\u0443\u0433\u043e\u0439 <strong>\u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438<\/strong>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438\/\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f.  <\/p>\n<p> \u0412 \u0447\u0451\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430?  <\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a:<\/p>\n<ul>\n<li>\n<p><strong>Deadlock<\/strong> (\u0432\u0437\u0430\u0438\u043c\u043d\u0430\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430).<\/p>\n<\/li>\n<li>\n<p><strong>Panic<\/strong> (\u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0438\u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0438\u0437 \u043d\u0435\u0433\u043e).<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u0442\u0435\u0447\u043a\u0430\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/strong>, \u0435\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u043d\u0435 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f (\u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043d\u0435\u043a\u0443\u0434\u0430 \u043f\u0438\u0441\u0430\u0442\u044c\/\u0447\u0438\u0442\u0430\u0442\u044c).<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e<\/strong>, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0435\u0437 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func main() {     ch := make(chan int) \/\/ \u043d\u0435\u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b      ch &lt;- 1 \/\/ deadlock: main \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d, \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442     fmt.Println(\"unreachable\") }<\/code><\/pre>\n<p> \u0417\u0434\u0435\u0441\u044c <code>main()<\/code> \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f <strong>\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u0430\u043d\u0430\u043b<\/strong>, \u043d\u043e <strong>\u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442<\/strong>, \u0438 \u043e\u043d <strong>\u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0432\u0438\u0441\u0430\u0435\u0442<\/strong> \u2014 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c <strong>deadlock<\/strong>.  <\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func main() {     ch := make(chan int, 1) \/\/ \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b     ch &lt;- 1                 \/\/ \u043d\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0431\u0443\u0444\u0435\u0440 \u0435\u0441\u0442\u044c     fmt.Println(\"done\") }<\/code><\/pre>\n<p>\u0411\u0443\u0444\u0435\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u043e\u0434\u043d\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0431\u0435\u0437 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f<\/strong>.  <\/p>\n<p>\u0418\u043b\u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u0435\u043c  <\/p>\n<pre><code class=\"go\">func main() {     ch := make(chan int)      go func() {         ch &lt;- 1 \/\/ \u044d\u0442\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 main \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c     }()      value := &lt;-ch     fmt.Println(value) }<\/code><\/pre>\n<p>\u0410 \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u0435\u0441\u0442\u044c <strong>\u043f\u043e\u043b\u043d\u044b\u0439 \u0446\u0438\u043a\u043b<\/strong>: \u043e\u0434\u043d\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043f\u0438\u0448\u0435\u0442, \u0434\u0440\u0443\u0433\u0430\u044f \u0447\u0438\u0442\u0430\u0435\u0442 \u2014 \u0432\u0441\u0451 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0438 \u0431\u0435\u0437 deadlock.  <\/p>\n<p> \u0414\u0440\u0443\u0433\u0438\u0435 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438:  <\/p>\n<p> \u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b  <\/p>\n<pre><code class=\"go\">close(ch) ch &lt;- 1 \/\/ panic: send on closed channel<\/code><\/pre>\n<p> \u0427\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 \u2014 \u043d\u043e\u0440\u043c\u0430, \u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c:  <\/p>\n<pre><code class=\"go\">value, ok := &lt;-ch if !ok {     fmt.Println(\\\"\u043a\u0430\u043d\u0430\u043b \u0437\u0430\u043a\u0440\u044b\u0442\\\") }<\/code><\/pre>\n<p> \u041f\u043e\u0447\u0435\u043c\u0443 \u0432\u0430\u0436\u043d\u043e?  <\/p>\n<p>\u041a\u0430\u043d\u0430\u043b\u044b \u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432 Go:<\/p>\n<ul>\n<li>\n<p>\u041e\u043d\u0438 <strong>\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442<\/strong> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0438 \u044d\u0442\u043e \u0444\u0438\u0447\u0430, \u0430 \u043d\u0435 \u0431\u0430\u0433.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 <strong>\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0445 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0443\u0431\u0438\u0442\u044c \u0432\u0441\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443.<\/p>\n<\/li>\n<\/ul>\n<h2>8. \u0417\u0430\u0431\u044b\u0442\u044b\u0435 defer-\u0432\u044b\u0437\u043e\u0432\u044b<\/h2>\n<p>\u0417\u0430\u0431\u044b\u0442\u044b\u0435 defer \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0443\u0442\u0435\u0447\u043a\u0430\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"fsharp\">f, err := os.Open(\"file.txt\") if err != nil { log.Fatal(err) } defer f.Close()<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 defer \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<h3>9. Race conditions<\/h3>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">var mu sync.Mutex mu.Lock() defer mu.Unlock()<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 sync.Mutex \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<h2>10. \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432<\/h2>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func TestAdd(t *testing.T) {}<\/code><\/pre>\n<p>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043f\u0438\u0448\u0438\u0442\u0435 \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<h3>11. \u0417\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 reflection<\/h3>\n<p>Reflection \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 reflection \u0432 Go?  <\/p>\n<p><code>reflection<\/code> \u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 <strong>\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/strong>. \u0412 Go \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u043a\u0435\u0442 <code>reflect<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"go\">import \"reflect\"  func printType(x interface{}) {     v := reflect.ValueOf(x)     fmt.Println(\"Type:\", v.Type()) }<\/code><\/pre>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 reflection \u2014 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e?<\/h4>\n<ol>\n<li>\n<p><strong>\u041f\u043e\u0442\u0435\u0440\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>Reflection \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u044b\u0437\u043e\u0432. \u0412\u0441\u0451, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>reflect<\/code>, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u043f\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0447\u0430\u0441\u0442\u044f\u0445 \u043a\u043e\u0434\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0423\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f<\/strong><\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u0434 \u0441 <code>reflect<\/code> \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u0435\u043d. \u0412\u043c\u0435\u0441\u0442\u043e \u044f\u0432\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u043e\u043b\u044f\u043c \u2014 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <code>reflect.ValueOf<\/code>, <code>Elem()<\/code>, <code>Field(i)<\/code> \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432 \u0438\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u2014 \u043d\u043e\u0447\u043d\u043e\u0439 \u043a\u043e\u0448\u043c\u0430\u0440.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0442\u0435\u0440\u044f \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u043b\u044e\u0441\u043e\u0432 Go \u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u0433\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f. Reflection \u043e\u0431\u0445\u043e\u0434\u0438\u0442 \u044d\u0442\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a runtime-\u043e\u0448\u0438\u0431\u043a\u0430\u043c \u0432\u043c\u0435\u0441\u0442\u043e compile-time.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c reflection?<\/h4>\n<ol>\n<li>\n<p><strong>\u0424\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>encoding\/json<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>reflect<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>ORM-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u0440\u043e\u0434\u0435 <code>gorm<\/code> \u2014 \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043b\u044e\u0431\u044b\u043c\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u2014 \u0438 \u043e\u043d\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 UI, \u0440\u043e\u0443\u0442\u0438\u043d\u0433 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0438\u043b\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u0432\u0442\u043e-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f API \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0418\u0437\u0431\u0435\u0433\u0430\u0439\u0442\u0435:<\/p>\n<pre><code class=\"go\">func setField(x interface{}, fieldName string, value interface{}) {     v := reflect.ValueOf(x).Elem()     f := v.FieldByName(fieldName)     if f.IsValid() &amp;&amp; f.CanSet() {         f.Set(reflect.ValueOf(value))     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0442\u0440\u0443\u0434\u043d\u043e \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c \u0438 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c. \u041b\u0443\u0447\u0448\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u044f\u0432\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c generics (\u0441 Go 1.18+).  <\/p>\n<p> \u041b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c generics (\u0435\u0441\u043b\u0438 \u043c\u043e\u0436\u043d\u043e) <\/p>\n<pre><code class=\"go\">func print[T any](value T) {     fmt.Printf(\"%v\\n\", value) }<\/code><\/pre>\n<p>Generics \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>reflect<\/code> \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.  <\/p>\n<h2>12. \u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u0438\u043d\u0442\u0435\u0440\u043e\u0432 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0442\u0435\u0440\u043e\u0432<\/h2>\n<p>\u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0440\u0430\u0437\u0440\u043e\u0437\u043d\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u0442\u0438\u043b\u044e \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435:<\/p>\n<pre><code class=\"go\">go fmt .\/...<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0439\u0442\u0435 \u0435\u0434\u0438\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u043a\u043e\u0434\u0430.<\/p>\n<h3>13. \u041d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440<\/h3>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">type User struct {     Name  string     Email string     Age   int }  func PrintUser(u User) {     fmt.Println(u.Name, u.Email, u.Age) }  func main() {     user := User{Name: \"Alice\", Email: \"alice@example.com\", Age: 30}     PrintUser(user) \/\/ \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u044f }<\/code><\/pre>\n<p><em>\u0417\u0434\u0435\u0441\u044c <\/em><code><em>User<\/em><\/code><em> \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u043e\u043f\u0438\u044f \u0432\u0441\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/em>  <\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func PrintUser(u *User) {     fmt.Println(u.Name, u.Email, u.Age) }  func main() {     user := User{Name: \"Alice\", Email: \"alice@example.com\", Age: 30}     PrintUser(&amp;user) \/\/ \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c, \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u0442 }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e <code>*User<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u044b.  <\/p>\n<h2>14. \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0438 \u043c\u0435\u0442\u0440\u0438\u043a<\/h2>\n<p>\u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Prometheus:<\/p>\n<pre><code class=\"go\">prometheus.MustRegister(myMetric)<\/code><\/pre>\n<p>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043a\u0446\u0438\u0438 \u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<h2>15.  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 Go  <\/h2>\n<h4>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h4>\n<p>\u0412\u043e \u043c\u043d\u043e\u0433\u0438\u0445 Go-\u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"go\">goCopyEditlog.Println(\"Something went wrong\") log.Printf(\"error: %v\", err)<\/code><\/pre>\n<p><code>log.Println(\"Something went wrong\") log.Printf(\"error: %v\", err) <\/code><\/p>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u2014 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u041e\u0448\u0438\u0431\u043a\u0430 \u043b\u043e\u0433\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u041d\u043e \u0435\u0441\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 DevOps-\u043e\u0431\u0432\u044f\u0437\u043a\u0430, <strong>\u0442\u0430\u043a\u0438\u0435 \u043b\u043e\u0433\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u0431\u043e\u043b\u043e\u0442\u043e<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, <strong>\u043e\u0442\u043a\u0443\u0434\u0430<\/strong> \u043f\u0440\u0438\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435 \u0432\u0438\u0434\u043d\u043e, <strong>\u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e<\/strong><\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Loki, ELK, Datadog)<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0435\u0442 <\/strong><code><strong>request_id<\/strong><\/code> \u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/li>\n<\/ul>\n<h4>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434<\/strong> (JSON \u0438\u043b\u0438 key-value \u0444\u043e\u0440\u043c\u0430\u0442)<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u0440\u043e\u0432\u043d\u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>: debug, info, warning, error, fatal<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/strong>: \u043c\u043e\u0434\u0443\u043b\u044c, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, ID \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (<code>request_id<\/code>), \u043e\u0448\u0438\u0431\u043a\u0430, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><strong>\u041b\u0435\u0433\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f<\/strong> \u0432 Prometheus\/Grafana\/Cloud Logging<\/p>\n<\/li>\n<\/ol>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 request_id<\/h4>\n<p><code>request_id<\/code> \u2014 \u044d\u0442\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 ID \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <code>X-Request-ID<\/code><\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <code>context.Context<\/code><\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043b\u043e\u0433\u0435<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 <strong>\u0442\u0440\u0435\u0439\u0441\u0438\u043d\u0433 \u043e\u0448\u0438\u0431\u043e\u043a<\/strong>, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 logrus<\/h4>\n<pre><code class=\"go\">goCopyEditimport (     log \"github.com\/sirupsen\/logrus\"     \"github.com\/google\/uuid\" )  func logAuthError(userID string, err error, requestID string) {     log.WithFields(log.Fields{         \"request_id\": requestID,         \"module\":     \"auth\",         \"user_id\":    userID,         \"action\":     \"login_attempt\",         \"error\":      err,     }).Error(\"failed to authenticate user\") } <\/code><\/pre>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 zap<\/h4>\n<pre><code class=\"go\">goCopyEditimport (     \"go.uber.org\/zap\"     \"github.com\/google\/uuid\" )  func logAuthError(userID string, err error, requestID string, logger *zap.Logger) {     logger.Error(\"failed to authenticate user\",         zap.String(\"request_id\", requestID),         zap.String(\"module\", \"auth\"),         zap.String(\"user_id\", userID),         zap.String(\"action\", \"login_attempt\"),         zap.Error(err),     ) } <\/code><\/pre>\n<h4>Middleware \u0434\u043b\u044f request_id (Gin-\u043f\u0440\u0438\u043c\u0435\u0440)<\/h4>\n<pre><code class=\"go\">goCopyEditfunc RequestIDMiddleware() gin.HandlerFunc {     return func(c *gin.Context) {         reqID := c.GetHeader(\"X-Request-ID\")         if reqID == \"\" {             reqID = uuid.New().String()         }          c.Set(\"request_id\", reqID)         c.Writer.Header().Set(\"X-Request-ID\", reqID)         c.Next()     } } <\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430\u0445:<\/p>\n<pre><code class=\"go\">goCopyEditfunc LoginHandler(c *gin.Context) {     requestID, _ := c.Get(\"request_id\")     userID := \"123\"     err := errors.New(\"invalid password\")      log.WithFields(log.Fields{         \"request_id\": requestID,         \"module\":     \"auth\",         \"user_id\":    userID,         \"action\":     \"login_attempt\",         \"error\":      err,     }).Error(\"failed to authenticate user\") } <\/code><\/pre>\n<h3>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043b\u043e\u0433 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"go\">jsonCopyEdit{   \"level\": \"error\",   \"msg\": \"failed to authenticate user\",   \"request_id\": \"abcd-1234-efgh-5678\",   \"module\": \"auth\",   \"user_id\": \"123\",   \"action\": \"login_attempt\",   \"error\": \"invalid password\" } <\/code><\/pre>\n<p>\u0418 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e:<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043a\u0430\u0442\u044c \u043b\u043e\u0433\u0438 \u043f\u043e <code>request_id<\/code><\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044f\u043c<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 Observability-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p><strong>\u041f\u043b\u043e\u0445\u0438\u0435 \u043b\u043e\u0433\u0438<\/strong> \u2014 \u044d\u0442\u043e \u043b\u043e\u0433\u0438 \u0431\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0443\u0440\u043e\u0432\u043d\u044f \u0438 ID.<\/p>\n<p><strong>\u0425\u043e\u0440\u043e\u0448\u0438\u0435 \u043b\u043e\u0433\u0438<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u0442 <code>request_id<\/code><\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0443\u0440\u043e\u0432\u043d\u0438 (<code>Info<\/code>, <code>Error<\/code>, <code>Debug<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0442\u0435\u0431\u0435 \u0438 \u043c\u0430\u0448\u0438\u043d\u0430\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0437\u0431\u0435\u0433\u0430\u044f \u044d\u0442\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0441\u043b\u0435\u0434\u0443\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u043c, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0432\u0430\u0448\u0438\u0445 Go-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/904658\/\"> https:\/\/habr.com\/ru\/articles\/904658\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"bordered full-width\"><\/figure>\n<div class=\"floating-image\">\n<p>Go \u2013 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e \u0438\u0437-\u0437\u0430 \u043a\u0430\u0436\u0443\u0449\u0435\u0439\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043c\u043d\u043e\u0433\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c \u0432 production. <\/p>\n<p>\u041d\u0438\u0436\u0435 \u0441\u043e\u0431\u0440\u0430\u043d\u044b 15 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043d\u0430 Golang \u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043f\u043e \u0438\u0445 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e.<\/p>\n<\/div>\n<h2>1. \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>\u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0431\u0430\u0433\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">_, err := ioutil.ReadFile(\"config.json\")<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">data, err := ioutil.ReadFile(\"config.json\") if err != nil {     log.Fatal(err) }<\/code><\/pre>\n<h2>2. \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438<\/h2>\n<p>\u0411\u0435\u0441\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0442\u0435\u0447\u043a\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">for i := 0; i &lt; 1000; i++ {     go doSomething() }<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">var wg sync.WaitGroup for i := 0; i &lt; 1000; i++ {     wg.Add(1)     go func() {         defer wg.Done()         doSomething()     }() } wg.Wait()<\/code><\/pre>\n<pre><code class=\"go\">var wg sync.WaitGroup <\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>wg<\/code> \u0442\u0438\u043f\u0430 <code>sync.WaitGroup<\/code> \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Go, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <strong>\u0436\u0434\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/strong>.  <\/p>\n<pre><code class=\"go\">for i := 0; i &lt; 1000; i++ {     wg.Add(1)     go func() {         defer wg.Done()         doSomething()     }() }<\/code><\/pre>\n<p>\u0426\u0438\u043a\u043b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 <strong>1000 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/strong>.<br \/>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p><code>wg.Add(1)<\/code> \u2014 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a <code>WaitGroup<\/code> \u043d\u0430 1: \u00ab\u041e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u00bb.<\/p>\n<\/li>\n<li>\n<p><code>go func() { ... }()<\/code> \u2014 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u043d\u043e\u0432\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435.<\/p>\n<\/li>\n<li>\n<p><code>defer wg.Done()<\/code> \u2014 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a <code>WaitGroup<\/code> \u043d\u0430 1, \u043a\u043e\u0433\u0434\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p><code>doSomething()<\/code> \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0448\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"go\">wg.Wait()<\/code><\/pre>\n<p> \u042d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 <strong>\u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 1000 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0443\u0442 <\/strong><code><strong>wg.Done()<\/strong><\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043e \u0438\u0445 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f.  <\/p>\n<h4>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e?<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b <strong>\u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447<\/strong>, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0418\u043d\u0430\u0447\u0435 <code>main()<\/code> \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0443\u0441\u043f\u0435\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<h4>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f:<\/h4>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0442\u0435, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u0440\u0443\u0447\u0438\u043b\u0438 1000 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430\u043c \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b, \u043d\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0443, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u043e\u0444\u0438\u0441. <code>WaitGroup<\/code> \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u0433\u0430\u043b\u043e\u0447\u043a\u0430\u043c\u0438: \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u043c, \u0438 \u0442\u044b \u0436\u0434\u0451\u0448\u044c, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u044f\u0442 \u0433\u0430\u043b\u043e\u0447\u043a\u0438.<\/p>\n<p>\u0411\u0435\u0437 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c \u0438 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c.<\/p>\n<h2>3. \u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 context<\/h2>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 context \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c \u0432 \u043e\u0442\u043c\u0435\u043d\u0435 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">req, _ := http.NewRequest(\"GET\", url, nil) client.Do(req)<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() req, _ := http.NewRequestWithContext(ctx, \"GET\", url, nil) client.Do(req)<\/code><\/pre>\n<p>Context \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 context \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c \u0432 \u043e\u0442\u043c\u0435\u043d\u0435 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>context<\/code> \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u043e \u0432 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445. \u0411\u0435\u0437 context \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0440\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0437\u0430\u0432\u0438\u0441\u0430\u043d\u0438\u044f\u043c, \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043d\u044f\u0442\u044b\u043c\u0438 \u043d\u0430 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<h2>4. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 interface{} \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u0433\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func doSomething(data interface{}) {}<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func doSomething(data string) {}<\/code><\/pre>\n<p>\u0421\u0442\u0440\u043e\u0433\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<h2>5. \u041f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u042d\u0442\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0431\u0435\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u044b\u0433\u043e\u0434\u044b.<\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">buf := make([]byte, 0, 1024)<\/code><\/pre>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">buf := []byte{}<\/code><\/pre>\n<p>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h2>6. \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438<\/h2>\n<p>\u0423\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0443\u0445\u0443\u0434\u0448\u0430\u044e\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0443\u0442\u0435\u0447\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 Go?  <\/strong><\/p>\n<p>\u0425\u043e\u0442\u044f Go \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>\u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430 (GC)<\/strong>, \u044d\u0442\u043e <strong>\u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0442\u0435\u043a\u0430\u0442\u044c<\/strong>. <\/p>\n<p>\u0423\u0442\u0435\u0447\u043a\u0430 \u2014 \u044d\u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u043d\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 (\u043a\u0430\u043a \u0432 C), \u0430 \u0441\u043a\u043e\u0440\u0435\u0435 <strong>\u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b<\/strong>, \u0438 <strong>GC \u0438\u0445 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430 \u043d\u0438\u0445 <strong>\u0432\u0441\u0451 \u0435\u0449\u0451 \u0435\u0441\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438<\/strong>.  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u0447\u0438\u043d \u0443\u0442\u0435\u0447\u0435\u043a<\/h4>\n<ol>\n<li>\n<p><strong>\u0413\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0442\u0441\u044f<\/strong> (\u0437\u0430\u0432\u0438\u0441\u043b\u0438, \u0436\u0434\u0443\u0442 \u043f\u043e \u043a\u0430\u043d\u0430\u043b\u0443).<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u044d\u0448 \u0438\u043b\u0438 map, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0438\u0448\u0443\u0442, \u043d\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043e\u0447\u0438\u0449\u0430\u044e\u0442.<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0440\u0435\u0437\u044b \u0438\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0445 \u0447\u0430\u0441\u0442\u044c.<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0438\u043b\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u0435\u0437 <\/strong><code><strong>Close()<\/strong><\/code>.<\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e?<\/h4>\n<ul>\n<li>\n<p>\u0421\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0443\u0442\u0435\u0447\u043a\u0438 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 CPU (GC \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0447\u0430\u0449\u0435).<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c \u0438\u043b\u0438 \u043a\u0440\u0430\u0448\u0438\u0442\u044c\u0441\u044f \u0438\u0437-\u0437\u0430 OOM (Out of Memory).<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435:<\/p>\n<pre><code class=\"go\">import _ \"net\/http\/pprof\"<\/code><\/pre>\n<p>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435 \u0443\u0442\u0435\u0447\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 pprof.<\/p>\n<h4>\u041a\u0430\u043a \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 pprof<\/h4>\n<p><code>pprof<\/code> \u2014 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 <strong>\u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong> \u0432 Go, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c:<\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0438\u043c\u0430\u0442\u044c <strong>heap-\u043f\u0440\u043e\u0444\u0438\u043b\u0438<\/strong> (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438).<\/p>\n<\/li>\n<li>\n<p>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c <strong>goroutine dump<\/strong> \u2014 \u043a\u0430\u043a\u0438\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432\u0438\u0441\u044f\u0442 \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c <strong>CPU, \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438, \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438<\/strong> \u0438 \u0434\u0440.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/strong> \u0447\u0435\u0440\u0435\u0437 <code>go tool pprof<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p> \u041a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c <code>pprof<\/code>  <\/p>\n<pre><code class=\"go\">mport _ \"net\/http\/pprof\" import \"net\/http\"  func main() {     go func() {         http.ListenAndServe(\"localhost:6060\", nil)     }()     \/\/ \u0442\u0432\u043e\u0439 \u043a\u043e\u0434 }<\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435:  <\/p>\n<pre><code class=\"bash\">http:\/\/localhost:6060\/debug\/pprof\/<\/code><\/pre>\n<p> \u0421\u043d\u044f\u0442\u0438\u0435 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u043e\u0444\u0438\u043b\u044f  <\/p>\n<pre><code class=\"bash\">go tool pprof http:\/\/localhost:6060\/debug\/pprof\/heap<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435:<\/p>\n<ul>\n<li>\n<p><code>top<\/code> \u2014 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><code>list SomeFunc<\/code> \u2014 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0433\u0434\u0435 \u0432 <code>SomeFunc<\/code> \u0443\u0442\u0435\u0447\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><code>web<\/code> \u2014 \u043e\u0442\u043a\u0440\u044b\u0442\u044c SVG-\u0433\u0440\u0430\u0444 \u0443\u0442\u0435\u0447\u043a\u0438 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 (\u0435\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d Graphviz).<\/p>\n<\/li>\n<\/ul>\n<p> \u041f\u0440\u0438\u043c\u0435\u0440 \u0443\u0442\u0435\u0447\u043a\u0438:  <\/p>\n<pre><code class=\"go\">func leaky() {     ch := make(chan int)     go func() {         for {             ch &lt;- 1 \/\/ \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442 \u2014 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f         }     }() }<\/code><\/pre>\n<p> \u0422\u0430\u043a\u0430\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u0430\u0435\u0442 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430 \u0438 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c.  <\/p>\n<ul>\n<li>\n<p>\u0412\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0439 \u043a\u0430\u043d\u0430\u043b\u044b, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u0444\u0430\u0439\u043b\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 <code>context<\/code> \u0441 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0439 <code>pprof<\/code> \u0432 stress-\u0442\u0435\u0441\u0442\u0430\u0445 \u0438\u043b\u0438 \u043f\u0440\u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435.<\/p>\n<\/li>\n<\/ul>\n<h2>7. \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438<\/h2>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 deadlock \u0438\u043b\u0438 panic.<\/p>\n<p><strong>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u0430\u043d\u0430\u043b\u044b \u0432 Go?  <\/strong><\/p>\n<p>\u041a\u0430\u043d\u0430\u043b\u044b (<code>chan<\/code>) \u0432 Go \u2014 \u044d\u0442\u043e <strong>\u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438<\/strong> \u043c\u0435\u0436\u0434\u0443 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043a \u0434\u0440\u0443\u0433\u043e\u0439 <strong>\u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438<\/strong>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438\/\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f.  <\/p>\n<p> \u0412 \u0447\u0451\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430?  <\/p>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a:<\/p>\n<ul>\n<li>\n<p><strong>Deadlock<\/strong> (\u0432\u0437\u0430\u0438\u043c\u043d\u0430\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430).<\/p>\n<\/li>\n<li>\n<p><strong>Panic<\/strong> (\u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0438\u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0438\u0437 \u043d\u0435\u0433\u043e).<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u0442\u0435\u0447\u043a\u0430\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/strong>, \u0435\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u043d\u0435 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f (\u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043d\u0435\u043a\u0443\u0434\u0430 \u043f\u0438\u0441\u0430\u0442\u044c\/\u0447\u0438\u0442\u0430\u0442\u044c).<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e<\/strong>, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0435\u0437 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func main() {     ch := make(chan int) \/\/ \u043d\u0435\u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b      ch &lt;- 1 \/\/ deadlock: main \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d, \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442     fmt.Println(\"unreachable\") }<\/code><\/pre>\n<p> \u0417\u0434\u0435\u0441\u044c <code>main()<\/code> \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f <strong>\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u0430\u043d\u0430\u043b<\/strong>, \u043d\u043e <strong>\u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442<\/strong>, \u0438 \u043e\u043d <strong>\u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0432\u0438\u0441\u0430\u0435\u0442<\/strong> \u2014 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c <strong>deadlock<\/strong>.  <\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func main() {     ch := make(chan int, 1) \/\/ \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b     ch &lt;- 1                 \/\/ \u043d\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0431\u0443\u0444\u0435\u0440 \u0435\u0441\u0442\u044c     fmt.Println(\"done\") }<\/code><\/pre>\n<p>\u0411\u0443\u0444\u0435\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u043e\u0434\u043d\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0431\u0435\u0437 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f<\/strong>.  <\/p>\n<p>\u0418\u043b\u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u0435\u043c  <\/p>\n<pre><code class=\"go\">func main() {     ch := make(chan int)      go func() {         ch &lt;- 1 \/\/ \u044d\u0442\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 main \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c     }()      value := &lt;-ch     fmt.Println(value) }<\/code><\/pre>\n<p>\u0410 \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u0435\u0441\u0442\u044c <strong>\u043f\u043e\u043b\u043d\u044b\u0439 \u0446\u0438\u043a\u043b<\/strong>: \u043e\u0434\u043d\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043f\u0438\u0448\u0435\u0442, \u0434\u0440\u0443\u0433\u0430\u044f \u0447\u0438\u0442\u0430\u0435\u0442 \u2014 \u0432\u0441\u0451 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0438 \u0431\u0435\u0437 deadlock.  <\/p>\n<p> \u0414\u0440\u0443\u0433\u0438\u0435 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438:  <\/p>\n<p> \u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b  <\/p>\n<pre><code class=\"go\">close(ch) ch &lt;- 1 \/\/ panic: send on closed channel<\/code><\/pre>\n<p> \u0427\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 \u2014 \u043d\u043e\u0440\u043c\u0430, \u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c:  <\/p>\n<pre><code class=\"go\">value, ok := &lt;-ch if !ok {     fmt.Println(\\\"\u043a\u0430\u043d\u0430\u043b \u0437\u0430\u043a\u0440\u044b\u0442\\\") }<\/code><\/pre>\n<p> \u041f\u043e\u0447\u0435\u043c\u0443 \u0432\u0430\u0436\u043d\u043e?  <\/p>\n<p>\u041a\u0430\u043d\u0430\u043b\u044b \u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432 Go:<\/p>\n<ul>\n<li>\n<p>\u041e\u043d\u0438 <strong>\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442<\/strong> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0438 \u044d\u0442\u043e \u0444\u0438\u0447\u0430, \u0430 \u043d\u0435 \u0431\u0430\u0433.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 <strong>\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0445 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0443\u0431\u0438\u0442\u044c \u0432\u0441\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443.<\/p>\n<\/li>\n<\/ul>\n<h2>8. \u0417\u0430\u0431\u044b\u0442\u044b\u0435 defer-\u0432\u044b\u0437\u043e\u0432\u044b<\/h2>\n<p>\u0417\u0430\u0431\u044b\u0442\u044b\u0435 defer \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0443\u0442\u0435\u0447\u043a\u0430\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"fsharp\">f, err := os.Open(\"file.txt\") if err != nil { log.Fatal(err) } defer f.Close()<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 defer \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<h3>9. Race conditions<\/h3>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">var mu sync.Mutex mu.Lock() defer mu.Unlock()<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 sync.Mutex \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<h2>10. \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432<\/h2>\n<p>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">func TestAdd(t *testing.T) {}<\/code><\/pre>\n<p>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043f\u0438\u0448\u0438\u0442\u0435 \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<h3>11. \u0417\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 reflection<\/h3>\n<p>Reflection \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 reflection \u0432 Go?  <\/p>\n<p><code>reflection<\/code> \u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 <strong>\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/strong>. \u0412 Go \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u043a\u0435\u0442 <code>reflect<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"go\">import \"reflect\"  func printType(x interface{}) {     v := reflect.ValueOf(x)     fmt.Println(\"Type:\", v.Type()) }<\/code><\/pre>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 reflection \u2014 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e?<\/h4>\n<ol>\n<li>\n<p><strong>\u041f\u043e\u0442\u0435\u0440\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>Reflection \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u044b\u0437\u043e\u0432. \u0412\u0441\u0451, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>reflect<\/code>, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u043f\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0447\u0430\u0441\u0442\u044f\u0445 \u043a\u043e\u0434\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0423\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f<\/strong><\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u0434 \u0441 <code>reflect<\/code> \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u0435\u043d. \u0412\u043c\u0435\u0441\u0442\u043e \u044f\u0432\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u043e\u043b\u044f\u043c \u2014 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <code>reflect.ValueOf<\/code>, <code>Elem()<\/code>, <code>Field(i)<\/code> \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432 \u0438\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u2014 \u043d\u043e\u0447\u043d\u043e\u0439 \u043a\u043e\u0448\u043c\u0430\u0440.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0442\u0435\u0440\u044f \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u043b\u044e\u0441\u043e\u0432 Go \u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u0433\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f. Reflection \u043e\u0431\u0445\u043e\u0434\u0438\u0442 \u044d\u0442\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a runtime-\u043e\u0448\u0438\u0431\u043a\u0430\u043c \u0432\u043c\u0435\u0441\u0442\u043e compile-time.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c reflection?<\/h4>\n<ol>\n<li>\n<p><strong>\u0424\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>encoding\/json<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>reflect<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>ORM-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u0440\u043e\u0434\u0435 <code>gorm<\/code> \u2014 \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043b\u044e\u0431\u044b\u043c\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u2014 \u0438 \u043e\u043d\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 UI, \u0440\u043e\u0443\u0442\u0438\u043d\u0433 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0438\u043b\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u0432\u0442\u043e-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f API \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0418\u0437\u0431\u0435\u0433\u0430\u0439\u0442\u0435:<\/p>\n<pre><code class=\"go\">func setField(x interface{}, fieldName string, value interface{}) {     v := reflect.ValueOf(x).Elem()     f := v.FieldByName(fieldName)     if f.IsValid() &amp;&amp; f.CanSet() {         f.Set(reflect.ValueOf(value))     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-457499","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/457499","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=457499"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/457499\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=457499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=457499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=457499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}