{"id":445885,"date":"2025-01-23T09:00:46","date_gmt":"2025-01-23T09:00:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=445885"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=445885","title":{"rendered":"<span>\u041f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Golang<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d36\/dd7\/8b1\/d36dd78b1572c10ba3a0e3d7a00dc952.png\" width=\"1440\" height=\"895\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d36\/dd7\/8b1\/d36dd78b1572c10ba3a0e3d7a00dc952.png\"\/><\/figure>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Golang, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0432 \u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438.<\/p>\n<p>\u0424\u0430\u0441\u0430\u0434, \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f,  \u041f\u0440\u043e\u043a\u0441\u0438, \u0410\u0434\u0430\u043f\u0442\u0435\u0440<\/p>\n<h2>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u0424\u0430\u0441\u0430\u0434&#187;<\/h2>\n<p><strong>\u0424\u0430\u0441\u0430\u0434<\/strong> \u2014 \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <strong>\u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441<\/strong> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <strong>\u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439<\/strong>. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0441\u0430\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;. \u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0424\u0430\u0441\u0430\u0434 \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u043a\u043d\u043e\u043f\u043a\u0430 &#171;\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u0451&#187;. \u041e\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0442\u0435\u0431\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440:<\/h4>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0443\u043c\u043d\u044b\u0439 \u0434\u043e\u043c. \u0418 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0436\u0438\u043c\u0430 &#171;\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438&#187;<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0432\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043a\u0440\u044b\u0442\u044c \u0448\u0442\u043e\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0434\u043e\u043b\u0433\u043e \u0438 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e, \u0434\u0430 \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u043d\u0430\u0434\u043e. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u0444\u0430\u0441\u0430\u0434<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0432\u0441\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439.<\/p>\n<pre><code class=\"go\">package main  import \"fmt\"  \/\/ \u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 1: \u041e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435 type Lights struct{}  func (l *Lights) Off() { fmt.Println(\"\u0421\u0432\u0435\u0442: \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\") }  \/\/ \u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 2: \u0428\u0442\u043e\u0440\u044b type Curtains struct{}  func (c *Curtains) Close() { fmt.Println(\"\u0428\u0442\u043e\u0440\u044b: \u0437\u0430\u043a\u0440\u044b\u0442\u044b\") }  \/\/ \u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 3: \u041a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440 type Thermostat struct{}  func (t *Thermostat) SetTemperature(temp int) { fmt.Printf(\"\u041a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 %d\u00b0C\\n\", temp) }  \/\/ \u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 4: \u0421\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f type Alarm struct{}  func (a *Alarm) Activate() { fmt.Println(\"\u0421\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f: \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0430\") }  \/\/ \u0424\u0430\u0441\u0430\u0434: \u0423\u043c\u043d\u044b\u0439 \u0434\u043e\u043c type SmartHomeFacade struct { lights     *Lights curtains   *Curtains thermostat *Thermostat alarm      *Alarm }  \/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0444\u0430\u0441\u0430\u0434\u0430 func NewSmartHomeFacade() *SmartHomeFacade { return &amp;SmartHomeFacade{ lights:     &amp;Lights{}, curtains:   &amp;Curtains{}, thermostat: &amp;Thermostat{}, alarm:      &amp;Alarm{}, } }  \/\/ \u041c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0436\u0438\u043c\u0430 \"\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438\" func (s *SmartHomeFacade) GoodNightMode() { fmt.Println(\"\u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0440\u0435\u0436\u0438\u043c\u0430 `\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438`...\") s.lights.Off() s.curtains.Close() s.thermostat.SetTemperature(20) \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u0443\u044e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 s.alarm.Activate() fmt.Println(\"\u0420\u0435\u0436\u0438\u043c `\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438` \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d!\") }  func main() { \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0444\u0430\u0441\u0430\u0434 \u0434\u043b\u044f \u0443\u043c\u043d\u043e\u0433\u043e \u0434\u043e\u043c\u0430 smartHome := NewSmartHomeFacade()  \/\/ \u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0436\u0438\u043c \"\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438\" smartHome.GoodNightMode() }<\/code><\/pre>\n<h4>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/h4>\n<h4>\u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b:<\/h4>\n<ul>\n<li>\n<p><strong>Lights (\u041e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435)<\/strong> \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u0435\u0442\u043e\u043c \u0432 \u0434\u043e\u043c\u0435, \u043c\u0435\u0442\u043e\u0434 <code>Off()<\/code> \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0432\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>Curtains (\u0428\u0442\u043e\u0440\u044b)<\/strong> \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0448\u0442\u043e\u0440\u0430\u043c\u0438, \u043c\u0435\u0442\u043e\u0434 <code>Close()<\/code> \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0438\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>Thermostat (\u041a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440)<\/strong> \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439 \u0432 \u0434\u043e\u043c\u0435, \u043c\u0435\u0442\u043e\u0434 <code>SetTemperature(int)<\/code> \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443.<\/p>\n<\/li>\n<li>\n<p><strong>Alarm (\u0421\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f)<\/strong> \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043c\u0435\u0442\u043e\u0434 <code>Activate()<\/code> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0424\u0430\u0441\u0430\u0434 (SmartHomeFacade):<\/h4>\n<p>\u0424\u0430\u0441\u0430\u0434 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435\u043c \u0443\u043c\u043d\u044b\u043c \u0434\u043e\u043c\u043e\u043c. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0441\u0430\u0434.<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>NewSmartHomeFacade<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0438\u0445 \u0432 \u043e\u0434\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041c\u0435\u0442\u043e\u0434 GoodNightMode:<\/h4>\n<ul>\n<li>\n<p>\u0412\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0432\u0435\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434 <code>s.lights.Off()<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0448\u0442\u043e\u0440\u044b, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434 <code>s.curtains.Close()<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u0443\u044e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 (20\u00b0C) \u0434\u043b\u044f \u043a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440\u0430 \u0447\u0435\u0440\u0435\u0437 <code>s.thermostat.SetTemperature(20)<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>s.alarm.Activate()<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 (main):<\/h4>\n<ol>\n<li>\n<p>\u0412 <code>main<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0444\u0430\u0441\u0430\u0434\u0430 <code>smartHome<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u043c\u0438 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>GoodNightMode()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u0436\u0438\u043c &#171;\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438&#187;, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u043e\u043c\u0430 \u043a \u043d\u043e\u0447\u043d\u043e\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<h3>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f&#187;<\/h3>\n<p>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f&#187; \u2014 \u044d\u0442\u043e \u0432\u044b\u0431\u043e\u0440 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c <strong>\u043d\u0430\u0431\u043e\u0440 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432<\/strong> (\u0438\u043b\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439), \u0430 \u043f\u043e\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438, \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c, \u0447\u0442\u043e \u0442\u044b \u0438\u0434\u0451\u0448\u044c \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d. \u0423 \u0442\u0435\u0431\u044f \u0435\u0441\u0442\u044c 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430:<\/p>\n<ol>\n<li>\n<p>\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u043a\u0430\u0440\u0442\u043e\u0439 <\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u0430\u0433\u0430\u0437\u0438\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0443\u0441\u043b\u0443\u0433\u0443 (\u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u0442\u043e\u0432\u0430\u0440\u0430), \u043d\u043e \u0442\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0448\u044c, \u043a\u0430\u043a \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"go\">package main  import \"fmt\"  \/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043e\u043f\u043b\u0430\u0442\u044b type PaymentStrategy interface { Pay(amount float64) }  \/\/ \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u043a\u0430\u0440\u0442\u043e\u0439 type CardPayment struct{}  func (c *CardPayment) Pay(amount float64) { fmt.Printf(\"\u041e\u043f\u043b\u0430\u0442\u0430 \u043a\u0430\u0440\u0442\u043e\u0439: %.2f \u0440\u0443\u0431\u043b\u0435\u0439\\n\", amount) }  \/\/ \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438 type CashPayment struct{}  func (c *CashPayment) Pay(amount float64) { fmt.Printf(\"\u041e\u043f\u043b\u0430\u0442\u0430 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438: %.2f \u0440\u0443\u0431\u043b\u0435\u0439\\n\", amount) }  \/\/ \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439 type Shop struct { paymentStrategy PaymentStrategy }  func (s *Shop) SetPaymentStrategy(strategy PaymentStrategy) { s.paymentStrategy = strategy }  func (s *Shop) MakePayment(amount float64) { s.paymentStrategy.Pay(amount) }  func main() { \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0433\u0430\u0437\u0438\u043d shop := &amp;Shop{}  \/\/ \u041f\u043b\u0430\u0442\u0438\u043c \u043a\u0430\u0440\u0442\u043e\u0439 shop.SetPaymentStrategy(&amp;CardPayment{}) shop.MakePayment(1000.50)  \/\/ \u041f\u043b\u0430\u0442\u0438\u043c \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438 shop.SetPaymentStrategy(&amp;CashPayment{}) shop.MakePayment(500.75) }<\/code><\/pre>\n<h4>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/h4>\n<ol>\n<li>\n<p><strong>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <\/strong><code>PaymentStrategy<\/code>:<\/p>\n<ul>\n<li>\n<p>\u042d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pay(amount float64)<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438 \u043e\u043f\u043b\u0430\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043e\u043f\u043b\u0430\u0442\u044b<\/strong>:<\/p>\n<ul>\n<li>\n<p><code>CardPayment<\/code> (\u043e\u043f\u043b\u0430\u0442\u0430 \u043a\u0430\u0440\u0442\u043e\u0439): \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pay()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u043b\u0430\u0442\u0435\u0436\u0435 \u0441 \u043a\u0430\u0440\u0442\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><code>CashPayment<\/code> (\u043e\u043f\u043b\u0430\u0442\u0430 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438): \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pay()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u043b\u0430\u0442\u0435\u0436\u0435 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 <\/strong><code>Shop<\/code>:<\/p>\n<ul>\n<li>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Shop<\/code> \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>PaymentStrategy<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>SetPaymentStrategy(strategy PaymentStrategy)<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043e\u043f\u043b\u0430\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>MakePayment(amount float64)<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pay()<\/code> \u0443 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u043b\u0430\u0442\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 (<\/strong><code>main<\/code>):<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430 <code>shop<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u043a\u0430\u0440\u0442\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>SetPaymentStrategy(&amp;CardPayment{})<\/code>, \u0438 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>MakePayment()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043e\u043f\u043b\u0430\u0442\u0443 \u043a\u0430\u0440\u0442\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u043f\u043b\u0430\u0442\u0443 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>SetPaymentStrategy(&amp;CashPayment{})<\/code>, \u0438 \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>MakePayment()<\/code> \u0434\u043b\u044f<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr\/>\n<h2>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u041f\u0440\u043e\u043a\u0441\u0438&#187;<\/h2>\n<p><strong>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u041f\u0440\u043e\u043a\u0441\u0438<\/strong> \u2014 \u044d\u0442\u043e <strong>\u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443. \u041e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043e \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0442. \u0434.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u043a\u0441\u0438. \u041f\u0440\u043e\u043a\u0441\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443.<\/p>\n<pre><code class=\"go\">package main  import \"fmt\"  \/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 type Database interface { Connect() string Query(query string) string }  \/\/ \u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b type RealDatabase struct{}  func (db *RealDatabase) Connect() string { return \"\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445...\" }  func (db *RealDatabase) Query(query string) string { return fmt.Sprintf(\"\u0417\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445: %s\", query) }  \/\/ \u041f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f type DatabaseProxy struct { realDatabase Database userRole     string \/\/ \u0420\u043e\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \"admin\", \"user\", \"guest\") }  func (proxy *DatabaseProxy) Connect() string { \/\/ \u041f\u0440\u043e\u043a\u0441\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 if proxy.userRole != \"admin\" { return \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430: \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0430\u0432 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.\" } \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 return proxy.realDatabase.Connect() }  func (proxy *DatabaseProxy) Query(query string) string { \/\/ \u041f\u0440\u043e\u043a\u0441\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 if proxy.userRole != \"admin\" { return \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430: \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0430\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430.\" } \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 return proxy.realDatabase.Query(query) }  func main() { \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 realDB := &amp;RealDatabase{}  \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0440\u043e\u043b\u044c\u044e \"admin\" adminProxy := &amp;DatabaseProxy{ realDatabase: realDB, userRole:     \"admin\", \/\/ \u042d\u0442\u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f }  \/\/ \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 fmt.Println(adminProxy.Connect()) fmt.Println(adminProxy.Query(\"SELECT * FROM users\"))  \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0440\u043e\u043b\u044c\u044e \"guest\" guestProxy := &amp;DatabaseProxy{ realDatabase: realDB, userRole:     \"quest\", \/\/ \u0423 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 }  \/\/ \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0433\u043e\u0441\u0442\u044f fmt.Println(guestProxy.Connect()) fmt.Println(guestProxy.Query(\"SELECT * FROM users\")) }<\/code><\/pre>\n<h4>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/h4>\n<ul>\n<li>\n<p><strong>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <\/strong><code>Database<\/code>: \u042d\u0442\u043e \u043e\u0431\u0449\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <\/strong><code>RealDatabase<\/code>: \u042d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Database<\/code>. \u041e\u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u043a\u0441\u0438 <\/strong><code>DatabaseProxy<\/code>: \u042d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u043e\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Database<\/code>, \u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0412 \u043f\u0440\u043e\u043a\u0441\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0440\u043e\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0438 \u0435\u0441\u043b\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u0442 \u043f\u0440\u0430\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u043e\u043b\u044c &#171;guest&#187;), \u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u043a\u0441\u0438 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043a\u0441\u0438 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0433\u043e\u0441\u0442\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0433\u043e \u0440\u043e\u043b\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr\/>\n<h2>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u0410\u0434\u0430\u043f\u0442\u0435\u0440&#187;<\/h2>\n<p><strong>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u0410\u0434\u0430\u043f\u0442\u0435\u0440<\/strong> \u2014 \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <strong>\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/strong> \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <strong>\u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435<\/strong>.<\/p>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <strong>\u0437\u0430\u0440\u044f\u0434\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c USB-C<\/strong>, \u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0438\u043c\u0435\u0435\u0442 <strong>\u0440\u0430\u0437\u044a\u0435\u043c Lightning<\/strong>. \u0412 \u0436\u0438\u0437\u043d\u0438 \u044f \u0434\u0443\u043c\u0430\u044e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d <strong>\u0430\u0434\u0430\u043f\u0442\u0435\u0440<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u044a\u0435\u043c USB-C \u0432 Lightning.<\/p>\n<pre><code class=\"go\">package main  import \"fmt\"  \/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c Lightning type LightningPhone interface { ChargeWithLightning() }  \/\/ \u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c Lightning type iPhone struct{}  func (i *iPhone) ChargeWithLightning() { fmt.Println(\"iPhone \u0437\u0430\u0440\u044f\u0436\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 Lightning!\") }  \/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0437\u0430\u0440\u044f\u0434\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c USB-C type USBCCharger interface { ChargeWithUSB_C() }  \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0440\u044f\u0434\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0441 USB-C \/\/ \u042d\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \/\/ \u0434\u043b\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c Lightning \u0447\u0435\u0440\u0435\u0437 \u0430\u0434\u0430\u043f\u0442\u0435\u0440  \/\/ \u0417\u0430\u0440\u044f\u0434\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c USB-C type USBCharger struct{}  func (u *USBCharger) ChargeWithUSB_C() { fmt.Println(\"\u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u0430\u0440\u044f\u0434 \u0447\u0435\u0440\u0435\u0437 USB-C!\") }  \/\/ \u0410\u0434\u0430\u043f\u0442\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0440\u044f\u0436\u0430\u0442\u044c Lightning-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \/\/ \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c USB-C \u0437\u0430\u0440\u044f\u0434\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 type USBToLightningAdapter struct { usbCharger USBCCharger }  func (a *USBToLightningAdapter) ChargeWithLightning() { fmt.Println(\"\u0410\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0437\u0430\u0440\u044f\u0434 USB-C \u0432 Lightning...\") a.usbCharger.ChargeWithUSB_C() }  func main() { \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0437\u0430\u0440\u044f\u0434\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0441 USB-C usbCharger := &amp;USBCharger{}  \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c USB-C \u0437\u0430\u0440\u044f\u0434\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0434\u043b\u044f Lightning adapter := &amp;USBToLightningAdapter{usbCharger: usbCharger}  \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c iPhone \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c Lightning iphone := &amp;iPhone{}  \/\/ \u0417\u0430\u0440\u044f\u0436\u0430\u0435\u043c iPhone \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 fmt.Println(\"\u0417\u0430\u0440\u044f\u0436\u0430\u0435\u043c iPhone \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e:\") iphone.ChargeWithLightning()  \/\/ \u0417\u0430\u0440\u044f\u0436\u0430\u0435\u043c iPhone \u0447\u0435\u0440\u0435\u0437 \u0430\u0434\u0430\u043f\u0442\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f USB-C \u0437\u0430\u0440\u044f\u0434\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e fmt.Println(\"\\n\u0417\u0430\u0440\u044f\u0436\u0430\u0435\u043c iPhone \u0447\u0435\u0440\u0435\u0437 USB-C \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430:\") adapter.ChargeWithLightning() }  <\/code><\/pre>\n<h3>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/h3>\n<ul>\n<li>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>main<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0437\u0430\u0440\u044f\u0434\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 <strong>usbCharger<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0430\u0437\u044a\u0435\u043c <strong>USB-C<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <strong>adapter<\/strong> \u0442\u0438\u043f\u0430 <strong>USBToLightningAdapter<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 <strong>usbCharger<\/strong>. \u042d\u0442\u043e\u0442 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <strong>USB-C<\/strong> \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <strong>Lightning<\/strong>, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0440\u044f\u0434\u043a\u0443 \u0441 USB-C \u0434\u043b\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c Lightning.<\/p>\n<\/li>\n<li>\n<p><code>adapter.ChargeWithLightning()<\/code> \u2014 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443 <code>adapter<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>ChargeWithLightning<\/code>, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<\/li>\n<li>\n<p>\u0410\u0434\u0430\u043f\u0442\u0435\u0440 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>ChargeWithUSB_C()<\/code> \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 <strong>usbCharger<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0437\u0430\u0440\u044f\u0434\u043a\u0430 \u0438\u0434\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 USB-C.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d <strong>\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 USB-C \u0432 Lightning<\/strong>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (\u0440\u0430\u0437\u044a\u0435\u043c\u044b USB-C \u0438 Lightning) \u0438 \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0440\u044f\u0434\u0438\u0442\u044c iPhone \u0447\u0435\u0440\u0435\u0437 USB-C \u0437\u0430\u0440\u044f\u0434\u043a\u0443.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 4 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Golang. \u0424\u0430\u0441\u0430\u0434, \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f,  \u041f\u0440\u043e\u043a\u0441\u0438, \u0410\u0434\u0430\u043f\u0442\u0435\u0440<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0432\u044f\u0437\u044c. \u0412\u0441\u0435\u0433\u043e \u0434\u043e\u0431\u0440\u043e\u0433\u043e!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/875794\/\"> https:\/\/habr.com\/ru\/articles\/875794\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Golang, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0432 \u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438.<\/p>\n<p>\u0424\u0430\u0441\u0430\u0434, \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f,  \u041f\u0440\u043e\u043a\u0441\u0438, \u0410\u0434\u0430\u043f\u0442\u0435\u0440<\/p>\n<h2>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u0424\u0430\u0441\u0430\u0434&#187;<\/h2>\n<p><strong>\u0424\u0430\u0441\u0430\u0434<\/strong> \u2014 \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <strong>\u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441<\/strong> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <strong>\u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439<\/strong>. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0441\u0430\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;. \u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0424\u0430\u0441\u0430\u0434 \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u043a\u043d\u043e\u043f\u043a\u0430 &#171;\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u0451&#187;. \u041e\u043d \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0442\u0435\u0431\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440:<\/h4>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0443\u043c\u043d\u044b\u0439 \u0434\u043e\u043c. \u0418 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0436\u0438\u043c\u0430 &#171;\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438&#187;<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0432\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043a\u0440\u044b\u0442\u044c \u0448\u0442\u043e\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0434\u043e\u043b\u0433\u043e \u0438 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e, \u0434\u0430 \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u043d\u0430\u0434\u043e. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u0444\u0430\u0441\u0430\u0434<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0432\u0441\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439.<\/p>\n<pre><code class=\"go\">package main  import \"fmt\"  \/\/ \u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 1: \u041e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435 type Lights struct{}  func (l *Lights) Off() { fmt.Println(\"\u0421\u0432\u0435\u0442: \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\") }  \/\/ \u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 2: \u0428\u0442\u043e\u0440\u044b type Curtains struct{}  func (c *Curtains) Close() { fmt.Println(\"\u0428\u0442\u043e\u0440\u044b: \u0437\u0430\u043a\u0440\u044b\u0442\u044b\") }  \/\/ \u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 3: \u041a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440 type Thermostat struct{}  func (t *Thermostat) SetTemperature(temp int) { fmt.Printf(\"\u041a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 %d\u00b0C\\n\", temp) }  \/\/ \u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 4: \u0421\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f type Alarm struct{}  func (a *Alarm) Activate() { fmt.Println(\"\u0421\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f: \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0430\") }  \/\/ \u0424\u0430\u0441\u0430\u0434: \u0423\u043c\u043d\u044b\u0439 \u0434\u043e\u043c type SmartHomeFacade struct { lights     *Lights curtains   *Curtains thermostat *Thermostat alarm      *Alarm }  \/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0444\u0430\u0441\u0430\u0434\u0430 func NewSmartHomeFacade() *SmartHomeFacade { return &amp;SmartHomeFacade{ lights:     &amp;Lights{}, curtains:   &amp;Curtains{}, thermostat: &amp;Thermostat{}, alarm:      &amp;Alarm{}, } }  \/\/ \u041c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0436\u0438\u043c\u0430 \"\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438\" func (s *SmartHomeFacade) GoodNightMode() { fmt.Println(\"\u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0440\u0435\u0436\u0438\u043c\u0430 `\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438`...\") s.lights.Off() s.curtains.Close() s.thermostat.SetTemperature(20) \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u0443\u044e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 s.alarm.Activate() fmt.Println(\"\u0420\u0435\u0436\u0438\u043c `\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438` \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d!\") }  func main() { \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0444\u0430\u0441\u0430\u0434 \u0434\u043b\u044f \u0443\u043c\u043d\u043e\u0433\u043e \u0434\u043e\u043c\u0430 smartHome := NewSmartHomeFacade()  \/\/ \u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0436\u0438\u043c \"\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438\" smartHome.GoodNightMode() }<\/code><\/pre>\n<h4>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/h4>\n<h4>\u041f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b:<\/h4>\n<ul>\n<li>\n<p><strong>Lights (\u041e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435)<\/strong> \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u0435\u0442\u043e\u043c \u0432 \u0434\u043e\u043c\u0435, \u043c\u0435\u0442\u043e\u0434 <code>Off()<\/code> \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0432\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>Curtains (\u0428\u0442\u043e\u0440\u044b)<\/strong> \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0448\u0442\u043e\u0440\u0430\u043c\u0438, \u043c\u0435\u0442\u043e\u0434 <code>Close()<\/code> \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0438\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>Thermostat (\u041a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440)<\/strong> \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439 \u0432 \u0434\u043e\u043c\u0435, \u043c\u0435\u0442\u043e\u0434 <code>SetTemperature(int)<\/code> \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443.<\/p>\n<\/li>\n<li>\n<p><strong>Alarm (\u0421\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f)<\/strong> \u2014 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043c\u0435\u0442\u043e\u0434 <code>Activate()<\/code> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0424\u0430\u0441\u0430\u0434 (SmartHomeFacade):<\/h4>\n<p>\u0424\u0430\u0441\u0430\u0434 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435\u043c \u0443\u043c\u043d\u044b\u043c \u0434\u043e\u043c\u043e\u043c. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0441\u0430\u0434.<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>NewSmartHomeFacade<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0438\u0445 \u0432 \u043e\u0434\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041c\u0435\u0442\u043e\u0434 GoodNightMode:<\/h4>\n<ul>\n<li>\n<p>\u0412\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0432\u0435\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434 <code>s.lights.Off()<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0448\u0442\u043e\u0440\u044b, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434 <code>s.curtains.Close()<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u0443\u044e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 (20\u00b0C) \u0434\u043b\u044f \u043a\u043e\u043d\u0434\u0438\u0446\u0438\u043e\u043d\u0435\u0440\u0430 \u0447\u0435\u0440\u0435\u0437 <code>s.thermostat.SetTemperature(20)<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>s.alarm.Activate()<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 (main):<\/h4>\n<ol>\n<li>\n<p>\u0412 <code>main<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0444\u0430\u0441\u0430\u0434\u0430 <code>smartHome<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u043c\u0438 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>GoodNightMode()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u0436\u0438\u043c &#171;\u0421\u043f\u043e\u043a\u043e\u0439\u043d\u043e\u0439 \u043d\u043e\u0447\u0438&#187;, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u043e\u043c\u0430 \u043a \u043d\u043e\u0447\u043d\u043e\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<h3>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f&#187;<\/h3>\n<p>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f&#187; \u2014 \u044d\u0442\u043e \u0432\u044b\u0431\u043e\u0440 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c <strong>\u043d\u0430\u0431\u043e\u0440 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432<\/strong> (\u0438\u043b\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439), \u0430 \u043f\u043e\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438, \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c, \u0447\u0442\u043e \u0442\u044b \u0438\u0434\u0451\u0448\u044c \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d. \u0423 \u0442\u0435\u0431\u044f \u0435\u0441\u0442\u044c 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430:<\/p>\n<ol>\n<li>\n<p>\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u043a\u0430\u0440\u0442\u043e\u0439 <\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u0430\u0433\u0430\u0437\u0438\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0443\u0441\u043b\u0443\u0433\u0443 (\u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u0442\u043e\u0432\u0430\u0440\u0430), \u043d\u043e \u0442\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0448\u044c, \u043a\u0430\u043a \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"go\">package main  import \"fmt\"  \/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043e\u043f\u043b\u0430\u0442\u044b type PaymentStrategy interface { Pay(amount float64) }  \/\/ \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u043a\u0430\u0440\u0442\u043e\u0439 type CardPayment struct{}  func (c *CardPayment) Pay(amount float64) { fmt.Printf(\"\u041e\u043f\u043b\u0430\u0442\u0430 \u043a\u0430\u0440\u0442\u043e\u0439: %.2f \u0440\u0443\u0431\u043b\u0435\u0439\\n\", amount) }  \/\/ \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438 type CashPayment struct{}  func (c *CashPayment) Pay(amount float64) { fmt.Printf(\"\u041e\u043f\u043b\u0430\u0442\u0430 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438: %.2f \u0440\u0443\u0431\u043b\u0435\u0439\\n\", amount) }  \/\/ \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439 type Shop struct { paymentStrategy PaymentStrategy }  func (s *Shop) SetPaymentStrategy(strategy PaymentStrategy) { s.paymentStrategy = strategy }  func (s *Shop) MakePayment(amount float64) { s.paymentStrategy.Pay(amount) }  func main() { \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0433\u0430\u0437\u0438\u043d shop := &amp;Shop{}  \/\/ \u041f\u043b\u0430\u0442\u0438\u043c \u043a\u0430\u0440\u0442\u043e\u0439 shop.SetPaymentStrategy(&amp;CardPayment{}) shop.MakePayment(1000.50)  \/\/ \u041f\u043b\u0430\u0442\u0438\u043c \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438 shop.SetPaymentStrategy(&amp;CashPayment{}) shop.MakePayment(500.75) }<\/code><\/pre>\n<h4>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/h4>\n<ol>\n<li>\n<p><strong>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <\/strong><code>PaymentStrategy<\/code>:<\/p>\n<ul>\n<li>\n<p>\u042d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pay(amount float64)<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438 \u043e\u043f\u043b\u0430\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043e\u043f\u043b\u0430\u0442\u044b<\/strong>:<\/p>\n<ul>\n<li>\n<p><code>CardPayment<\/code> (\u043e\u043f\u043b\u0430\u0442\u0430 \u043a\u0430\u0440\u0442\u043e\u0439): \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pay()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u043b\u0430\u0442\u0435\u0436\u0435 \u0441 \u043a\u0430\u0440\u0442\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><code>CashPayment<\/code> (\u043e\u043f\u043b\u0430\u0442\u0430 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438): \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pay()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u043b\u0430\u0442\u0435\u0436\u0435 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 <\/strong><code>Shop<\/code>:<\/p>\n<ul>\n<li>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Shop<\/code> \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>PaymentStrategy<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>SetPaymentStrategy(strategy PaymentStrategy)<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043e\u043f\u043b\u0430\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>MakePayment(amount float64)<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pay()<\/code> \u0443 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u043b\u0430\u0442\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 (<\/strong><code>main<\/code>):<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430 <code>shop<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u043a\u0430\u0440\u0442\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>SetPaymentStrategy(&amp;CardPayment{})<\/code>, \u0438 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>MakePayment()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043e\u043f\u043b\u0430\u0442\u0443 \u043a\u0430\u0440\u0442\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u043f\u043b\u0430\u0442\u0443 \u043d\u0430\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>SetPaymentStrategy(&amp;CashPayment{})<\/code>, \u0438 \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>MakePayment()<\/code> \u0434\u043b\u044f<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr\/>\n<h2>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u041f\u0440\u043e\u043a\u0441\u0438&#187;<\/h2>\n<p><strong>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u041f\u0440\u043e\u043a\u0441\u0438<\/strong> \u2014 \u044d\u0442\u043e <strong>\u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443. \u041e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043e \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0442. \u0434.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u043a\u0441\u0438. \u041f\u0440\u043e\u043a\u0441\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443.<\/p>\n<pre><code class=\"go\">package main  import \"fmt\"  \/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 type Database interface { Connect() string Query(query string) string }  \/\/ \u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b type RealDatabase struct{}  func (db *RealDatabase) Connect() string { return \"\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445...\" }  func (db *RealDatabase) Query(query string) string { return fmt.Sprintf(\"\u0417\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445: %s\", query) }  \/\/ \u041f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f type DatabaseProxy struct { realDatabase Database userRole     string \/\/ \u0420\u043e\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \"admin\", \"user\", \"guest\") }  func (proxy *DatabaseProxy) Connect() string { \/\/ \u041f\u0440\u043e\u043a\u0441\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 if proxy.userRole != \"admin\" { return \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430: \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0430\u0432 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.\" } \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 return proxy.realDatabase.Connect() }  func (proxy *DatabaseProxy) Query(query string) string { \/\/ \u041f\u0440\u043e\u043a\u0441\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 if proxy.userRole != \"admin\" { return \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430: \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0430\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430.\" } \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 return proxy.realDatabase.Query(query) }  func main() { \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 realDB := &amp;RealDatabase{}  \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0440\u043e\u043b\u044c\u044e \"admin\" adminProxy := &amp;DatabaseProxy{ realDatabase: realDB, userRole:     \"admin\", \/\/ \u042d\u0442\u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f }  \/\/ \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 fmt.Println(adminProxy.Connect()) fmt.Println(adminProxy.Query(\"SELECT * FROM users\"))  \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0440\u043e\u043b\u044c\u044e \"guest\" guestProxy := &amp;DatabaseProxy{ realDatabase: realDB, userRole:     \"quest\", \/\/ \u0423 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 }  \/\/ \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0433\u043e\u0441\u0442\u044f fmt.Println(guestProxy.Connect()) fmt.Println(guestProxy.Query(\"SELECT * FROM users\")) }<\/code><\/pre>\n<h4>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/h4>\n<ul>\n<li>\n<p><strong>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <\/strong><code>Database<\/code>: \u042d\u0442\u043e \u043e\u0431\u0449\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <\/strong><code>RealDatabase<\/code>: \u042d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Database<\/code>. \u041e\u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u043a\u0441\u0438 <\/strong><code>DatabaseProxy<\/code>: \u042d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u043e\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Database<\/code>, \u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0412 \u043f\u0440\u043e\u043a\u0441\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0440\u043e\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0438 \u0435\u0441\u043b\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u0442 \u043f\u0440\u0430\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u043e\u043b\u044c &#171;guest&#187;), \u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u043a\u0441\u0438 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043a\u0441\u0438 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0433\u043e\u0441\u0442\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0433\u043e \u0440\u043e\u043b\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr\/>\n<h2>\u041f\u0430\u0442\u0442\u0435\u0440\u043d &#171;\u0410\u0434\u0430\u043f\u0442\u0435\u0440&#187;<\/h2>\n<p><strong>\u041f\u0430\u0442\u0442\u0435\u0440\u043d \u0410\u0434\u0430\u043f\u0442\u0435\u0440<\/strong> \u2014 \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <strong>\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/strong> \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <strong>\u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435<\/strong>.<\/p>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <strong>\u0437\u0430\u0440\u044f\u0434\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c USB-C<\/strong>, \u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0438\u043c\u0435\u0435\u0442 <strong>\u0440\u0430\u0437\u044a\u0435\u043c Lightning<\/strong>. \u0412 \u0436\u0438\u0437\u043d\u0438 \u044f \u0434\u0443\u043c\u0430\u044e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d <strong>\u0430\u0434\u0430\u043f\u0442\u0435\u0440<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u044a\u0435\u043c USB-C \u0432 Lightning.<\/p>\n<pre><code class=\"go\">package main  import \"fmt\"  \/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c Lightning type LightningPhone interface { ChargeWithLightning() }  \/\/ \u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0441 \u0440\u0430\u0437\u044a\u0435\u043c\u043e\u043c Lightning type iPhone struct{}  func (i *iPhone) ChargeWithLightning() { fmt.Println(\"iPhone \u0437\u0430\u0440\u044f\u0436\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 Lightning!\") }  \/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0437\u0430\u0440\u044f\u0434\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0441<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-445885","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/445885","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=445885"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/445885\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=445885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=445885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=445885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}