{"id":280688,"date":"2016-11-09T14:55:13","date_gmt":"2016-11-09T11:55:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=280688"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=280688","title":{"rendered":"50 \u043e\u0442\u0442\u0435\u043d\u043a\u043e\u0432 Go: \u043b\u043e\u0432\u0443\u0448\u043a\u0438, \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438 \u0438 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/64f\/bc1\/8a3\/64fbc18a37fa4dd884eeb8200dd5c8dd.jpg\"\/><\/p>\n<p>  Go \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0439 \u044f\u0437\u044b\u043a. \u041d\u043e \u0432 \u043d\u0451\u043c, \u043a\u0430\u043a \u0438 \u0432 \u043b\u044e\u0431\u044b\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438. \u0418 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0438\u0437 \u043d\u0438\u0445 \u0441\u0430\u043c Go \u043d\u0435 \u0432\u0438\u043d\u043e\u0432\u0430\u0442. \u041e\u0434\u043d\u0438 \u2014 \u044d\u0442\u043e \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0438\u0437-\u0437\u0430 \u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0438 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 \u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0432\u0438\u043a\u0438, \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0435 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438, \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u0431\u043b\u043e\u0433\u0430\u0445 \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u0442\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u0435\u0439 \u0441\u0442\u0430\u043d\u0443\u0442 \u0434\u043b\u044f \u0432\u0430\u0441 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b. \u041d\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0430\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442, \u0438 \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u043e\u0432\u0438\u0447\u043e\u043a \u0432 Go, \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043d\u0435\u043c\u0430\u043b\u043e \u0447\u0430\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0431\u044b \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u043d\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u043a\u043e\u0434\u0430. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u0438 Go 1.5 \u0438 \u043d\u0438\u0436\u0435.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h1>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h1>\n<p>  \u0423\u0440\u043e\u0432\u0435\u043d\u044c: \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439 \u043d\u043e\u0432\u0438\u0447\u043e\u043a<\/p>\n<p>  1. <a href=\"#1\">\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u0444\u0438\u0433\u0443\u0440\u043d\u0443\u044e \u0441\u043a\u043e\u0431\u043a\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435<\/a><br \/>  2. <a href=\"#2\">\u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/a><br \/>  3. <a href=\"#3\">\u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b<\/a><br \/>  4. <a href=\"#4\">\u041a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a><br \/>  5. <a href=\"#5\">\u041f\u0435\u0440\u0435\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0439<\/a><br \/>  6. <a href=\"#6\">\u041d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0435\u0439<\/a><br \/>  7. <a href=\"#7\">\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0441\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/a><br \/>  8. <a href=\"#8\">\u041d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c nil \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430<\/a><br \/>  9. <a href=\"#9\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 nil-\u0441\u043b\u0430\u0439\u0441\u043e\u0432 (slice) \u0438 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446 (map)<\/a><br \/>  10. <a href=\"#10\">\u0401\u043c\u043a\u043e\u0441\u0442\u044c \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446<\/a><br \/>  11. <a href=\"#11\">\u0421\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c nil<\/a><br \/>  12. <a href=\"#12\">\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a><br \/>  13. <a href=\"#13\">\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 range \u0432 \u0441\u043b\u0430\u0439\u0441\u0430\u0445 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445<\/a><br \/>  14. <a href=\"#14\">\u041e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432<\/a><br \/>  15. <a href=\"#15\">\u041e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043b\u044e\u0447\u0430\u043c \u0432 map<\/a><br \/>  16. <a href=\"#16\">\u041d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a<\/a><br \/>  17. <a href=\"#17\">\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0432 \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441\u044b (Byte Slices), \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442<\/a><br \/>  18. <a href=\"#18\">\u0421\u0442\u0440\u043e\u043a\u0438 \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430<\/a><br \/>  19. <a href=\"#19\">\u0421\u0442\u0440\u043e\u043a\u0438 \u2014 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u0435\u043a\u0441\u0442 \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 UTF-8<\/a><br \/>  20. <a href=\"#20\">\u0414\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a<\/a><br \/>  21. <a href=\"#21\">\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u043f\u044f\u0442\u0430\u044f \u0432 \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u0430\u0445 slice\/array\/map<\/a><br \/>  22. <a href=\"#22\">log.Fatal \u0438 log.Panic \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u044e\u0442<\/a><br \/>  23. <a href=\"#23\">\u041d\u0435\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><br \/>  24. <a href=\"#24\">\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 range<\/a><br \/>  25. <a href=\"#25\">\u0418\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446 (map) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f for range<\/a><br \/>  26. <a href=\"#26\">\u0421\u0431\u043e\u0439\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 switch<\/a><br \/>  27. <a href=\"#27\">\u0418\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u0434\u0435\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u044b<\/a><br \/>  28. <a href=\"#28\">\u041f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0439 NOT-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<\/a><br \/>  29. <a href=\"#29\">\u0420\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/a><br \/>  30. <a href=\"#30\">\u041d\u0435\u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u043d\u0435 \u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0442\u0441\u044f<\/a><br \/>  31. <a href=\"#31\">\u0412\u044b\u0445\u043e\u0434 \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/a><br \/>  32. <a href=\"#32\">\u041f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0432 \u043d\u0435\u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f<\/a><br \/>  33. <a href=\"#33\">\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a panic<\/a><br \/>  34. <a href=\"#34\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u00abnil\u00bb-\u043a\u0430\u043d\u0430\u043b\u043e\u0432<\/a><br \/>  35. <a href=\"#35\">\u041c\u0435\u0442\u043e\u0434\u044b, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><\/p>\n<p>  \u0423\u0440\u043e\u0432\u0435\u043d\u044c: \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u043d\u043e\u0432\u0438\u0447\u043e\u043a<\/p>\n<p>  36. <a href=\"#36\">\u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0442\u0435\u043b\u0430 HTTP-\u043e\u0442\u0432\u0435\u0442\u0430<\/a><br \/>  37. <a href=\"#37\">\u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439<\/a><br \/>  38. <a href=\"#38\">\u0414\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (unmarshalling) JSON-\u0447\u0438\u0441\u0435\u043b \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/a><br \/>  39. <a href=\"#39\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 struct, array, slice \u0438 map<\/a><br \/>  40. <a href=\"#40\">\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 panic<\/a><br \/>  41. <a href=\"#41\">\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0435\u0439 \u0432 slice, array \u0438 map \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 for range<\/a><br \/>  42. <a href=\"#42\">\u00ab\u0421\u043a\u0440\u044b\u0442\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\u00bb \u0432 \u0441\u043b\u0430\u0439\u0441\u0430\u0445<\/a><br \/>  43. <a href=\"#43\">\u00ab\u041f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435\u00bb \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u043b\u0430\u0439\u0441\u0430\u0445<\/a><br \/>  44. <a href=\"#44\">\u00ab\u0423\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435\u00bb \u0441\u043b\u0430\u0439\u0441\u044b<\/a><br \/>  45. <a href=\"#45\">\u041c\u0435\u0442\u043e\u0434\u044b \u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432<\/a><br \/>  46. <a href=\"#46\">\u041a\u0430\u043a \u0432\u044b\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u043a\u043e\u0434\u043e\u0432\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 for switch \u0438 for select<\/a><br \/>  47. <a href=\"#47\">\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 for<\/a><br \/>  48. <a href=\"#48\">\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0431\u043b\u043e\u043a\u0430 defer (Deferred Function Call Argument Evaluation)<\/a><br \/>  49. <a href=\"#49\">\u0412\u044b\u0437\u043e\u0432 \u0431\u043b\u043e\u043a\u0430 defer<\/a><br \/>  50. <a href=\"#50\">\u041e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0442\u0438\u043f\u043e\u0432<\/a><br \/>  51. <a href=\"#51\">\u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0438 \u0443\u0442\u0435\u0447\u043a\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432<\/a><\/p>\n<p>  \u0423\u0440\u043e\u0432\u0435\u043d\u044c: \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u043d\u043e\u0432\u0438\u0447\u043e\u043a<\/p>\n<p>  52. <a href=\"#52\">\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 (pointer receiver), \u043a \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/a><br \/>  53. <a href=\"#53\">\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/a><br \/>  54. <a href=\"#54\">nil-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438 nil-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/a><br \/>  55. <a href=\"#55\">\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0435\u043a\u0430 \u0438 \u043a\u0443\u0447\u0438<\/a><br \/>  56. <a href=\"#56\">GOMAXPROCS, \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c (concurrency) \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c<\/a><br \/>  57. <a href=\"#57\">\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438<\/a><br \/>  58. <a href=\"#58\">\u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430\u043c (Preemptive Scheduling)<\/a><\/p>\n<p>  <a name=\"1\"><\/a><\/p>\n<h1>1. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u0444\u0438\u0433\u0443\u0440\u043d\u0443\u044e \u0441\u043a\u043e\u0431\u043a\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435<\/h1>\n<p>  \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c, \u0433\u0434\u0435 \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c. Go \u0432\u044b\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u0440\u0430\u0432\u0438\u043b\u0430. \u0417\u0430 \u044d\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u0442\u043e\u0447\u043a\u0438 \u0441 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 (\u0442\u043e\u0447\u043a\u0430 \u0441 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0431\u0435\u0437 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439). \u0414\u0430, \u0432 Go \u0435\u0441\u0442\u044c \u0442\u043e\u0447\u043a\u0430 \u0441 \u0437\u0430\u043f\u044f\u0442\u043e\u0439!<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main()   { \/\/ \u043e\u0448\u0438\u0431\u043a\u0430, \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u0444\u0438\u0433\u0443\u0440\u043d\u0443\u044e \u0441\u043a\u043e\u0431\u043a\u0443 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443     fmt.Println(&quot;hello there!&quot;) } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox826898458\/main.go:6: syntax error: unexpected semicolon or newline before { <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       fmt.Println(&quot;works!&quot;) } <\/code><\/pre>\n<p>  <a name=\"2\"><\/a><\/p>\n<h1>2. \u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/h1>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0442\u043e \u043a\u043e\u0434 \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435: \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043d\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u0432\u0430\u0448 \u043a\u043e\u0434 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0435\u0451 \u0433\u0434\u0435-\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0443\u0433\u043e\u0434\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  var gvar int \/\/ not an error  func main() {       var one int   \/\/ \u043e\u0448\u0438\u0431\u043a\u0430, \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f     two := 2      \/\/ \u043e\u0448\u0438\u0431\u043a\u0430, \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f     var three int \/\/ \u043e\u0448\u0438\u0431\u043a\u0430, \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 3 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435     three = 3      func(unused string) {         fmt.Println(&quot;Unused arg. No compile error&quot;)     }(&quot;what?&quot;) } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox473116179\/main.go:6: one declared and not used \/tmp\/sandbox473116179\/main.go:7: two declared and not used \/tmp\/sandbox473116179\/main.go:8: three declared and not used <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       var one int     _ = one      two := 2     fmt.Println(two)      var three int     three = 3     one = three      var four int     four = four } <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<\/p>\n<p>  <a name=\"3\"><\/a><\/p>\n<h1>3. \u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b<\/h1>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0435 \u043f\u0430\u043a\u0435\u0442 \u0438 \u043f\u043e\u0442\u043e\u043c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0438\u0437 \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0442\u043e \u043a\u043e\u0434 \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u00ab_\u00bb \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0435\u0433\u043e \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u00ab_\u00bb \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0430\u0439\u0434-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;log&quot;     &quot;time&quot; )  func main() {   } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox627475386\/main.go:4: imported and not used: &quot;fmt&quot; \/tmp\/sandbox627475386\/main.go:5: imported and not used: &quot;log&quot; \/tmp\/sandbox627475386\/main.go:6: imported and not used: &quot;time&quot; <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (       _ &quot;fmt&quot;     &quot;log&quot;     &quot;time&quot; )  var _ = log.Println  func main() {       _ = time.Now } <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u043b\u0438 \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b. \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 <a href=\"http:\/\/godoc.org\/golang.org\/x\/tools\/cmd\/goimports\">goimports<\/a>.<\/p>\n<p>  <a name=\"4\"><\/a><\/p>\n<h1>4. \u041a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/h1>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  myvar := 1 \/\/ \u043e\u0448\u0438\u0431\u043a\u0430  func main() {   } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox265716165\/main.go:3: non-declaration statement outside function body <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  var myvar = 1  func main() {   } <\/code><\/pre>\n<p>  <a name=\"5\"><\/a><\/p>\n<h1>5. \u041f\u0435\u0440\u0435\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0439<\/h1>\n<p>  \u0412 \u043e\u0434\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (multi-variable declarations), \u0441\u0440\u0435\u0434\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u0430 \u2014 \u043d\u043e\u0432\u0430\u044f. \u041f\u0435\u0440\u0435\u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u0431\u043b\u043e\u043a\u0435, \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043a\u0440\u044b\u0442\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f (shadowed variable).<br \/>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       one := 0     one := 1 \/\/ \u043e\u0448\u0438\u0431\u043a\u0430 } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox706333626\/main.go:5: no new variables on left side of := <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       one := 0     one, two := 1,2      one,two = two,one } <\/code><\/pre>\n<p>  <a name=\"6\"><\/a><\/p>\n<h1>6. \u041d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0435\u0439<\/h1>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (     &quot;fmt&quot; )  type info struct {     result int }  func work() (int,error) {       return 13,nil     }  func main() {     var data info    data.result, err := work() \/\/ \u043e\u0448\u0438\u0431\u043a\u0430   fmt.Printf(&quot;info: %+v\\n&quot;,data) } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">prog.go:18: non-name data.result on left side of := <\/code><\/pre>\n<p>  \u0425\u043e\u0442\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c Go \u0443\u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b\u0438 \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043d\u0430\u0434\u0435\u044f\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u044b: \u0420\u043e\u0431\u0443 \u041f\u0430\u0439\u043a\u0443 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0432\u0441\u0451 \u00ab\u043a\u0430\u043a \u0435\u0441\u0442\u044c\u00bb. \u0412\u0430\u043c \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0418\u043b\u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0439\u0442\u0435 \u0432\u0441\u0435 \u0441\u0432\u043e\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (     &quot;fmt&quot; )  type info struct {     result int }  func work() (int,error) {       return 13,nil     }  func main() {     var data info    var err error   data.result, err = work() \/\/ ok   if err != nil {     fmt.Println(err)     return   }    fmt.Printf(&quot;info: %+v\\n&quot;,data) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: info: {result:13} } <\/code><\/pre>\n<p>  <a name=\"7\"><\/a><\/p>\n<h1>7. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0441\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/h1>\n<p>  \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u0435\u043d (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043f\u0440\u0438\u0448\u0451\u043b \u0432 Go \u0438\u0437 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432), \u0447\u0442\u043e \u0435\u0433\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0437\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u044d\u0442\u0443 \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u043d\u043e\u0432\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u043a\u043e\u0434\u0430, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u043d\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := 1     fmt.Println(x)     \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 1     {         fmt.Println(x) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 1         x := 2         fmt.Println(x) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 2     }     fmt.Println(x)     \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 1 (\u043f\u043b\u043e\u0445\u043e, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e 2) } <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0434\u0430\u0436\u0435 \u0441\u0440\u0435\u0434\u0438 \u043e\u043f\u044b\u0442\u043d\u044b\u0445 Go-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432. \u0415\u0451 \u043b\u0435\u0433\u043a\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0438 \u0442\u0440\u0443\u0434\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c. \u0414\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 vet. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d\u0430 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u043a\u0440\u044b\u0442\u043e\u0441\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u043b\u0430\u0433 <code>-shadow: go tool vet -shadow your_file.go<\/code><\/p>\n<p>  <a name=\"8\"><\/a><\/p>\n<h1>8. \u041d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c nil \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430<\/h1>\n<p>  \u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 <code>nil<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u00ab\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb (zero value) \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439, \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446 (map), \u0441\u043b\u0430\u0439\u0441\u043e\u0432 (slices) \u0438 \u043a\u0430\u043d\u0430\u043b\u043e\u0432. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0437\u0430\u0434\u0430\u0442\u044c \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435 \u0441\u0443\u043c\u0435\u0435\u0442 \u0443\u0433\u0430\u0434\u0430\u0442\u044c \u0442\u0438\u043f.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       var x = nil \/\/ \u043e\u0448\u0438\u0431\u043a\u0430      _ = x } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox188239583\/main.go:4: use of untyped nil <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       var x interface{} = nil      _ = x } <\/code><\/pre>\n<p>  <a name=\"9\"><\/a><\/p>\n<h1>9. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 nil-\u0441\u043b\u0430\u0439\u0441\u043e\u0432 (slice) \u0438 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446 (map)<\/h1>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 <code>nil<\/code>-\u0441\u043b\u0430\u0439\u0441, \u043d\u043e \u0435\u0441\u043b\u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u0442\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a runtime panic.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       var s []int     s = append(s,1) } <\/code><\/pre>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       var m map[string]int     m[&quot;one&quot;] = 1 \/\/ \u043e\u0448\u0438\u0431\u043a\u0430  } <\/code><\/pre>\n<p>  <a name=\"10\"><\/a><\/p>\n<h1>10. \u0401\u043c\u043a\u043e\u0441\u0442\u044c \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446<\/h1>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0451\u043c\u043a\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446, \u043d\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a \u043d\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>cap()<\/code>.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       m := make(map[string]int,99)     cap(m) \/\/ \u043e\u0448\u0438\u0431\u043a\u0430 } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox326543983\/main.go:5: invalid argument m (type map[string]int) for cap <\/code><\/pre>\n<p>  <a name=\"11\"><\/a><\/p>\n<h1>11. \u0421\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c nil<\/h1>\n<p>  \u042d\u0442\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u0430\u043c\u0435\u043d\u044c \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u044e\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c <code>nil<\/code>-\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       var x string = nil \/\/ \u043e\u0448\u0438\u0431\u043a\u0430      if x == nil { \/\/ \u043e\u0448\u0438\u0431\u043a\u0430         x = &quot;default&quot;     } } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox630560459\/main.go:4: cannot use nil as type string in assignment \/tmp\/sandbox630560459\/main.go:6: invalid operation: x == nil (mismatched types string and nil) <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<p>  package main<\/p>\n<pre><code class=\"go\">func main() {       var x string \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e &quot;&quot; (\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435)      if x == &quot;&quot; {         x = &quot;default&quot;     } } <\/code><\/pre>\n<p>  <a name=\"12\"><\/a><\/p>\n<h1>12. \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h1>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u043d\u0430 \u0421\/\u0421++, \u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0434\u043b\u044f \u0432\u0430\u0441 \u2014 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0442\u0443 \u0436\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0412 Go \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0442\u0430\u043a \u0447\u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u043a\u043e\u043f\u0438\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := [3]int{1,2,3}      func(arr [3]int) {         arr[0] = 7         fmt.Println(arr) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [7 2 3]     }(x)      fmt.Println(x) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [1 2 3] (\u043f\u043b\u043e\u0445\u043e, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e [7 2 3]) } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0442\u0438\u043f\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := [3]int{1,2,3}      func(arr *[3]int) {         (*arr)[0] = 7         fmt.Println(arr) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 &[7 2 3]     }(&x)      fmt.Println(x) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [7 2 3] } <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0441\u043b\u0430\u0439\u0441\u044b. \u0425\u043e\u0442\u044f \u0432\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u043e\u043f\u0438\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u043b\u0430\u0439\u0441\u0430, \u0442\u0430 \u0432\u0441\u0451 \u0435\u0449\u0451 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := []int{1,2,3}      func(arr []int) {         arr[0] = 7         fmt.Println(arr) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [7 2 3]     }(x)      fmt.Println(x) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [7 2 3] } <\/code><\/pre>\n<p>  <a name=\"13\"><\/a><\/p>\n<h1>13. \u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 range \u0432 \u0441\u043b\u0430\u0439\u0441\u0430\u0445 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445<\/h1>\n<p>  \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u043a \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c <code>for-in<\/code> \u0438\u043b\u0438 <code>foreach<\/code> \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041d\u043e \u0432 Go \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>range<\/code> \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f: \u043f\u0435\u0440\u0432\u043e\u0435 \u2014 \u044d\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 (item index), \u0430 \u0432\u0442\u043e\u0440\u043e\u0435 \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 (item data).<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := []string{&quot;a&quot;,&quot;b&quot;,&quot;c&quot;}      for v := range x {         fmt.Println(v) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 0, 1, 2     } } <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := []string{&quot;a&quot;,&quot;b&quot;,&quot;c&quot;}      for _, v := range x {         fmt.Println(v) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 a, b, c     } } <\/code><\/pre>\n<p>  <a name=\"14\"><\/a><\/p>\n<h1>14. \u041e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432<\/h1>\n<p>  \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e Go \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438 \u0441\u043b\u0430\u0439\u0441\u044b? \u041d\u0435\u0442, \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u0425\u043e\u0442\u044f \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0438 \u0441\u043b\u0430\u0439\u0441\u044b \u0438\u0437 \u0441\u043b\u0430\u0439\u0441\u043e\u0432. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u2014 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432, \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u0438\u0437 \u00ab\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445\u00bb \u0441\u043b\u0430\u0439\u0441\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u0438\u0437 \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u00ab\u0441 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438\u00bb.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b, \u0442\u043e \u043f\u0440\u0438 \u0438\u0445 \u0440\u043e\u0441\u0442\u0435 \u0432\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442\u0435 \u0437\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0433\u0440\u0430\u043d\u0438\u0446 \u0438 \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u0438\u0437 \u00ab\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445\u00bb \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0448\u0430\u0433\u043e\u0432. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0441\u043b\u0430\u0439\u0441, \u0430 \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0441\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0441\u043b\u0430\u0439\u0441\u044b. \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0441\u043b\u0430\u0439\u0441\u044b \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430. \u0418\u0445 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c, \u043d\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044f \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<pre><code class=\"go\">package main  func main() {       x := 2     y := 4      table := make([][]int,x)     for i:= range table {         table[i] = make([]int,y)     } } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u0438\u0437 \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u00ab\u0441 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438\u00bb \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u0440\u0451\u0445 \u0448\u0430\u0433\u043e\u0432. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043b\u0430\u0439\u0441, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439 \u0440\u043e\u043b\u044c \u00ab\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u00bb \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (raw data). \u0417\u0430\u0442\u0435\u043c \u2014 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0441\u043b\u0430\u0439\u0441. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0441\u043b\u0430\u0439\u0441\u043e\u0432, \u043f\u0435\u0440\u0435\u043d\u0430\u0440\u0435\u0437\u0430\u044f \u0441\u043b\u0430\u0439\u0441 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       h, w := 2, 4      raw := make([]int,h*w)     for i := range raw {         raw[i] = i     }     fmt.Println(raw,&raw[4])     \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: [0 1 2 3 4 5 6 7] &lt;ptr_addr_x&gt;      table := make([][]int,h)     for i:= range table {         table[i] = raw[i*w:i*w + w]     }      fmt.Println(table,&table[1][0])     \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: [[0 1 2 3] [4 5 6 7]] &lt;ptr_addr_x&gt; } <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043d\u0430 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438 \u0441\u043b\u0430\u0439\u0441\u044b, \u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441, \u0441\u0443\u0434\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443, \u0443 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0438\u0437\u043a\u0438\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442.<\/p>\n<p>  <a name=\"15\"><\/a><\/p>\n<h1>15. \u041e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043b\u044e\u0447\u0430\u043c \u0432 map<\/h1>\n<p>  \u042d\u0442\u0443 \u043e\u0448\u0438\u0431\u043a\u0443 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <code>nil<\/code>-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445). \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 <code>nil<\/code>, \u0435\u0441\u043b\u0438 \u00ab\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb \u0434\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 <code>nil<\/code>. \u041d\u043e \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435 (map record), \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u00ab\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb. \u041d\u043e \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0434\u0451\u0436\u043d\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u043b\u0435\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0433\u0434\u0435 \u00ab\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb \u2014 false). \u0421\u0430\u043c\u044b\u0439 \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u0437\u043d\u0430\u0442\u044c, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c, \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435.<\/p>\n<p>  \u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := map[string]string{&quot;one&quot;:&quot;a&quot;,&quot;two&quot;:&quot;&quot;,&quot;three&quot;:&quot;c&quot;}      if v := x[&quot;two&quot;]; v == &quot;&quot; { \/\/ \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e         fmt.Println(&quot;no entry&quot;)     } } <\/code><\/pre>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := map[string]string{&quot;one&quot;:&quot;a&quot;,&quot;two&quot;:&quot;&quot;,&quot;three&quot;:&quot;c&quot;}      if _,ok := x[&quot;two&quot;]; !ok {         fmt.Println(&quot;no entry&quot;)     } } <\/code><\/pre>\n<p>  <a name=\"16\"><\/a><\/p>\n<h1>16. \u041d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a<\/h1>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0421\u0442\u0440\u043e\u043a\u0438 \u2014 \u044d\u0442\u043e \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441\u044b (byte slices), \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := &quot;text&quot;     x[0] = 'T'      fmt.Println(x) } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox305565531\/main.go:7: cannot assign to x[0] <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := &quot;text&quot;     xbytes := []byte(x)     xbytes[0] = 'T'      fmt.Println(string(xbytes)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 Text } <\/code><\/pre>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0431\u0430\u0439\u0442\u043e\u0432. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0443\u0447\u0448\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0441\u043b\u0430\u0439\u0441 \u0438\u0437 \u00ab\u0440\u0443\u043d\u00bb (rune). \u041d\u043e \u0434\u0430\u0436\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u0438\u0437 \u00ab\u0440\u0443\u043d\u00bb \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0442 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0443\u043d, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b \u0430\u043f\u043e\u0441\u0442\u0440\u043e\u0444\u0430 (grave accent). \u0422\u0430\u043a\u0430\u044f \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u0438\u0440\u043e\u0434\u0430 \u00ab\u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432\u00bb \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 Go \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0431\u0430\u0439\u0442\u043e\u0432.<\/p>\n<p>  <a name=\"17\"><\/a><\/p>\n<h1>17. \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0432 \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441\u044b (Byte Slices), \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442<\/h1>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441 (\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442), \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u043f\u043e\u043b\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u043d\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f (cast operation), \u043a\u0430\u043a \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u043d\u0430\u0440\u0435\u0437\u043a\u0430 (reslicing), \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043b\u0430\u0439\u0441\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043c\u0430\u0441\u0441\u0438\u0432, \u0437\u0430\u043d\u044f\u0442\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441\u043e\u043c.<\/p>\n<p>  \u0412 Go \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0438\u0437 <code>[]byte<\/code> \u0432 <code>string<\/code> \u0438 \u0438\u0437 <code>string<\/code> \u0432 <code>[]byte<\/code>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0445 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 (\u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 todo).<\/p>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043b\u044e\u0447\u0438 <code>[]byte<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u0445 <code>map[string]: m[string(key)]<\/code>.<\/p>\n<p>  \u0412\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 <code>for range<\/code>, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 <code>[]byte: for i,v := range []byte(str) {...}<\/code>.<\/p>\n<p>  <a name=\"18\"><\/a><\/p>\n<h1>18. \u0421\u0442\u0440\u043e\u043a\u0438 \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430<\/h1>\n<p>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043a <b>\u0441\u0442\u0440\u043e\u043a\u0435<\/b>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (byte value), \u0430 \u043d\u0435 \u0441\u0438\u043c\u0432\u043e\u043b (\u043a\u0430\u043a \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445).<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       x := &quot;text&quot;     fmt.Println(x[0]) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 116     fmt.Printf(&quot;%T&quot;,x[0]) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 uint8 } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u00ab\u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u00bb (\u043a\u043e\u0434\u043e\u0432\u044b\u043c \u0442\u043e\u0447\u043a\u0430\u043c\/\u0440\u0443\u043d\u0430\u043c Unicode), \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>for range<\/code>. \u0422\u0430\u043a\u0436\u0435 \u0432\u0430\u043c \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 unicode\/utf8 \u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439 utf8string (golang.org\/x\/exp\/utf8string). utf8string \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>At()<\/code>. \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c <b>\u0441\u0442\u0440\u043e\u043a\u0443<\/b> \u0432 \u0441\u043b\u0430\u0439\u0441 \u0440\u0443\u043d (slice of runes).<\/p>\n<p>  <a name=\"19\"><\/a><\/p>\n<h1>19. \u0421\u0442\u0440\u043e\u043a\u0438 \u2014 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u0435\u043a\u0441\u0442 \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 UTF-8<\/h1>\n<p>  \u0421\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0432\u0438\u0434\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 UTF-8. \u0417\u0434\u0435\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0431\u0430\u0439\u0442\u043e\u0432. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 UTF-8, \u2014 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b. \u041d\u043e \u0434\u0430\u0436\u0435 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u0442\u0440\u043e\u043a\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>ValidString()<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 unicode\/utf8.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;unicode\/utf8&quot; )  func main() {       data1 := &quot;ABC&quot;     fmt.Println(utf8.ValidString(data1)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: true      data2 := &quot;A\\xfeC&quot;     fmt.Println(utf8.ValidString(data2)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: false } <\/code><\/pre>\n<p>  <a name=\"20\"><\/a><\/p>\n<h1>20. \u0414\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a<\/h1>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u043d\u0430 Python \u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">data = u''   print(len(data)) #prints: 1   <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Go, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u0441 \u0443\u0434\u0438\u0432\u0438\u0442\u044c.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       data := &quot;&quot;     fmt.Println(len(data)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 3 } <\/code><\/pre>\n<p>  \u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>len()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435 \u0441\u0438\u043c\u0432\u043e\u043b, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 Unicode-\u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0432 Python.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 Go, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>RuneCountInString()<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 unicode\/utf8.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;unicode\/utf8&quot; )  func main() {       data := &quot;&quot;     fmt.Println(utf8.RuneCountInString(data)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 1 <\/code><\/pre>\n<p>  \u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>RuneCountInString()<\/code> \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0443\u043d.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;unicode\/utf8&quot; )  func main() {       data := &quot;e\u0301&quot;     fmt.Println(len(data))                    \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 3     fmt.Println(utf8.RuneCountInString(data)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 2 } <\/code><\/pre>\n<p>  <a name=\"21\"><\/a><\/p>\n<h1>21. \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u043f\u044f\u0442\u0430\u044f \u0432 \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u0430\u0445 slice\/array\/map<\/h1>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       x := []int{     1,     2 \/\/ error     }     _ = x } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox367520156\/main.go:6: syntax error: need trailing comma before newline in composite literal \/tmp\/sandbox367520156\/main.go:8: non-declaration statement outside function body \/tmp\/sandbox367520156\/main.go:9: syntax error: unexpected } <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  func main() {       x := []int{     1,     2,     }     x = x      y := []int{3,4,} \/\/ \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435\u0442     y = y } <\/code><\/pre>\n<p>  \u0412\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0435\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u044f\u0442\u0443\u044e \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443.<\/p>\n<p>  <a name=\"22\"><\/a><\/p>\n<h1>22. log.Fatal \u0438 log.Panic \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u044e\u0442<\/h1>\n<p>  \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u0434\u043b\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u043f\u0430\u043a\u0435\u0442 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Go \u0434\u0435\u043b\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435. \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Fatal*()<\/code> \u0438 <code>Panic*()<\/code>, \u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u043e.<\/p>\n<pre><code class=\"go\">package main  import &quot;log&quot;  func main() {       log.Fatalln(&quot;Fatal Level: log entry&quot;) \/\/ \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f     log.Println(&quot;Normal Level: log entry&quot;) } <\/code><\/pre>\n<p>  <a name=\"23\"><\/a><\/p>\n<h1>23. \u041d\u0435\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<\/h1>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Go \u043d\u0430\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u044c (concurrency), \u043d\u043e \u0432 \u0438\u0445 \u0447\u0438\u0441\u043b\u043e \u043d\u0435 \u0432\u0445\u043e\u0434\u044f\u0442 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 (concurrency safe). \u0412\u044b \u0441\u0430\u043c\u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442\u0435 \u0437\u0430 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439. \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0438 \u043a\u0430\u043d\u0430\u043b\u044b, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u0430\u043a\u0435\u0442 sync, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <a name=\"24\"><\/a><\/p>\n<h1>24. \u0418\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 range<\/h1>\n<p>  \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 (\u043f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439 <code>range<\/code>) \u2014 \u044d\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u0430\u0439\u0442\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u00ab\u0441\u0438\u043c\u0432\u043e\u043b\u0430\u00bb (\u043a\u043e\u0434\u043e\u0432\u0430\u044f \u0442\u043e\u0447\u043a\u0430\/\u0440\u0443\u043d\u0430 Unicode), \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u044b\u0439 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438. \u042d\u0442\u043e \u043d\u0435 \u0438\u043d\u0434\u0435\u043a\u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u00ab\u0441\u0438\u043c\u0432\u043e\u043b\u0430\u00bb, \u043a\u0430\u043a \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0440\u0443\u043d\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 norm (golang.org\/x\/text\/unicode\/norm).<\/p>\n<p>  \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f <code>for range<\/code> \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u0442\u0435\u043a\u0441\u0442 \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 UTF-8. \u0415\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u044e\u0442 \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0439\u0442\u043e\u0432, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0440\u0443\u043d\u044b 0xfffd (\u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0437\u0430\u043c\u0435\u043d\u044b Unicode), \u0430 \u043d\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0415\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043d\u0435 UTF-8), \u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0439\u0442\u0435 \u0438\u0445 \u0432 \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441\u044b.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       data := &quot;A\\xfe\\x02\\xff\\x04&quot;     for _,v := range data {         fmt.Printf(&quot;%#x &quot;,v)     }     \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 0x41 0xfffd 0x2 0xfffd 0x4 (\u043d\u0435\u0445\u043e\u0440\u043e\u0448\u043e)      fmt.Println()     for _,v := range []byte(data) {         fmt.Printf(&quot;%#x &quot;,v)     }     \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 0x41 0xfe 0x2 0xff 0x4 (\u0445\u043e\u0440\u043e\u0448\u043e) } <\/code><\/pre>\n<p>  <a name=\"25\"><\/a><\/p>\n<h1>25. \u0418\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446 (map) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f for range<\/h1>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u0430\u043c\u0435\u043d\u044c \u043d\u0430\u0442\u044b\u043a\u0430\u044e\u0442\u0441\u044f \u0442\u0435, \u043a\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043a\u043b\u044e\u0447\u0430). \u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c. \u0421\u0440\u0435\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (runtime) Go \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0451 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435, \u0440\u0430\u043d\u0434\u043e\u043c\u0438\u0437\u0438\u0440\u0443\u044f \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u0435\u0439 \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u0430\u0451\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u044f\u0442\u044c) \u043f\u043e\u0434\u0440\u044f\u0434.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       m := map[string]int{&quot;one&quot;:1,&quot;two&quot;:2,&quot;three&quot;:3,&quot;four&quot;:4}     for k,v := range m {         fmt.Println(k,v)     } } <\/code><\/pre>\n<p>  \u0410 \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Go Playground (https:\/\/play.golang.org\/), \u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043e\u0434 \u043d\u0435 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u0432\u044b \u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435.<\/p>\n<p>  <a name=\"26\"><\/a><\/p>\n<h1>26. \u0421\u0431\u043e\u0439\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 switch<\/h1>\n<p>  \u0411\u043b\u043e\u043a\u0438 <code>case<\/code> \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 <code>switch<\/code> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f (break). \u0412 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u0440\u0443\u0433\u043e\u0435: \u043f\u0435\u0440\u0435\u0445\u043e\u0434 (fall through) \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0431\u043b\u043e\u043a\u0443 <code>case<\/code>.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       isSpace := func(ch byte) bool {         switch(ch) {         case ' ': \/\/ \u043e\u0448\u0438\u0431\u043a\u0430         case '\\t':             return true         }         return false     }      fmt.Println(isSpace('\\t')) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 true (\u0445\u043e\u0440\u043e\u0448\u043e)     fmt.Println(isSpace(' '))  \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 false (\u043f\u043b\u043e\u0445\u043e) } <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0431\u043b\u043e\u043a\u0438 case \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f <code>fallthrough<\/code> \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430. \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0430\u0448\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>switch<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432 \u0431\u043b\u043e\u043a\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u043f\u0438\u0441\u043a\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       isSpace := func(ch byte) bool {         switch(ch) {         case ' ', '\\t':             return true         }         return false     }      fmt.Println(isSpace('\\t')) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 true (\u0445\u043e\u0440\u043e\u0448\u043e)     fmt.Println(isSpace(' '))  \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 true (\u0445\u043e\u0440\u043e\u0448\u043e) } <\/code><\/pre>\n<p>  <a name=\"27\"><\/a><\/p>\n<h1>27. \u0418\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u0434\u0435\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u044b<\/h1>\n<p>  \u0412\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0435\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041d\u043e \u0432 Go \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0445 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438. \u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0430 \u044d\u0442\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       data := []int{1,2,3}     i := 0     ++i \/\/ error     fmt.Println(data[i++]) \/\/ \u043e\u0448\u0438\u0431\u043a\u0430 } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox101231828\/main.go:8: syntax error: unexpected ++ \/tmp\/sandbox101231828\/main.go:9: syntax error: unexpected ++, expecting : <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       data := []int{1,2,3}     i := 0     i++     fmt.Println(data[i]) } <\/code><\/pre>\n<p>  <a name=\"28\"><\/a><\/p>\n<h1>28. \u041f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0439 NOT-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<\/h1>\n<p>  \u0412\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0441\u0438\u043c\u0432\u043e\u043b ~ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043d\u0430\u0440\u043d\u043e\u0439 NOT-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (aka \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, bitwise complement), \u043e\u0434\u043d\u0430\u043a\u043e \u0432 Go \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f XOR-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 (^).<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       fmt.Println(~2) \/\/ \u043e\u0448\u0438\u0431\u043a\u0430 } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox965529189\/main.go:6: the bitwise complement operator is ^ <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       var d uint8 = 2     fmt.Printf(&quot;%08b\\n&quot;,^d) } <\/code><\/pre>\n<p>  \u041a\u043e\u0433\u043e-\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0443\u0442\u0430\u0442\u044c, \u0447\u0442\u043e ^ \u0432 Go \u2014 \u044d\u0442\u043e XOR-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435, \u0432\u044b\u0440\u0430\u0436\u0430\u0439\u0442\u0435 \u0443\u043d\u0430\u0440\u043d\u0443\u044e NOT-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>NOT 0x02<\/code>) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 XOR-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>0x02 XOR 0xff<\/code>). \u042d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442, \u043f\u043e\u0447\u0435\u043c\u0443 ^ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0443\u043d\u0430\u0440\u043d\u043e\u0439 NOT-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0432 Go \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 AND NOT (&#038;^), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0437\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 NOT. AND NOT \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f\/\u0445\u0430\u043a \u0440\u0430\u0434\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <code>A AND (NOT B)<\/code> \u0431\u0435\u0437 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043e\u043a.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       var a uint8 = 0x82     var b uint8 = 0x02     fmt.Printf(&quot;%08b [A]\\n&quot;,a)     fmt.Printf(&quot;%08b [B]\\n&quot;,b)      fmt.Printf(&quot;%08b (NOT B)\\n&quot;,^b)     fmt.Printf(&quot;%08b ^ %08b = %08b [B XOR 0xff]\\n&quot;,b,0xff,b ^ 0xff)      fmt.Printf(&quot;%08b ^ %08b = %08b [A XOR B]\\n&quot;,a,b,a ^ b)     fmt.Printf(&quot;%08b & %08b = %08b [A AND B]\\n&quot;,a,b,a & b)     fmt.Printf(&quot;%08b &^%08b = %08b [A 'AND NOT' B]\\n&quot;,a,b,a &^ b)     fmt.Printf(&quot;%08b&(^%08b)= %08b [A AND (NOT B)]\\n&quot;,a,b,a & (^b)) } <\/code><\/pre>\n<p>  <a name=\"29\"><\/a><\/p>\n<h1>29. \u0420\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/h1>\n<p>  \u041f\u043e\u043c\u0438\u043c\u043e \u00ab\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0445\u00bb (bit clear) \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 (&#038;^), \u0432 Go \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u044f\u0437\u044b\u043a\u0430\u043c\u0438. \u041d\u043e \u0438\u0445 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u044b \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       fmt.Printf(&quot;0x2 & 0x2 + 0x4 -&gt; %#x\\n&quot;,0x2 & 0x2 + 0x4)     \/\/prints: 0x2 & 0x2 + 0x4 -&gt; 0x6     \/\/Go:    (0x2 & 0x2) + 0x4     \/\/C++:    0x2 & (0x2 + 0x4) -&gt; 0x2      fmt.Printf(&quot;0x2 + 0x2 &lt;&lt; 0x1 -&gt; %#x\\n&quot;,0x2 + 0x2 &lt;&lt; 0x1)     \/\/prints: 0x2 + 0x2 &lt;&lt; 0x1 -&gt; 0x6     \/\/Go:     0x2 + (0x2 &lt;&lt; 0x1)     \/\/C++:   (0x2 + 0x2) &lt;&lt; 0x1 -&gt; 0x8      fmt.Printf(&quot;0xf | 0x2 ^ 0x2 -&gt; %#x\\n&quot;,0xf | 0x2 ^ 0x2)     \/\/prints: 0xf | 0x2 ^ 0x2 -&gt; 0xd     \/\/Go:    (0xf | 0x2) ^ 0x2     \/\/C++:    0xf | (0x2 ^ 0x2) -&gt; 0xf } <\/code><\/pre>\n<p>  <a name=\"30\"><\/a><\/p>\n<h1>30. \u041d\u0435\u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u043d\u0435 \u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0442\u0441\u044f<\/h1>\n<p>  \u041f\u043e\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 (struct fields), \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0431\u0443\u043a\u0432, \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f (JSON, XML, GON \u0438 \u0442. \u0434.), \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u0440\u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0432 \u044d\u0442\u0438\u0445 \u043d\u0435\u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044f\u0445 \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;encoding\/json&quot; )  type MyData struct {       One int     two string }  func main() {       in := MyData{1,&quot;two&quot;}     fmt.Printf(&quot;%#v\\n&quot;,in) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 main.MyData{One:1, two:&quot;two&quot;}      encoded,_ := json.Marshal(in)     fmt.Println(string(encoded)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 {&quot;One&quot;:1}      var out MyData     json.Unmarshal(encoded,&out)      fmt.Printf(&quot;%#v\\n&quot;,out) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 main.MyData{One:1, two:&quot;&quot;} } <\/code><\/pre>\n<p>  <a name=\"31\"><\/a><\/p>\n<h1>31. \u0412\u044b\u0445\u043e\u0434 \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/h1>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0430\u0448\u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d. \u041d\u043e\u0432\u0438\u0447\u043a\u0438 \u0447\u0430\u0441\u0442\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0437\u0430\u0431\u044b\u0432\u0430\u044e\u0442. \u0412\u0441\u0435 \u043a\u043e\u0433\u0434\u0430-\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u2014 \u0432 \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u044b\u0434\u043d\u043e\u0433\u043e.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  func main() {       workerCount := 2      for i := 0; i &lt; workerCount; i++ {         go doit(i)     }     time.Sleep(1 * time.Second)     fmt.Println(&quot;all done!&quot;) }  func doit(workerId int) {       fmt.Printf(&quot;[%v] is running\\n&quot;,workerId)     time.Sleep(3 * time.Second)     fmt.Printf(&quot;[%v] is done\\n&quot;,workerId) } <\/code><\/pre>\n<p>  \u0412\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435:<\/p>\n<pre><code class=\"go\">[0] is running  [1] is running  all done! <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u043e \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u2014 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>WaitGroup<\/code>. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0441\u0435\u0445 \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d. \u0415\u0441\u043b\u0438 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043e\u043b\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0441 \u0446\u0438\u043a\u043b\u0430\u043c\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0442\u043e \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043a\u0430\u043a-\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0440\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c. \u041c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u043a\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>kill<\/code>. \u0418\u043b\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043d\u0430\u043b\u044b, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435: \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0442\u043e\u043c.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;sync&quot; )  func main() {       var wg sync.WaitGroup     done := make(chan struct{})     workerCount := 2      for i := 0; i &lt; workerCount; i++ {         wg.Add(1)         go doit(i,done,wg)     }      close(done)     wg.Wait()     fmt.Println(&quot;all done!&quot;) }  func doit(workerId int,done &lt;-chan struct{},wg sync.WaitGroup) {       fmt.Printf(&quot;[%v] is running\\n&quot;,workerId)     defer wg.Done()     &lt;- done     fmt.Printf(&quot;[%v] is done\\n&quot;,workerId) } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435:<\/p>\n<pre><code class=\"go\">[0] is running  [0] is done  [1] is running  [1] is done <\/code><\/pre>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0435, \u0432\u0441\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u0417\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e! \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0438 \u044d\u0442\u043e:<\/p>\n<pre><code class=\"bash\">fatal error: all goroutines are asleep - deadlock! <\/code><\/pre>\n<p>  \u041d\u0435\u0445\u043e\u0440\u043e\u0448\u043e! \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442? \u041e\u0442\u043a\u0443\u0434\u0430 \u0432\u0437\u044f\u043b\u0430\u0441\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430? \u0412\u0435\u0434\u044c \u0432\u0441\u0435 \u0432\u044b\u0448\u043b\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 <code>wg.Done()<\/code>. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  \u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u043e\u043f\u0438\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>WaitGroup<\/code>. \u0418 \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 <code>wg.Done()<\/code>, \u044d\u0442\u043e \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>WaitGroup<\/code> \u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;sync&quot; )  func main() {       var wg sync.WaitGroup     done := make(chan struct{})     wq := make(chan interface{})     workerCount := 2      for i := 0; i &lt; workerCount; i++ {         wg.Add(1)         go doit(i,wq,done,&wg)     }      for i := 0; i &lt; workerCount; i++ {         wq &lt;- i     }      close(done)     wg.Wait()     fmt.Println(&quot;all done!&quot;) }  func doit(workerId int, wq &lt;-chan interface{},done &lt;-chan struct{},wg *sync.WaitGroup) {       fmt.Printf(&quot;[%v] is running\\n&quot;,workerId)     defer wg.Done()     for {         select {         case m := &lt;- wq:             fmt.Printf(&quot;[%v] m =&gt; %v\\n&quot;,workerId,m)         case &lt;- done:             fmt.Printf(&quot;[%v] is done\\n&quot;,workerId)             return         }     } } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.<\/p>\n<p>  <a name=\"32\"><\/a><\/p>\n<h1>32. \u041f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0432 \u043d\u0435\u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f<\/h1>\n<p>  \u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d, \u043f\u043e\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0430\u0448\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u0430\u0448\u0438\u043d\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0434, \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0449\u0430\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       ch := make(chan string)      go func() {         for m := range ch {             fmt.Println(&quot;processed:&quot;,m)         }     }()      ch &lt;- &quot;cmd.1&quot;     ch &lt;- &quot;cmd.2&quot; \/\/ \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e } <\/code><\/pre>\n<p>  <a name=\"33\"><\/a><\/p>\n<h1>33. \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a panic<\/h1>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>ok<\/code> \u0432 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 (receive statement) \u0441\u0442\u0430\u043d\u0435\u0442 <code>false<\/code>, \u0447\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0430\u0442\u0441\u044f, \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>ok<\/code> \u0441\u0442\u0430\u043d\u0435\u0442 <code>false<\/code>.<\/p>\n<p>  \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a panic. \u042d\u0442\u043e \u0437\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043d\u043e \u043e\u043d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u043f\u0440\u0438 \u043f\u0440\u0438\u0451\u043c\u0435.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  func main() {       ch := make(chan int)     for i := 0; i &lt; 3; i++ {         go func(idx int) {             ch &lt;- (idx + 1) * 2         }(i)     }      \/\/ get the first result     fmt.Println(&lt;-ch)     close(ch) \/\/\u043d\u0435\u0445\u043e\u0440\u043e\u0448\u043e (\u0443 \u0432\u0430\u0441 \u0432\u0441\u0451 \u0435\u0449\u0451 \u0435\u0441\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u0438)     \/\/ do other work     time.Sleep(2 * time.Second) } <\/code><\/pre>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u2014 \u0438\u043b\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044c\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0430\u043d\u0430\u043b.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0431\u0430\u0433\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044f \u0447\u0435\u0440\u0435\u0437 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u043e\u0442\u043c\u0435\u043d\u044b (special cancellation channel) \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0430\u0431\u043e\u0447\u0438\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c, \u0447\u0442\u043e \u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  func main() {       ch := make(chan int)     done := make(chan struct{})     for i := 0; i &lt; 3; i++ {         go func(idx int) {             select {             case ch &lt;- (idx + 1) * 2: fmt.Println(idx,&quot;sent result&quot;)             case &lt;- done: fmt.Println(idx,&quot;exiting&quot;)             }         }(i)     }      \/\/ get first result     fmt.Println(&quot;result:&quot;,&lt;-ch)     close(done)     \/\/ do other work     time.Sleep(3 * time.Second) } <\/code><\/pre>\n<p>  <a name=\"34\"><\/a><\/p>\n<h1>34. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u00abnil\u00bb-\u043a\u0430\u043d\u0430\u043b\u043e\u0432<\/h1>\n<p>  \u0412 \u043a\u0430\u043d\u0430\u043b\u0435 <code>nil<\/code> \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438 \u043f\u0440\u0438\u0451\u043c\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043d\u043e \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u043e\u043c \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  func main() {       var ch chan int     for i := 0; i &lt; 3; i++ {         go func(idx int) {             ch &lt;- (idx + 1) * 2         }(i)     }      \/\/ get first result     fmt.Println(&quot;result:&quot;,&lt;-ch)     \/\/ do other work     time.Sleep(2 * time.Second) } <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 runtime \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>fatal error: all goroutines are asleep - deadlock!<\/code><\/p>\n<p>  \u042d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u043e\u0432 <code>case<\/code> \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 <code>select<\/code>.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;   import &quot;time&quot;  func main() {       inch := make(chan int)     outch := make(chan int)      go func() {         var in &lt;- chan int = inch         var out chan &lt;- int         var val int         for {             select {             case out &lt;- val:                 out = nil                 in = inch             case val = &lt;- in:                 out = outch                 in = nil             }         }     }()      go func() {         for r := range outch {             fmt.Println(&quot;result:&quot;,r)         }     }()      time.Sleep(0)     inch &lt;- 1     inch &lt;- 2     time.Sleep(3 * time.Second) } <\/code><\/pre>\n<p>  <a name=\"35\"><\/a><\/p>\n<h1>35. \u041c\u0435\u0442\u043e\u0434\u044b, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h1>\n<p>  \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0415\u0441\u043b\u0438 \u043e\u043d\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\/\u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u043e\u043f\u0438\u044e \u0432\u0430\u0448\u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 (receiver argument). \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u0438\u043d\u044f\u0442\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u043d\u0435 \u043f\u043e\u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b (map) \u0438\u043b\u0438 \u0441\u043b\u0430\u0439\u0441\u0430 \u0438 \u0432\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u2014 \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  type data struct {       num int     key *string     items map[string]bool }  func (this *data) pmethod() {       this.num = 7 }  func (this data) vmethod() {       this.num = 8     *this.key = &quot;v.key&quot;     this.items[&quot;vmethod&quot;] = true }  func main() {       key := &quot;key.1&quot;     d := data{1,&key,make(map[string]bool)}      fmt.Printf(&quot;num=%v key=%v items=%v\\n&quot;,d.num,*d.key,d.items)     \/\/ prints num=1 key=key.1 items=map[]      d.pmethod()     fmt.Printf(&quot;num=%v key=%v items=%v\\n&quot;,d.num,*d.key,d.items)     \/\/ prints num=7 key=key.1 items=map[]      d.vmethod()     fmt.Printf(&quot;num=%v key=%v items=%v\\n&quot;,d.num,*d.key,d.items)     \/\/ prints num=7 key=v.key items=map[vmethod:true] } <\/code><\/pre>\n<p>  <a name=\"36\"><\/a><\/p>\n<h1>36. \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0442\u0435\u043b\u0430 HTTP-\u043e\u0442\u0432\u0435\u0442\u0430<\/h1>\n<p>  \u0414\u0435\u043b\u0430\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 HTTP-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e HTTP-\u043e\u0442\u0432\u0435\u0442\u0430. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430, \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0435\u0433\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u044d\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0438 \u043a \u043f\u0443\u0441\u0442\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u0430\u043c. \u041e \u043d\u0438\u0445 \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u0431\u044b\u0442\u044c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c.<\/p>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u043e\u0432\u0438\u0447\u043a\u0438 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430, \u043d\u043e \u0432 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;net\/http&quot;     &quot;io\/ioutil&quot; )  func main() {       resp, err := http.Get(&quot;https:\/\/api.ipify.org?format=json&quot;)     defer resp.Body.Close()\/\/ \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e     if err != nil {         fmt.Println(err)         return     }      body, err := ioutil.ReadAll(resp.Body)     if err != nil {         fmt.Println(err)         return     }      fmt.Println(string(body)) } <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u043c\u0438 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0431\u043e\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>resp<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <code>nil<\/code>, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a runtime panic.<\/p>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u0430 <code>defer<\/code> \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u0441\u0442\u0438 HTTP-\u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;net\/http&quot;     &quot;io\/ioutil&quot; )  func main() {       resp, err := http.Get(&quot;https:\/\/api.ipify.org?format=json&quot;)     if err != nil {         fmt.Println(err)         return     }      defer resp.Body.Close()\/\/ \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e, \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 :-)     body, err := ioutil.ReadAll(resp.Body)     if err != nil {         fmt.Println(err)         return     }      fmt.Println(string(body)) } <\/code><\/pre>\n<p>  \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0441\u0431\u043e\u0438 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>resp<\/code> \u0431\u0443\u0434\u0435\u0442 <code>nil<\/code>, \u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>err \u2014 non-nil<\/code>. \u041d\u043e \u043f\u0440\u0438 \u0441\u0431\u043e\u0435 \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u0438 \u043e\u0431\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 <code>non-nil<\/code>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435 \u0443\u0442\u0435\u0447\u043a\u0438.<\/p>\n<p>  \u0415\u0451 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432\u044b\u0437\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0442\u0435\u043b \u043e\u0442\u0432\u0435\u0442\u043e\u0432 <code>non-nil<\/code> \u0432 \u0431\u043b\u043e\u043a\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 <code>defer<\/code> \u0434\u043b\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0442\u0435\u043b \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0431\u043e\u0439\u043d\u044b\u0445 \u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;net\/http&quot;     &quot;io\/ioutil&quot; )  func main() {       resp, err := http.Get(&quot;https:\/\/api.ipify.org?format=json&quot;)     if resp != nil {         defer resp.Body.Close()     }      if err != nil {         fmt.Println(err)         return     }      body, err := ioutil.ReadAll(resp.Body)     if err != nil {         fmt.Println(err)         return     }      fmt.Println(string(body)) } <\/code><\/pre>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>resp.Body.Close()<\/code> \u0442\u0430\u043a\u0436\u0435 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0438 \u043e\u0442\u043a\u043b\u043e\u043d\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0442\u0435\u043b \u043e\u0442\u0432\u0435\u0442\u043e\u0432. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0435\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <code>keep alive<\/code>. \u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e HTTP-\u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0442\u043e HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043a\u0440\u044b\u0442\u043e. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e\u0442 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u0430\u043c\u0435\u043d\u044c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0432 Go 1.5.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0442\u043e \u0432 \u043a\u043e\u043d\u0446\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<pre><code class=\"go\">_, err = io.Copy(ioutil.Discard, resp.Body) <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u0432\u0441\u0451 \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 JSON API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"go\">json.NewDecoder(resp.Body).Decode(&data) <\/code><\/pre>\n<p>  <a name=\"37\"><\/a><\/p>\n<h1>37. \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439<\/h1>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440\u044b \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c\u0438 (\u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 HTTP 1.1 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <code>keep alive<\/code>). \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f HTTP-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0438\u0442 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u043a\u0435\u0442\u044b \/ \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0437\u0430\u0434\u0430\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>true<\/code> \u0432 \u043f\u043e\u043b\u0435 <code>Close<\/code> \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0430 <code>Connection<\/code> \u0438 \u0437\u0430\u0434\u0430\u0442\u044c \u0435\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>close<\/code>. \u0426\u0435\u043b\u0435\u0432\u043e\u0439 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c <code>Connection: close<\/code>. \u041a\u043e\u0433\u0434\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0435\u0433\u043e \u0443\u0432\u0438\u0434\u0438\u0442, \u043e\u043d\u0430 \u0437\u0430\u043a\u0440\u043e\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;net\/http&quot;     &quot;io\/ioutil&quot; )  func main() {       req, err := http.NewRequest(&quot;GET&quot;,&quot;http:\/\/golang.org&quot;,nil)     if err != nil {         fmt.Println(err)         return     }      req.Close = true     \/\/or do this:     \/\/req.Header.Add(&quot;Connection&quot;, &quot;close&quot;)      resp, err := http.DefaultClient.Do(req)     if resp != nil {         defer resp.Body.Close()     }      if err != nil {         fmt.Println(err)         return     }      body, err := ioutil.ReadAll(resp.Body)     if err != nil {         fmt.Println(err)         return     }      fmt.Println(len(string(body))) } <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e HTTP-\u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;net\/http&quot;     &quot;io\/ioutil&quot; )  func main() {       tr := &http.Transport{DisableKeepAlives: true}     client := &http.Client{Transport: tr}      resp, err := client.Get(&quot;http:\/\/golang.org&quot;)     if resp != nil {         defer resp.Body.Close()     }      if err != nil {         fmt.Println(err)         return     }      fmt.Println(resp.StatusCode)      body, err := ioutil.ReadAll(resp.Body)     if err != nil {         fmt.Println(err)         return     }      fmt.Println(len(string(body))) } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0435\u0440 \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c. \u041d\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0448\u043b\u0451\u0442 \u043e\u0434\u0438\u043d-\u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043b\u0438\u043c\u0438\u0442 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u0427\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u2014 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <a name=\"38\"><\/a><\/p>\n<h1>38. \u0414\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (unmarshalling) JSON-\u0447\u0438\u0441\u0435\u043b \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/h1>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0435\/\u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0435 JSON-\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, Go \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 JSON \u043a\u0430\u043a \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 <code>float64<\/code>. \u0417\u043d\u0430\u0447\u0438\u0442, \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 panic:<\/p>\n<pre><code class=\"go\">package main  import (     &quot;encoding\/json&quot;   &quot;fmt&quot; )  func main() {     var data = []byte(`{&quot;status&quot;: 200}`)    var result map[string]interface{}   if err := json.Unmarshal(data, &result); err != nil {     fmt.Println(&quot;error:&quot;, err)     return   }    var status = result[&quot;status&quot;].(int) \/\/ \u043e\u0448\u0438\u0431\u043a\u0430   fmt.Println(&quot;status value:&quot;,status) } <\/code><\/pre>\n<p>  Runtime Panic:<\/p>\n<p>  <code>panic: interface conversion: interface is float64, not int<\/code> <\/p>\n<p>  \u0415\u0441\u043b\u0438 JSON-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435, \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432.<\/p>\n<ul>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 \u043a\u0430\u043a \u0435\u0441\u0442\u044c \ud83d\ude42<\/li>\n<li>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 \u0432 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0430\u043c \u043d\u0443\u0436\u0435\u043d.\n<pre><code class=\"go\">package main  import (     &quot;encoding\/json&quot;   &quot;fmt&quot; )  func main() {     var data = []byte(`{&quot;status&quot;: 200}`)    var result map[string]interface{}   if err := json.Unmarshal(data, &result); err != nil {     fmt.Println(&quot;error:&quot;, err)     return   }    var status = uint64(result[&quot;status&quot;].(float64)) \/\/ \u0445\u043e\u0440\u043e\u0448\u043e   fmt.Println(&quot;status value:&quot;,status) } <\/code><\/pre>\n<p>  <\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f <code>Decoder<\/code> \u0434\u043b\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 JSON \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f JSON-\u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>Number<\/code>.\n<pre><code class=\"go\">package main  import (     &quot;encoding\/json&quot;   &quot;bytes&quot;   &quot;fmt&quot; )  func main() {     var data = []byte(`{&quot;status&quot;: 200}`)    var result map[string]interface{}   var decoder = json.NewDecoder(bytes.NewReader(data))   decoder.UseNumber()    if err := decoder.Decode(&result); err != nil {     fmt.Println(&quot;error:&quot;, err)     return   }    var status,_ = result[&quot;status&quot;].(json.Number).Int64() \/\/ \u0445\u043e\u0440\u043e\u0448\u043e   fmt.Println(&quot;status value:&quot;,status) } <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>Number<\/code>, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0442\u0438\u043f:<\/p>\n<pre><code class=\"go\">package main  import (     &quot;encoding\/json&quot;   &quot;bytes&quot;   &quot;fmt&quot; )  func main() {     var data = []byte(`{&quot;status&quot;: 200}`)    var result map[string]interface{}   var decoder = json.NewDecoder(bytes.NewReader(data))   decoder.UseNumber()    if err := decoder.Decode(&result); err != nil {     fmt.Println(&quot;error:&quot;, err)     return   }    var status uint64   if err := json.Unmarshal([]byte(result[&quot;status&quot;].(json.Number).String()), &status); err != nil {     fmt.Println(&quot;error:&quot;, err)     return   }    fmt.Println(&quot;status value:&quot;,status) } <\/code><\/pre>\n<p>  <\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f <code>struct<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 (maps) \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0430\u043c \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0442\u0438\u043f.\n<pre><code class=\"go\">package main  import (     &quot;encoding\/json&quot;   &quot;bytes&quot;   &quot;fmt&quot; )  func main() {     var data = []byte(`{&quot;status&quot;: 200}`)    var result struct {     Status uint64 `json:&quot;status&quot;`   }    if err := json.NewDecoder(bytes.NewReader(data)).Decode(&result); err != nil {     fmt.Println(&quot;error:&quot;, err)     return   }    fmt.Printf(&quot;result =&gt; %+v&quot;,result)   \/\/prints: result =&gt; {Status:200} } <\/code><\/pre>\n<p>  <\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>struct<\/code> \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0442\u0438\u043f <code>json.RawMessage<\/code>, \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043b\u043e\u0436\u0438\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.\n<p>  \u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e JSON-\u043f\u043e\u043b\u044f (conditional field) \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438\u043b\u0438 \u0442\u0438\u043f\u0430 \u043f\u043e\u043b\u044f.<\/p>\n<pre><code class=\"go\">package main  import (     &quot;encoding\/json&quot;   &quot;bytes&quot;   &quot;fmt&quot; )  func main() {     records := [][]byte{     []byte(`{&quot;status&quot;: 200, &quot;tag&quot;:&quot;one&quot;}`),     []byte(`{&quot;status&quot;:&quot;ok&quot;, &quot;tag&quot;:&quot;two&quot;}`),   }    for idx, record := range records {     var result struct {       StatusCode uint64       StatusName string       Status json.RawMessage `json:&quot;status&quot;`       Tag string             `json:&quot;tag&quot;`     }      if err := json.NewDecoder(bytes.NewReader(record)).Decode(&result); err != nil {       fmt.Println(&quot;error:&quot;, err)       return     }      var sstatus string     if err := json.Unmarshal(result.Status, &sstatus); err == nil {       result.StatusName = sstatus     }      var nstatus uint64     if err := json.Unmarshal(result.Status, &nstatus); err == nil {       result.StatusCode = nstatus     }      fmt.Printf(&quot;[%v] result =&gt; %+v\\n&quot;,idx,result)   } } <\/code><\/pre>\n<p>  <\/li>\n<\/ul>\n<p>  <a name=\"39\"><\/a><\/p>\n<h1>39. \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 struct, array, slice \u0438 map<\/h1>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 <code>==<\/code> \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440, \u0435\u0441\u043b\u0438 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  type data struct {       num int     fp float32     complex complex64     str string     char rune     yes bool     events &lt;-chan string     handler interface{}     ref *byte     raw [10]byte }  func main() {       v1 := data{}     v2 := data{}     fmt.Println(&quot;v1 == v2:&quot;,v1 == v2) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: v1 == v2: true } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u043f\u043e\u043b\u0435\u0439 \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e, \u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u044b \u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  type data struct {       num int                \/\/ ok     checks [10]func() bool \/\/ \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e     doit func() bool       \/\/ \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e     m map[string] string   \/\/ \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e     bytes []byte           \/\/ \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e }  func main() {       v1 := data{}     v2 := data{}     fmt.Println(&quot;v1 == v2:&quot;,v1 == v2) } <\/code><\/pre>\n<p>  Go \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0421\u0430\u043c\u043e\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>DeepEqual()<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 reflect.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;reflect&quot; )  type data struct {       num int                \/\/ ok     checks [10]func() bool \/\/ \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e     doit func() bool       \/\/ \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e     m map[string] string   \/\/ \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e     bytes []byte           \/\/ \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u043e }  func main() {       v1 := data{}     v2 := data{}     fmt.Println(&quot;v1 == v2:&quot;,reflect.DeepEqual(v1,v2)) \/\/ prints: v1 == v2: true      m1 := map[string]string{&quot;one&quot;: &quot;a&quot;,&quot;two&quot;: &quot;b&quot;}     m2 := map[string]string{&quot;two&quot;: &quot;b&quot;, &quot;one&quot;: &quot;a&quot;}     fmt.Println(&quot;m1 == m2:&quot;,reflect.DeepEqual(m1, m2)) \/\/ prints: m1 == m2: true      s1 := []int{1, 2, 3}     s2 := []int{1, 2, 3}     fmt.Println(&quot;s1 == s2:&quot;,reflect.DeepEqual(s1, s2)) \/\/ prints: s1 == s2: true } <\/code><\/pre>\n<p>  \u041f\u043e\u043c\u0438\u043c\u043e \u043d\u0435\u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 (\u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f), <code>DeepEqual()<\/code> \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;reflect&quot; )  func main() {       var b1 []byte = nil     b2 := []byte{}     fmt.Println(&quot;b1 == b2:&quot;,reflect.DeepEqual(b1, b2)) \/\/ prints: b1 == b2: false } <\/code><\/pre>\n<p>  <code>DeepEqual()<\/code> \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u043b\u0430\u0439\u0441 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u043c <code>nil<\/code>-\u0441\u043b\u0430\u0439\u0441\u0443. \u042d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>bytes.Equal()<\/code>: \u043e\u043d\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u043c\u0438 <code>nil<\/code> \u0438 \u043f\u0443\u0441\u0442\u044b\u0435 \u0441\u043b\u0430\u0439\u0441\u044b.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;bytes&quot; )  func main() {       var b1 []byte = nil     b2 := []byte{}     fmt.Println(&quot;b1 == b2:&quot;,bytes.Equal(b1, b2)) \/\/ prints: b1 == b2: true } <\/code><\/pre>\n<p>  <code>DeepEqual()<\/code> \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0430 \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441\u043b\u0430\u0439\u0441\u043e\u0432.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;reflect&quot;     &quot;encoding\/json&quot; )  func main() {       var str string = &quot;one&quot;     var in interface{} = &quot;one&quot;     fmt.Println(&quot;str == in:&quot;,str == in,reflect.DeepEqual(str, in))     \/\/prints: str == in: true true      v1 := []string{&quot;one&quot;,&quot;two&quot;}     v2 := []interface{}{&quot;one&quot;,&quot;two&quot;}     fmt.Println(&quot;v1 == v2:&quot;,reflect.DeepEqual(v1, v2))     \/\/prints: v1 == v2: false (not ok)      data := map[string]interface{}{         &quot;code&quot;: 200,         &quot;value&quot;: []string{&quot;one&quot;,&quot;two&quot;},     }     encoded, _ := json.Marshal(data)     var decoded map[string]interface{}     json.Unmarshal(encoded, &decoded)     fmt.Println(&quot;data == decoded:&quot;,reflect.DeepEqual(data, decoded))     \/\/prints: data == decoded: false (not ok) } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u0448\u0438 \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441\u044b (\u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0438) \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0443\u0447\u0451\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ToUpper()<\/code> \u0438\u043b\u0438 <code>ToLower()<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 bytes \u0438 strings (\u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a <code>==<\/code>, <code>bytes.Equal()<\/code> \u0438\u043b\u0438 <code>bytes.Compare()<\/code>). \u042d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u0430\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u044b\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043d\u043e \u043d\u0435 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432. \u0422\u0430\u043a \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c <code>strings.EqualFold()<\/code> \u0438 <code>bytes.EqualFold()<\/code>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u0448\u0438 \u0431\u0430\u0439\u0442-\u0441\u043b\u0430\u0439\u0441\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0445\u0435\u0448\u0438, \u0442\u043e\u043a\u0435\u043d\u044b \u0438 \u0442. \u0434.), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u043e\u0431\u043e\u0439\u0434\u0438\u0442\u0435\u0441\u044c \u0431\u0435\u0437 <code>reflect.DeepEqual()<\/code>, <code>bytes.Equal()<\/code> \u0438\u043b\u0438 <code>bytes.Compare()<\/code>. \u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0434\u0435\u043b\u0430\u044e\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0443\u044f\u0437\u0432\u0438\u043c\u044b\u043c \u043a \u0430\u0442\u0430\u043a\u0430\u043c \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0427\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0443\u0442\u0435\u0447\u043a\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 crypto\/subtle (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>subtle.ConstantTimeCompare()<\/code>).<\/p>\n<p>  <a name=\"40\"><\/a><\/p>\n<h1>40. \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 panic<\/h1>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044e <code>recover()<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0438\u043c\u043a\u0438\/\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0430 panic. \u042d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0451 \u0432 \u0431\u043b\u043e\u043a\u0435 defer.<\/p>\n<p>  \u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       recover() \/\/ \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442     panic(&quot;not good&quot;)     recover() \/\/ \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e :)     fmt.Println(&quot;ok&quot;) } <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       defer func() {         fmt.Println(&quot;recovered:&quot;,recover())     }()      panic(&quot;not good&quot;) } <\/code><\/pre>\n<p>  \u0412\u044b\u0437\u043e\u0432 <code>recover()<\/code> \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0432 \u0431\u043b\u043e\u043a\u0435 defer.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func doRecover() {       fmt.Println(&quot;recovered =&gt;&quot;,recover()) \/\/ prints: recovered =&gt; &lt;nil&gt; }  func main() {       defer func() {         doRecover() \/\/ \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 panic \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e     }()      panic(&quot;not good&quot;) } <\/code><\/pre>\n<p>  <a name=\"41\"><\/a><\/p>\n<h1>41. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0435\u0439 \u0432 slice, array \u0438 map \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 for range<\/h1>\n<p>  \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 <code>range<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u044d\u0442\u043e \u043a\u043e\u043f\u0438\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439, \u0430 \u043d\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. \u0421\u0442\u0430\u043b\u043e \u0431\u044b\u0442\u044c, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0430\u0434\u0440\u0435\u0441 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u043e \u0432\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       data := []int{1,2,3}     for _,v := range data {         v *= 10 \/\/ \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f     }      fmt.Println(&quot;data:&quot;,data) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: [1 2 3] } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0442\u043e \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       data := []int{1,2,3}     for i,_ := range data {         data[i] *= 10     }      fmt.Println(&quot;data:&quot;,data) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: [10 20 30] } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f. \u0412\u0430\u043c \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 <code>for range<\/code>.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       data := []*struct{num int} {{1},{2},{3}}      for _,v := range data {         v.num *= 10     }      fmt.Println(data[0],data[1],data[2]) \/\/ prints &{10} &{20} &{30} } <\/code><\/pre>\n<p>  <a name=\"42\"><\/a><\/p>\n<h1>42. \u00ab\u0421\u043a\u0440\u044b\u0442\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\u00bb \u0432 \u0441\u043b\u0430\u0439\u0441\u0430\u0445<\/h1>\n<p>  \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u0440\u0435\u0437\u043a\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0441\u043b\u0430\u0439\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u0430\u0439\u0441\u0430. \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c. \u0418\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442 \u0432 \u043d\u0435\u0439 \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u0430\u0439\u0441\u044b \u0438 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0438\u0437 \u043d\u0438\u0445 \u043d\u043e\u0432\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043a\u0443\u0441\u043a\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func get() []byte {       raw := make([]byte,10000)     fmt.Println(len(raw),cap(raw),&raw[0]) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 10000 10000 &lt;byte_addr_x&gt;     return raw[:3] }  func main() {       data := get()     fmt.Println(len(data),cap(data),&data[0]) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 3 10000 &lt;byte_addr_x&gt; } <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u044d\u0442\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044c\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u0430\u0439\u0441\u0430 (\u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u0440\u0435\u0437\u043a\u0438).<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func get() []byte {       raw := make([]byte,10000)     fmt.Println(len(raw),cap(raw),&raw[0]) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 10000 10000 &lt;byte_addr_x&gt;     res := make([]byte,3)     copy(res,raw[:3])     return res }  func main() {       data := get()     fmt.Println(len(data),cap(data),&data[0]) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 3 3 &lt;byte_addr_y&gt; } <\/code><\/pre>\n<p>  <a name=\"43\"><\/a><\/p>\n<h1>43. \u00ab\u041f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435\u00bb \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u043b\u0430\u0439\u0441\u0430\u0445<\/h1>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0443\u0442\u044c (\u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439\u0441\u044f \u0432 \u0441\u043b\u0430\u0439\u0441\u0435). \u0427\u0442\u043e\u0431\u044b \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u0430\u043f\u043a\u0443, \u0432\u044b \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u0440\u0435\u0437\u0430\u0435\u0442\u0435, \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u0438\u043c\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u0435\u0442\u0435 \u0438\u043c\u0435\u043d\u0430 \u0432 \u043d\u043e\u0432\u044b\u0439 \u043f\u0443\u0442\u044c.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;bytes&quot; )  func main() {       path := []byte(&quot;AAAA\/BBBBBBBBB&quot;)     sepIndex := bytes.IndexByte(path,'\/')     dir1 := path[:sepIndex]     dir2 := path[sepIndex+1:]     fmt.Println(&quot;dir1 =&gt;&quot;,string(dir1)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: dir1 =&gt; AAAA     fmt.Println(&quot;dir2 =&gt;&quot;,string(dir2)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: dir2 =&gt; BBBBBBBBB      dir1 = append(dir1,&quot;suffix&quot;...)     path = bytes.Join([][]byte{dir1,dir2},[]byte{'\/'})      fmt.Println(&quot;dir1 =&gt;&quot;,string(dir1)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: dir1 =&gt; AAAAsuffix     fmt.Println(&quot;dir2 =&gt;&quot;,string(dir2)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: dir2 =&gt; uffixBBBB (not ok)      fmt.Println(&quot;new path =&gt;&quot;,string(path)) } <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0412\u043c\u0435\u0441\u0442\u043e AAAAsuffix\/BBBBBBBBB \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 AAAAsuffix\/uffixBBBB. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043b\u0430\u0439\u0441\u044b \u043e\u0431\u0435\u0438\u0445 \u043f\u0430\u043f\u043e\u043a \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u0430\u0439\u0441\u0430 \u043f\u0443\u0442\u0438. \u0422\u043e \u0435\u0441\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0442\u043e\u0436\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0415\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c, \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0432 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u043e\u0432\u044b\u0435 \u0441\u043b\u0430\u0439\u0441\u044b \u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0432 \u0442\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u0440\u0443\u0433\u043e\u0439 \u0432\u044b\u0445\u043e\u0434: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0430\u0439\u0441\u0430 (full slice expression).<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;bytes&quot; )  func main() {       path := []byte(&quot;AAAA\/BBBBBBBBB&quot;)     sepIndex := bytes.IndexByte(path,'\/')     dir1 := path[:sepIndex:sepIndex] \/\/ \u043f\u043e\u043b\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0430\u0439\u0441\u0430     dir2 := path[sepIndex+1:]     fmt.Println(&quot;dir1 =&gt;&quot;,string(dir1)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: dir1 =&gt; AAAA     fmt.Println(&quot;dir2 =&gt;&quot;,string(dir2)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: dir2 =&gt; BBBBBBBBB      dir1 = append(dir1,&quot;suffix&quot;...)     path = bytes.Join([][]byte{dir1,dir2},[]byte{'\/'})      fmt.Println(&quot;dir1 =&gt;&quot;,string(dir1)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: dir1 =&gt; AAAAsuffix     fmt.Println(&quot;dir2 =&gt;&quot;,string(dir2)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: dir2 =&gt; BBBBBBBBB (ok now)      fmt.Println(&quot;new path =&gt;&quot;,string(path)) } <\/code><\/pre>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 \u043f\u043e\u043b\u043d\u043e\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0451\u043c\u043a\u043e\u0441\u0442\u044c\u044e \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043b\u0430\u0439\u0441\u0430. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043a \u043d\u043e\u0432\u043e\u043c\u0443 \u0441\u043b\u0430\u0439\u0441\u0443 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043b\u0430\u0439\u0441.<\/p>\n<p>  <a name=\"44\"><\/a><\/p>\n<h1>44. \u00ab\u0423\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435\u00bb \u0441\u043b\u0430\u0439\u0441\u044b<\/h1>\n<p>  \u041d\u0430 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0430\u0439\u0441\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0441\u043b\u0430\u0439\u0441 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e\u0441\u044f. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u044c\u0442\u0435\u0441\u044c \u043e\u0431 \u00ab\u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0445\u00bb \u0441\u043b\u0430\u0439\u0441\u0430\u0445.<\/p>\n<p>  \u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u0441\u0442\u0430\u0440\u043e\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u043d\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430 \u0441\u0442\u0430\u0440\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 (\u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438) \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0430\u0439\u0441\u043e\u0432.<\/p>\n<pre><code class=\"go\">import &quot;fmt&quot;  func main() {       s1 := []int{1,2,3}     fmt.Println(len(s1),cap(s1),s1) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 3 3 [1 2 3]      s2 := s1[1:]     fmt.Println(len(s2),cap(s2),s2) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 2 2 [2 3]      for i := range s2 { s2[i] += 20 }      \/\/ \u0432\u0441\u0451 \u0435\u0449\u0451 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0442\u043e\u0442 \u0436\u0435 \u043c\u0430\u0441\u0441\u0438\u0432     fmt.Println(s1) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [1 22 23]     fmt.Println(s2) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [22 23]      s2 = append(s2,4)      for i := range s2 { s2[i] += 10 }      \/\/s1 is now &quot;stale&quot;     fmt.Println(s1) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [1 22 23]     fmt.Println(s2) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442 [32 33 14] } <\/code><\/pre>\n<p>  <a name=\"45\"><\/a><\/p>\n<h1>45. \u041c\u0435\u0442\u043e\u0434\u044b \u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432<\/h1>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e (\u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u043e\u0433\u043e), \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 \u0438 \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u0442\u0438\u043f\u0435.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;sync&quot;  type myMutex sync.Mutex  func main() {       var mtx myMutex     mtx.Lock() \/\/ \u043e\u0448\u0438\u0431\u043a\u0430     mtx.Unlock() \/\/ \u043e\u0448\u0438\u0431\u043a\u0430 } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox106401185\/main.go:9: mtx.Lock undefined (type myMutex has no field or method Lock) \/tmp\/sandbox106401185\/main.go:10: mtx.Unlock undefined (type myMutex has no field or method Unlock) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0432\u0441\u0442\u0440\u043e\u0438\u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;sync&quot;  type myLocker struct {       sync.Mutex }  func main() {       var lock myLocker     lock.Lock() \/\/ ok     lock.Unlock() \/\/ ok } <\/code><\/pre>\n<p>  \u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442 \u0441\u0432\u043e\u0438 \u043d\u0430\u0431\u043e\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;sync&quot;  type myLocker sync.Locker  func main() {       var lock myLocker = new(sync.Mutex)     lock.Lock() \/\/ ok     lock.Unlock() \/\/ ok } <\/code><\/pre>\n<p>  <a name=\"46\"><\/a><\/p>\n<h1>46. \u041a\u0430\u043a \u0432\u044b\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u043a\u043e\u0434\u043e\u0432\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 for switch \u0438 for select<\/h1>\n<p>  <\/p>\n<ul>\n<li>\u0443\u0440\u043e\u0432\u0435\u043d\u044c: \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0439<\/li>\n<\/ul>\n<p>  \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>break<\/code> \u0431\u0435\u0437 \u043c\u0435\u0442\u043a\u0438 (label) \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0431\u043b\u043e\u043a\u0430 <code>switch\/select<\/code>. \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>return<\/code> \u2014 \u043d\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0442\u043e\u0433\u0434\u0430 \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u044b\u0445\u043e\u0434 \u2014 \u0437\u0430\u0434\u0430\u0442\u044c \u043c\u0435\u0442\u043a\u0443 \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0446\u0438\u043a\u043b\u0430.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       loop:         for {             switch {             case true:                 fmt.Println(&quot;breaking out...&quot;)                 break loop             }         }      fmt.Println(&quot;out!&quot;) } <\/code><\/pre>\n<p>  \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0438 \u0441 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c <code>goto<\/code>\u2026<\/p>\n<p>  <a name=\"47\"><\/a><\/p>\n<h1>47. \u0418\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 for<\/h1>\n<p>  \u0421\u0430\u043c\u0430\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 Go. \u0418\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 <code>for<\/code> \u0441\u043d\u043e\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u043e\u0435 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 (aka \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u043b), \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0435 \u0432 \u0432\u0430\u0448\u0435\u043c \u0446\u0438\u043a\u043b\u0435 <code>for<\/code>, \u0431\u0443\u0434\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0443 \u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u0438 \u043e\u043d\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0447\u043d\u0451\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d).<\/p>\n<p>  \u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  func main() {       data := []string{&quot;one&quot;,&quot;two&quot;,&quot;three&quot;}      for _,v := range data {         go func() {             fmt.Println(v)         }()     }      time.Sleep(3 * time.Second)     \/\/ \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432\u044b\u0432\u043e\u0434\u044f\u0442: three, three, three } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (\u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0435\u0435 \u043c\u0435\u043d\u044f\u0442\u044c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b): \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u0430 \u0446\u0438\u043a\u043b\u0430 <code>for<\/code>.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  func main() {       data := []string{&quot;one&quot;,&quot;two&quot;,&quot;three&quot;}      for _,v := range data {         vcopy := v \/\/         go func() {             fmt.Println(vcopy)         }()     }      time.Sleep(3 * time.Second)     \/\/ \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432\u044b\u0432\u043e\u0434\u044f\u0442: one, two, three } <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  func main() {       data := []string{&quot;one&quot;,&quot;two&quot;,&quot;three&quot;}      for _,v := range data {         go func(in string) {             fmt.Println(in)         }(v)     }      time.Sleep(3 * time.Second)     \/\/ \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432\u044b\u0432\u043e\u0434\u044f\u0442: one, two, three } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043b\u043e\u0432\u0443\u0448\u043a\u0438.<\/p>\n<p>  \u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  type field struct {       name string }  func (p *field) print() {       fmt.Println(p.name) }  func main() {       data := []field{{&quot;one&quot;},{&quot;two&quot;},{&quot;three&quot;}}      for _,v := range data {         go v.print()     }      time.Sleep(3 * time.Second)     \/\/ \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432\u044b\u0432\u043e\u0434\u044f\u0442: three, three, three } <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  type field struct {       name string }  func (p *field) print() {       fmt.Println(p.name) }  func main() {       data := []field{{&quot;one&quot;},{&quot;two&quot;},{&quot;three&quot;}}      for _,v := range data {         v := v         go v.print()     }      time.Sleep(3 * time.Second)     \/\/ \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432\u044b\u0432\u043e\u0434\u044f\u0442: one, two, three } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 (\u0438 \u043f\u043e\u0447\u0435\u043c\u0443), \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434?<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;time&quot; )  type field struct {       name string }  func (p *field) print() {       fmt.Println(p.name) }  func main() {       data := []*field{{&quot;one&quot;},{&quot;two&quot;},{&quot;three&quot;}}      for _,v := range data {         go v.print()     }      time.Sleep(3 * time.Second) } <\/code><\/pre>\n<p>  <a name=\"48\"><\/a><\/p>\n<h1>48. \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0431\u043b\u043e\u043a\u0430 defer (Deferred Function Call Argument Evaluation)<\/h1>\n<p>  \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u0433\u0434\u0430 \u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>defer<\/code> (\u0430 \u043d\u0435 \u043a\u043e\u0433\u0434\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f).<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       var i int = 1      defer fmt.Println(&quot;result =&gt;&quot;,func() int { return i * 2 }())     i++     \/\/\u0432\u044b\u0432\u043e\u0434\u0438\u0442: result =&gt; 2 (not ok if you expected 4) } <\/code><\/pre>\n<p>  <a name=\"49\"><\/a><\/p>\n<h1>49. \u0412\u044b\u0437\u043e\u0432 \u0431\u043b\u043e\u043a\u0430 defer<\/h1>\n<p>  \u041e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0433\u043e \u0438\u0445 \u043a\u043e\u0434\u043e\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430. \u041d\u043e\u0432\u0438\u0447\u043a\u0438 \u0447\u0430\u0441\u0442\u043e \u043e\u0448\u0438\u0431\u0430\u044e\u0442\u0441\u044f, \u043f\u0443\u0442\u0430\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u043b\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0446\u0438\u043a\u043b\u043e\u043c <code>for<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u043b\u043e\u0436\u0438\u0442\u044c (<code>defer<\/code>) \u0432\u044b\u0437\u043e\u0432\u044b \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;os&quot;     &quot;path\/filepath&quot; )  func main() {       if len(os.Args) != 2 {         os.Exit(-1)     }      start, err := os.Stat(os.Args[1])     if err != nil || !start.IsDir(){         os.Exit(-1)     }      var targets []string     filepath.Walk(os.Args[1], func(fpath string, fi os.FileInfo, err error) error {         if err != nil {             return err         }          if !fi.Mode().IsRegular() {             return nil         }          targets = append(targets,fpath)         return nil     })      for _,target := range targets {         f, err := os.Open(target)         if err != nil {             fmt.Println(&quot;bad target:&quot;,target,&quot;error:&quot;,err) \/\/\u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u0448\u0438\u0431\u043a\u0443: too many open files             break         }         defer f.Close() \/\/ \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u043e \u0432 \u043a\u043e\u043d\u0446\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430         \/\/ \u0441\u0434\u0435\u043b\u0430\u0439 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441 \u0444\u0430\u0439\u043b\u043e\u043c...     } } <\/code><\/pre>\n<p>  \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u2014 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043e\u0434\u043e\u0432\u044b\u0439 \u0431\u043b\u043e\u043a \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;os&quot;     &quot;path\/filepath&quot; )  func main() {       if len(os.Args) != 2 {         os.Exit(-1)     }      start, err := os.Stat(os.Args[1])     if err != nil || !start.IsDir(){         os.Exit(-1)     }      var targets []string     filepath.Walk(os.Args[1], func(fpath string, fi os.FileInfo, err error) error {         if err != nil {             return err         }          if !fi.Mode().IsRegular() {             return nil         }          targets = append(targets,fpath)         return nil     })      for _,target := range targets {         func() {             f, err := os.Open(target)             if err != nil {                 fmt.Println(&quot;bad target:&quot;,target,&quot;error:&quot;,err)                 return             }             defer f.Close() \/\/ ok             \/\/ \u0441\u0434\u0435\u043b\u0430\u0439 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441 \u0444\u0430\u0439\u043b\u043e\u043c...         }()     } } <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f <code>defer<\/code> \ud83d\ude42<\/p>\n<p>  <a name=\"50\"><\/a><\/p>\n<h1>50. \u041e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0442\u0438\u043f\u043e\u0432<\/h1>\n<p>  \u0421\u0431\u043e\u0439\u043d\u044b\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u00ab\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb \u0434\u043b\u044f \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f. \u041d\u0430\u043b\u043e\u0436\u0438\u0432\u0448\u0438\u0441\u044c \u043d\u0430 \u0441\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e.<\/p>\n<p>  \u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       var data interface{} = &quot;great&quot;      if data, ok := data.(int); ok {         fmt.Println(&quot;[is an int] value =&gt;&quot;,data)     } else {         fmt.Println(&quot;[not an int] value =&gt;&quot;,data)         \/\/\u0432\u044b\u0432\u043e\u0434\u0438\u0442: [not an int] value =&gt; 0 (not &quot;great&quot;)     } } <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       var data interface{} = &quot;great&quot;      if res, ok := data.(int); ok {         fmt.Println(&quot;[is an int] value =&gt;&quot;,res)     } else {         fmt.Println(&quot;[not an int] value =&gt;&quot;,data)         \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: [not an int] value =&gt; great (as expected)     } } <\/code><\/pre>\n<p>  <a name=\"51\"><\/a><\/p>\n<h1>51. \u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0438 \u0443\u0442\u0435\u0447\u043a\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432<\/h1>\n<p>  \u0412 \u0432\u044b\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u00abGo Concurrency Patterns\u00bb \u043d\u0430 \u043a\u043e\u043d\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0438 Google I\/O \u0432 2012-\u043c \u0420\u043e\u0431 \u041f\u0430\u0439\u043a \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 concurrency-\u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445. \u041e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u2014 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/p>\n<pre><code class=\"go\">func First(query string, replicas ...Search) Result {       c := make(chan Result)     searchReplica := func(i int) { c &lt;- replicas[i](query) }     for i := range replicas {         go searchReplica(i)     }     return &lt;-c } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043f\u0438\u0438 (replica) \u043f\u043e\u0438\u0441\u043a\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0443. \u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 \u043a\u0430\u043d\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043a\u0430\u043d\u0430\u043b\u0430.<\/p>\n<p>  \u0410 \u0447\u0442\u043e \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d? \u0418 \u0447\u0442\u043e \u043d\u0430\u0441\u0447\u0451\u0442 \u043d\u0438\u0445 \u0441\u0430\u043c\u0438\u0445?<\/p>\n<p>  \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>First()<\/code> \u043a\u0430\u043d\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u0435 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430. \u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0441\u0442\u0440\u0435\u0432\u0430\u044e\u0442 \u0432 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043f\u0438\u0438 (replica), \u0442\u043e \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0443\u0442\u0435\u0447\u043a\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c, \u0432\u0441\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f (exit). \u041e\u0434\u043d\u043e \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0439 \u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<pre><code class=\"go\">func First(query string, replicas ...Search) Result {       c := make(chan Result,len(replicas))     searchReplica := func(i int) { c &lt;- replicas[i](query) }     for i := range replicas {         go searchReplica(i)     }     return &lt;-c } <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>select<\/code> \u0441\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u043c (case) <code>default<\/code> \u0438 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u043d\u0430 \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 <code>default<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c, \u0447\u0442\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043d\u0435 \u0437\u0430\u0441\u0442\u0440\u044f\u043b\u0430, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043a\u0430\u043d\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"go\">func First(query string, replicas ...Search) Result {       c := make(chan Result,1)     searchReplica := func(i int) {         select {         case c &lt;- replicas[i](query):         default:         }     }     for i := range replicas {         go searchReplica(i)     }     return &lt;-c } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u043e\u0442\u043c\u0435\u043d\u044b (special cancellation channel) \u0434\u043b\u044f \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<pre><code class=\"go\">func First(query string, replicas ...Search) Result {       c := make(chan Result)     done := make(chan struct{})     defer close(done)     searchReplica := func(i int) {         select {         case c &lt;- replicas[i](query):         case &lt;- done:         }     }     for i := range replicas {         go searchReplica(i)     }      return &lt;-c } <\/code><\/pre>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u0432 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0431\u0430\u0433\u0438? \u0420\u043e\u0431 \u041f\u0430\u0439\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0445\u043e\u0442\u0435\u043b \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u0441\u043b\u0430\u0439\u0434\u044b (slides) \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b, \u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043e\u0434, \u043d\u0435 \u0434\u0443\u043c\u0430\u044f \u043e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445.<\/p>\n<p>  <a name=\"52\"><\/a><\/p>\n<h1>52. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 (pointer receiver), \u043a \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h1>\n<p>  \u041f\u043e\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0434\u0440\u0435\u0441\u0443\u0435\u043c\u043e (addressable), \u043a \u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u0430, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<\/p>\n<p>  \u041d\u043e \u043d\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0430\u0434\u0440\u0435\u0441\u0443\u0435\u043c\u0430. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b (map) \u043d\u0435\u0430\u0434\u0440\u0435\u0441\u0443\u0435\u043c\u044b. \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u0442\u043e\u0436\u0435 \u043d\u0435\u0430\u0434\u0440\u0435\u0441\u0443\u0435\u043c\u044b.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  type data struct {       name string }  func (p *data) print() {       fmt.Println(&quot;name:&quot;,p.name) }  type printer interface {       print() }  func main() {       d1 := data{&quot;one&quot;}     d1.print() \/\/ok      var in printer = data{&quot;two&quot;} \/\/ \u043e\u0448\u0438\u0431\u043a\u0430     in.print()      m := map[string]data {&quot;x&quot;:data{&quot;three&quot;}}     m[&quot;x&quot;].print() \/\/\u043e\u0448\u0438\u0431\u043a\u0430 } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox017696142\/main.go:21: cannot use data literal (type data) as type printer in assignment: data does not implement printer (print method has pointer receiver) \/tmp\/sandbox017696142\/main.go:25: cannot call pointer method on m[&quot;x&quot;] \/tmp\/sandbox017696142\/main.go:25: cannot take the address of m[&quot;x&quot;] <\/code><\/pre>\n<p>  <a name=\"53\"><\/a><\/p>\n<h1>53. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/h1>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440, \u0442\u043e \u0432\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u043f\u043e\u043b\u044f.<\/p>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  type data struct {       name string }  func main() {       m := map[string]data {&quot;x&quot;:{&quot;one&quot;}}     m[&quot;x&quot;].name = &quot;two&quot; \/\/ error } <\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">\/tmp\/sandbox380452744\/main.go:9: cannot assign to m[&quot;x&quot;].name <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0435 \u0430\u0434\u0440\u0435\u0441\u0443\u0435\u043c\u044b.<\/p>\n<p>  \u041d\u043e\u0432\u0438\u0447\u043a\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0443\u0442\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u043b\u0430\u0439\u0441\u043e\u0432 \u2014 \u0430\u0434\u0440\u0435\u0441\u0443\u0435\u043c\u044b.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  type data struct {       name string }  func main() {       s := []data {{&quot;one&quot;}}     s[0].name = &quot;two&quot; \/\/ ok     fmt.Println(s)    \/\/ prints: [{two}] } <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430-\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432 (gccgo) \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041d\u043e \u044d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u0444\u0438\u043a\u0441\u0438\u043b\u0438 \ud83d\ude42 \u0422\u0430\u043a\u0436\u0435 \u0441\u0447\u0438\u0442\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 Go 1.3. \u041d\u043e \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435 \u0442\u0430\u043a \u0432\u0430\u0436\u043d\u043e, \u0442\u0430\u043a \u0447\u0442\u043e \u0444\u0438\u0447\u0430 \u0432\u0441\u0451 \u0435\u0449\u0451 \u0432\u0438\u0441\u0438\u0442 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 todo.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435 \u043e\u0431\u0445\u043e\u0434\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>.package main<\/code><\/p>\n<pre><code class=\"go\">import &quot;fmt&quot;  type data struct {       name string }  func main() {       m := map[string]data {&quot;x&quot;:{&quot;one&quot;}}     r := m[&quot;x&quot;]     r.name = &quot;two&quot;     m[&quot;x&quot;] = r     fmt.Printf(&quot;%v&quot;,m) \/\/\u0432\u044b\u0432\u043e\u0434\u0438\u0442: map[x:{two}] } <\/code><\/pre>\n<p>  \u0412\u0442\u043e\u0440\u043e\u0435 \u043e\u0431\u0445\u043e\u0434\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  type data struct {       name string }  func main() {       m := map[string]*data {&quot;x&quot;:{&quot;one&quot;}}     m[&quot;x&quot;].name = &quot;two&quot; \/\/ok     fmt.Println(m[&quot;x&quot;]) \/\/\u0432\u044b\u0432\u043e\u0434\u0438\u0442: &{two} } <\/code><\/pre>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434?<\/p>\n<pre><code class=\"go\">package main  type data struct {       name string }  func main() {       m := map[string]*data {&quot;x&quot;:{&quot;one&quot;}}     m[&quot;z&quot;].name = &quot;what?&quot; \/\/??? } <\/code><\/pre>\n<p>  <a name=\"54\"><\/a><\/p>\n<h1>54. nil-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438 nil-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/h1>\n<p>  \u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0441\u0442\u0438 \u043b\u043e\u0432\u0443\u0448\u043a\u0430 Go. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u2014 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 <code>nil<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0438\u0445 \u0442\u0438\u043f\u044b \u0438 \u043f\u043e\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0443\u0442 <code>nil<\/code>.<\/p>\n<p>  \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0439 \u0442\u0438\u043f \u0438 \u043f\u043e\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0438\u043f\u0430 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u0430 \u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>nil<\/code>, \u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       var data *byte     var in interface{}      fmt.Println(data,data == nil) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: &lt;nil&gt; true     fmt.Println(in,in == nil)     \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: &lt;nil&gt; true      in = data     fmt.Println(in,in == nil)     \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: &lt;nil&gt; false     \/\/'data' \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f 'nil', \u043d\u043e 'in' \u2014 \u043d\u0435 'nil' } <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0435\u0440\u0435\u0433\u0430\u0439\u0442\u0435\u0441\u044c \u044d\u0442\u043e\u0439 \u043b\u043e\u0432\u0443\u0448\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b.<\/p>\n<p>  \u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       doit := func(arg int) interface{} {         var result *struct{} = nil          if(arg &gt; 0) {             result = &struct{}{}         }          return result     }      if res := doit(-1); res != nil {         fmt.Println(&quot;good result:&quot;,res) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: good result: &lt;nil&gt;         \/\/ 'res' \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f 'nil', \u043d\u043e \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 'nil'     } } <\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       doit := func(arg int) interface{} {         var result *struct{} = nil          if(arg &gt; 0) {             result = &struct{}{}         } else {             return nil \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044f\u0432\u043d\u044b\u0439 'nil'         }          return result     }      if res := doit(-1); res != nil {         fmt.Println(&quot;good result:&quot;,res)     } else {         fmt.Println(&quot;bad result (res is nil)&quot;) \/\/ \u0437\u0434\u0435\u0441\u044c \u2014 \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c     } } <\/code><\/pre>\n<p>  <a name=\"55\"><\/a><\/p>\n<h1>55. \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0435\u043a\u0430 \u0438 \u043a\u0443\u0447\u0438<\/h1>\n<p>  \u041d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432 \u0441\u0442\u0435\u043a\u0435 \u0438\u043b\u0438 \u0432 \u043a\u0443\u0447\u0435. \u0415\u0441\u043b\u0438 \u0432 \u0421++ \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>new<\/code>, \u0442\u043e \u043e\u043d\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432 \u043a\u0443\u0447\u0435. \u0412 Go \u043c\u0435\u0441\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>new()<\/code> \u0438\u043b\u0438 <code>make()<\/code>. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u044b\u0431\u043e\u0440 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u00ab\u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u00bb (escape analysis). \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0447\u0442\u043e \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0421 \u0438 \u0421++.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u043d\u0430\u0442\u044c, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 gc flag <code>-m<\/code> \u0432 <code>go build<\/code> \u0438\u043b\u0438 <code>go run<\/code> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>go run -gcflags -m app.go<\/code>).<\/p>\n<p>  <a name=\"56\"><\/a><\/p>\n<h1>56. GOMAXPROCS, \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c (concurrency) \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c<\/h1>\n<p>  Go 1.4 \u0438 \u043d\u0438\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0442\u0440\u0435\u0434 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \/ \u041e\u0421. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Go 1.5 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u043b\u043e \u0440\u0430\u0432\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u044b\u0445 \u044f\u0434\u0435\u0440, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c\u0443 <code>runtime.NumCPU()<\/code>. \u041e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u043e\u0431\u0449\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u044f\u0434\u0435\u0440 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 CPU \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c, \u0438\u0437\u043c\u0435\u043d\u0438\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u0440\u0435\u0434\u044b <code>GOMAXPROCS<\/code> \u0438\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>runtime.GOMAXPROCS()<\/code>.<\/p>\n<p>  \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0435 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435, \u0447\u0442\u043e <code>GOMAXPROCS<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 Go \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>runtime.GOMAXPROCS()<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u0440\u0430\u0437\u0431\u0435\u0440\u0438\u0445\u0438. \u041d\u043e \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>GOMAXPROCS<\/code> (https:\/\/golang.org\/pkg\/runtime\/) \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043e \u0442\u0440\u0435\u0434\u0430\u0445 \u041e\u0421.<\/p>\n<p>  \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>GOMAXPROCS<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u0432, \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u043f\u0440\u0435\u0434\u0435\u043b \u2014 256.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;runtime&quot; )  func main() {       fmt.Println(runtime.GOMAXPROCS(-1)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: X (1 on play.golang.org)     fmt.Println(runtime.NumCPU())       \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: X (1 on play.golang.org)     runtime.GOMAXPROCS(20)     fmt.Println(runtime.GOMAXPROCS(-1)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 20     runtime.GOMAXPROCS(300)     fmt.Println(runtime.GOMAXPROCS(-1)) \/\/ \u0432\u044b\u0432\u043e\u0434\u0438\u0442: 256 } <\/code><\/pre>\n<p>  <a name=\"57\"><\/a><\/p>\n<h1>57. \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438<\/h1>\n<p>  Go \u043c\u043e\u0436\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043d\u043e \u043e\u0431\u0449\u0435\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0433\u0434\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043f\u043e\u0440\u044f\u0434\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u0430\u043c\u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;runtime&quot;     &quot;time&quot; )  var _ = runtime.GOMAXPROCS(3)  var a, b int  func u1() {       a = 1     b = 2 }  func u2() {       a = 3     b = 4 }  func p() {       println(a)     println(b) }  func main() {       go u1()     go u2()     go p()     time.Sleep(1 * time.Second) } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <code>a<\/code> \u0438 <code>b<\/code>:<\/p>\n<pre><code class=\"bash\">1  2  3  4  0  2  0  0  1  4 <\/code><\/pre>\n<p>  \u0421\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u2014 02 \u2014 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e <code>b<\/code> \u0431\u044b\u043b\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0440\u0430\u043d\u044c\u0448\u0435 <code>a<\/code>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441\u0440\u0435\u0434\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043a\u0430\u043d\u0430\u043b\u044b \u0438\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 sync.<\/p>\n<p>  <a name=\"58\"><\/a><\/p>\n<h1>58. \u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430\u043c (Preemptive Scheduling)<\/h1>\n<p>  \u041c\u043e\u0433\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u0431\u043e\u0439\u043d\u0438\u0447\u044c\u0438 (rogue) \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u043d\u0435 \u0434\u0430\u044e\u0449\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f. \u0422\u0430\u043a\u043e\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0446\u0438\u043a\u043b <code>for<\/code>, \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       done := false      go func(){         done = true     }()      for !done {     }     fmt.Println(&quot;done!&quot;) } <\/code><\/pre>\n<p>  \u0426\u0438\u043a\u043b <code>for<\/code> \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u0438\u0441\u0447\u0435\u0437\u043d\u0435\u0442, \u043f\u043e\u043a\u0430 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043a\u043e\u0434, \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430.<\/p>\n<p>  \u041e\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u0443\u0441\u043e\u0440\u0430, \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 <code>go<\/code>, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u043d\u0430\u043b\u043e\u0432, \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0422\u0430\u043a\u0436\u0435 \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043d\u0435\u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f (non-inlined) \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<pre><code class=\"go\">package main  import &quot;fmt&quot;  func main() {       done := false      go func(){         done = true     }()      for !done {         fmt.Println(&quot;not done!&quot;) \/\/ \u043d\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u0430     }     fmt.Println(&quot;done!&quot;) } <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043b\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u0432\u0430\u043c\u0438 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 gc flag <code>\u2013m<\/code> \u0432 <code>go build<\/code> \u0438\u043b\u0438 <code>go run<\/code> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>go build -gcflags -m<\/code>).<\/p>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u044f\u0432\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Gosched()<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 runtime.<\/p>\n<pre><code class=\"go\">package main  import (       &quot;fmt&quot;     &quot;runtime&quot; )  func main() {       done := false      go func(){         done = true     }()      for !done {         runtime.Gosched()     }     fmt.Println(&quot;done!&quot;) } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438\u043b\u0438 \u0438\u0434\u0435\u0438, \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u044e \u043d\u0430 Reddit (\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0437\u0434\u0435\u0441\u044c, \u043d\u0430 \u0425\u0430\u0431\u0440\u0435. \u2014 \u041f\u0440\u0438\u043c\u0435\u0447. \u043f\u0435\u0440.).<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:\/\/habrahabr.ru\/post\/314804\/\"> https:\/\/habrahabr.ru\/post\/314804\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/64f\/bc1\/8a3\/64fbc18a37fa4dd884eeb8200dd5c8dd.jpg\"\/><\/p>\n<p>  Go \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0439 \u044f\u0437\u044b\u043a. \u041d\u043e \u0432 \u043d\u0451\u043c, \u043a\u0430\u043a \u0438 \u0432 \u043b\u044e\u0431\u044b\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438. \u0418 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0438\u0437 \u043d\u0438\u0445 \u0441\u0430\u043c Go \u043d\u0435 \u0432\u0438\u043d\u043e\u0432\u0430\u0442. \u041e\u0434\u043d\u0438 \u2014 \u044d\u0442\u043e \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0438\u0437-\u0437\u0430 \u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0438 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 \u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0432\u0438\u043a\u0438, \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0435 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438, \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u0431\u043b\u043e\u0433\u0430\u0445 \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u0442\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u0435\u0439 \u0441\u0442\u0430\u043d\u0443\u0442 \u0434\u043b\u044f \u0432\u0430\u0441 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b. \u041d\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0430\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442, \u0438 \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u043e\u0432\u0438\u0447\u043e\u043a \u0432 Go, \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043d\u0435\u043c\u0430\u043b\u043e \u0447\u0430\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0431\u044b \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u043d\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u043a\u043e\u0434\u0430. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u0438 Go 1.5 \u0438 \u043d\u0438\u0436\u0435.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-280688","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280688","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=280688"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280688\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}