{"id":462111,"date":"2025-06-04T15:02:03","date_gmt":"2025-06-04T15:02:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=462111"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=462111","title":{"rendered":"<span>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043b\u043e\u0433\u0438 + \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432: \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 Go<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/-t\/be\/lw\/-tbelwsaidub6lf1wbg3pbf-jia.jpeg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/-t\/be\/lw\/-tbelwsaidub6lf1wbg3pbf-jia.jpeg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/-t\/be\/lw\/-tbelwsaidub6lf1wbg3pbf-jia.jpeg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p> <\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 Go-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u044d\u0442\u0438\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u0451\u0440\u0442\u043e\u043a \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0441 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p> <\/p>\n<pre><code class=\"go\">func (*SomeObject).SomeMethod(val any) error {   if err := otherMethod(val); err != nil {     return fmt.Errorf(\"otherMethod %w with val %v\", err, val)   }   return nil }<\/code><\/pre>\n<p> <\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430:<\/p>\n<p> <\/p>\n<ul>\n<li><strong>\u0414\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/strong> \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445<\/li>\n<li><strong>\u0420\u0443\u0447\u043d\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445<\/strong> (\u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435) \u0432 \u043a\u0430\u0436\u0434\u043e\u0435 \u043c\u0435\u0441\u0442\u043e<\/li>\n<li><strong>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f<\/strong> \u043c\u0435\u0441\u0442\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0442\u043e\u0447\u043a\u0430\u0445 \u0432\u044b\u0445\u043e\u0434\u0430<\/li>\n<li><strong>\u0417\u0430\u0441\u043e\u0440\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430<\/strong> \u2014 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0439\u0441\u044f boilerplate<\/li>\n<li><strong>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/strong> \u2014 \u0432\u0441\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u044b \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435<\/li>\n<\/ul>\n<p> <\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043c\u043e\u0449\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<code>slog<\/code>) \u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0441\u0431\u043e\u0440\u043e\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0442\u0435\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 \u0447\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043b\u043e\u0433\u0438.<\/p>\n<p><a name=\"habracut\"><\/a> <\/p>\n<h2 id=\"reshenie-strukturirovannye-oshibki--avtomaticheskiy-stek\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435: \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 + \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0442\u0435\u043a<\/h2>\n<p> <\/p>\n<p><strong>\u0411\u044b\u043b\u043e:<\/strong><\/p>\n<p> <\/p>\n<pre><code class=\"go\">func (*SomeObject).SomeMethod(val any) error {   if err := otherMethod(val); err != nil {     slog.Error(err, \"val\", val) \/\/ \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435     return fmt.Errorf(\"someMethod %w with val %v\", err, val)   }   return nil }<\/code><\/pre>\n<p> <\/p>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<p> <\/p>\n<pre><code class=\"go\">func (*SomeObject).SomeMethod(val any) (err error) {   defer log.DebugOrError(\"debug description\", &amp;err)    if err = otherMethod(val); err != nil {     return log.WrapError(err, \"val\", val)   }   return nil }<\/code><\/pre>\n<p> <\/p>\n<h2 id=\"klyuchevye-vozmozhnosti\">\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p> <\/p>\n<h3 id=\"1-avtomaticheskiy-stek-vyzovov\">1. \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432<\/h3>\n<p> <\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u2014 \u0441\u0442\u0435\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438:<\/p>\n<p> <\/p>\n<pre><code class=\"plaintext\">level=ERROR msg=\"other error\" val=nil  stack[0]=\"lib.go:26\" stack[1]=\"lib.go:22\"<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"2-umnaya-identifikaciya-tochek-oshibok\">2. \u0423\u043c\u043d\u0430\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0442\u043e\u0447\u0435\u043a \u043e\u0448\u0438\u0431\u043e\u043a<\/h3>\n<p> <\/p>\n<p>\u041f\u0440\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<p> <\/p>\n<pre><code class=\"go\">func (*SomeObject).SomeMethod() (err error) {   defer log.DebugOrError(\"debug description\", &amp;err)    if err := otherMethod1(); err != nil {     return log.WrapError(err)  \/\/ line 25   }    if err := otherMethod2(); err != nil {     return log.WrapError(err)  \/\/ line 29   }   return nil }<\/code><\/pre>\n<p> <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u0447\u043d\u043e\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043c\u0435\u0441\u0442\u0430 \u0432 \u043b\u043e\u0433\u0430\u0445:<\/p>\n<p> <\/p>\n<pre><code class=\"plaintext\">level=ERROR msg=\"other error 1\" stack[0]=\"lib.go:25\" stack[1]=\"lib.go:22\"  level=ERROR msg=\"other error 2\" stack[0]=\"lib.go:29\" stack[1]=\"lib.go:22\"<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"3-sozdanie-novyh-strukturirovannyh-oshibok\">3. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a<\/h3>\n<p> <\/p>\n<pre><code class=\"go\">err = log.NewError(\"text\", \"key1\", \"value1\", \"key2\", \"value2\")<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"4-umnoe-obyortyvanie\">4. \u0423\u043c\u043d\u043e\u0435 \u043e\u0431\u0451\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p> <\/p>\n<p>\u041f\u0440\u0438 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u043c \u043e\u0431\u0451\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0435\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430:<\/p>\n<p> <\/p>\n<pre><code class=\"go\">err = log.WrapError(err, \"arg1\", \"val1\") \/\/ \u0441\u0442\u0435\u043a \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0434\u0435\u0441\u044c err = log.WrapError(err, \"arg2\", \"val2\") \/\/ \u0441\u0442\u0435\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"5-zaschita-ot-zabytyh-obyortok\">5. \u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 \u0437\u0430\u0431\u044b\u0442\u044b\u0445 \u043e\u0431\u0451\u0440\u0442\u043e\u043a<\/h3>\n<p> <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u0431\u044b\u043b\u0438 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443, <code>DebugOrError<\/code> \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0441\u0442\u0435\u043a:<\/p>\n<p> <\/p>\n<pre><code class=\"go\">func (*SomeObject).SomeMethod() (err error) {   \/\/ \u0441\u0442\u0435\u043a \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432   defer log.DebugOrError(\"debug description\", &amp;err)     return errors.New(\"unwrapped error\")  }<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"6-nakoplenie-metadannyh\">6. \u041d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p> <\/p>\n<p>\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0432\u0441\u0435\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u043e\u0431\u0451\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f:<\/p>\n<p> <\/p>\n<pre><code class=\"go\">func (*SomeObject).SomeMethod() (err error) {   defer log.DebugOrError(\"debug description\", &amp;err, \"arg3\", \"val3\")    err = log.NewError(\"my error\", \"arg1\", \"val1\")   \/\/ ...   err = log.WrapError(err, \"arg2\", \"val2\")    return err }<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p> <\/p>\n<pre><code class=\"plaintext\">level=ERROR msg=\"my error\" arg1=val1 arg2=val2 arg3=val3 stack[0]=\"lib.go:25\" stack[1]=\"lib.go:22\"<\/code><\/pre>\n<p> <\/p>\n<h2 id=\"arhitektura-resheniya\">\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h2>\n<p> <\/p>\n<h3 id=\"strukturirovannye-oshibki\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/h3>\n<p> <\/p>\n<pre><code class=\"go\">type CustomError struct {     error     Args  []any          \/\/ \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b     Stack []*CallInfo    \/\/ \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 }<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"umnyy-sbor-steka\">\u0423\u043c\u043d\u044b\u0439 \u0441\u0431\u043e\u0440 \u0441\u0442\u0435\u043a\u0430<\/h3>\n<p> <\/p>\n<ul>\n<li>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u043e <code>go.mod<\/code><\/li>\n<li>\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 (\u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 stdlib \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438)<\/li>\n<li>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0435 \u043f\u0443\u0442\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u0440\u043d\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/li>\n<li>\u041a\u0435\u0448\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0442\u0430\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/li>\n<\/ul>\n<p> <\/p>\n<h3 id=\"api-dlya-logirovaniya\">API \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p> <\/p>\n<pre><code class=\"go\">\/\/ \u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u044f \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435 logger.DebugOrError(\"operation completed\", &amp;err, \"user_id\", 123) logger.InfoOrError(\"data processed\", &amp;err, \"records\", count) logger.WarnOrError(\"cache miss\", &amp;err, \"key\", cacheKey)<\/code><\/pre>\n<p> <\/p>\n<h2 id=\"preimuschestva\">\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/h2>\n<p> <\/p>\n<p>\u2705 <strong>\u0427\u0438\u0441\u0442\u043e\u0442\u0430 \u043a\u043e\u0434\u0430<\/strong> \u2014 \u0443\u0431\u0440\u0430\u043b\u0438 boilerplate<br \/> \u2705 <strong>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435<\/strong> \u2014 \u0441\u0442\u0435\u043a \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0441\u0430\u043c\u0438<br \/> \u2705 <strong>IDE-friendly<\/strong> \u2014 \u043a\u043b\u0438\u043a \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432\u0435\u0434\u0451\u0442 \u043f\u0440\u044f\u043c\u043e \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443<br \/> \u2705 <strong>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/strong> \u2014 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<br \/> \u2705 <strong>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c<\/strong> \u2014 \u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 \u0437\u0430\u0431\u044b\u0442\u044b\u0445 \u043e\u0431\u0451\u0440\u0442\u043e\u043a<br \/> \u2705 <strong>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c<\/strong> \u2014 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043b\u044e\u0431\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <\/p>\n<p> <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p> <\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u0442\u0435\u043a\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u2014 \u044d\u0442\u043e \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 Go. \u041e\u043d\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0438\u044e \u044f\u0432\u043d\u043e\u0441\u0442\u0438 \u044f\u0437\u044b\u043a\u0430, \u043d\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0442 \u0440\u0443\u0442\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0430, \u0434\u0435\u043b\u0430\u044f \u043a\u043e\u0434 \u0447\u0438\u0449\u0435, \u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u2014 \u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0435.<\/p>\n<p> <\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u043c\u0438\u043d\u0443\u0442\u0430, \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u043b\u0435\u043d\u043d\u0430\u044f \u043d\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0435, \u043d\u0430 \u0441\u0447\u0435\u0442\u0443.<\/p>\n<p> <\/p>\n<h2 id=\"integraciya-s-telemetriey\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u0435\u0439<\/h2>\n<p> <\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043b\u043e\u0433\u0438 \u2014 \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0440\u044f\u0434\u0443 \u0441 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438 \u0438 \u0442\u0440\u0435\u0439\u0441\u0438\u043d\u0433\u043e\u043c. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043b\u043e\u0433\u0438 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f observability-\u0441\u0442\u0435\u043a\u0430:<\/p>\n<p> <\/p>\n<p><strong>Grafana + Loki<\/strong>: \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u044b. \u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u0441\u0442\u0435\u043a\u0430 (<code>stack[0]<\/code>, <code>stack[1]<\/code>) \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0443\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c\u0438 \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u043e \u043c\u0435\u0441\u0442\u0430\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f.<\/p>\n<p> <\/p>\n<p><strong>\u0410\u043b\u0435\u0440\u0442\u0438\u043d\u0433<\/strong>: \u041f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0443\u043c\u043d\u044b\u0445 \u0430\u043b\u0435\u0440\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u043a\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u043e \u0438 \u0435\u0451 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438.<\/p>\n<p> <\/p>\n<p><strong>\u0410\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430<\/strong>: \u041d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0432 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0433\u043e\u0440\u044f\u0447\u0438\u0435 \u0442\u043e\u0447\u043a\u0438 \u0432 \u043a\u043e\u0434\u0435 \u0438 \u0442\u0440\u0435\u043d\u0434\u044b \u0434\u0435\u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p> <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u0434\u0430 \u043e\u043a\u0443\u043f\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u0441\u0435\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430.<\/p>\n<p> <\/p>\n<hr\/>\n<p> <\/p>\n<p>\u041f\u043e\u043b\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0435\u0451 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 <a href=\"https:\/\/github.com\/comerc\/budva43\/tree\/main\/app\/log\" rel=\"nofollow noopener noreferrer\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u0435\u0442-\u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/a><\/p>\n<p> <\/p>\n<blockquote><p><strong>Disclaimer<\/strong>: \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0440\u043e\u043b\u044c \u043f\u0430\u043d\u0430\u0446\u0435\u0438 \u043e\u0442 \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Go. \u042d\u0442\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442, \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438. \u0410\u0432\u0442\u043e\u0440 \u043e\u0442\u043a\u0440\u044b\u0442 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u043e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c\u0443 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044e \u0438\u0434\u0435\u0438.<\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/915660\/\"> https:\/\/habr.com\/ru\/articles\/915660\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/-t\/be\/lw\/-tbelwsaidub6lf1wbg3pbf-jia.jpeg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/-t\/be\/lw\/-tbelwsaidub6lf1wbg3pbf-jia.jpeg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/-t\/be\/lw\/-tbelwsaidub6lf1wbg3pbf-jia.jpeg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p> <\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 Go-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u044d\u0442\u0438\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u0451\u0440\u0442\u043e\u043a \u0434\u043b\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0441 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p> <\/p>\n<pre><code class=\"go\">func (*SomeObject).SomeMethod(val any) error {   if err := otherMethod(val); err != nil {     return fmt.Errorf(\"otherMethod %w with val %v\", err, val)   }   return nil }<\/code><\/pre>\n<p> <\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430:<\/p>\n<p> <\/p>\n<ul>\n<li><strong>\u0414\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/strong> \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445<\/li>\n<li><strong>\u0420\u0443\u0447\u043d\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445<\/strong> (\u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435) \u0432 \u043a\u0430\u0436\u0434\u043e\u0435 \u043c\u0435\u0441\u0442\u043e<\/li>\n<li><strong>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f<\/strong> \u043c\u0435\u0441\u0442\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0442\u043e\u0447\u043a\u0430\u0445 \u0432\u044b\u0445\u043e\u0434\u0430<\/li>\n<li><strong>\u0417\u0430\u0441\u043e\u0440\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430<\/strong> \u2014 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0439\u0441\u044f boilerplate<\/li>\n<li><strong>\u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/strong> \u2014 \u0432\u0441\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u044b \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435<\/li>\n<\/ul>\n<p> <\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043c\u043e\u0449\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<code>slog<\/code>) \u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0441\u0431\u043e\u0440\u043e\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0442\u0435\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 \u0447\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043b\u043e\u0433\u0438.<\/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-462111","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/462111","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=462111"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/462111\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=462111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=462111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=462111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}