{"id":259551,"date":"2015-06-17T18:41:02","date_gmt":"2015-06-17T14:41:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=259551"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=259551","title":{"rendered":"\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Golang"},"content":{"rendered":"<p>             \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Go. \u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u043d\u0438\u0439 \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u0441\u043a\u043e\u0440\u0435\u0435 \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0436\u0435 \u043d\u043e\u0432\u043e\u0438\u0441\u043f\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u044f\u0437\u044b\u043a\u0430 \u043a\u0430\u043a \u0438 \u044f. \u0425\u043e\u0442\u044f, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0441\u0432\u0435\u0436\u0438\u0435 \u0438\u0434\u0435\u0438 \u0432\u044b \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043d\u0430\u0439\u0434\u0435\u0442\u0435.<\/p>\n<p>  \u0423 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043e \u00ab\u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438\u00bb \u2014 \u044d\u0442\u043e \u0432\u0441\u0451 \u043f\u043b\u043e\u0434\u044b \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u0441\u0442\u0432\u0430 \u0438 \u0436\u0438\u0432\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430 \u043f\u0440\u0438 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u0438 \u0441 \u044f\u0437\u044b\u043a\u043e\u043c Golang.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4><b>\u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/b><\/h4>\n<p>  \u041b\u0438\u0448\u044c \u043c\u0435\u043b\u044c\u043a\u043e\u043c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0443 \u044d\u0442\u043e\u0442 \u043f\u0443\u043d\u043a\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u043a\u0443\u0441\u043e\u0447\u043a\u0430\u043c \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0435\u0434\u0438\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0441\u0447\u0435\u0442\u0435 CI-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438\u0437 git-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 rpm-\u043f\u0430\u043a\u0435\u0442 \u0434\u043b\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043a\u0430\u043a systemd-\u0441\u0435\u0440\u0432\u0438\u0441.<\/p>\n<pre><code>Description=Description After=network.target Requires=mysqld.service  [Service] Type=simple User=nginx Group=nginx  WorkingDirectory=\/usr\/share\/project_name  StandardOutput=journal StandardError=journal  ExecStart=\/usr\/share\/project_name\/project_name Restart=always  [Install] WantedBy=multi-user.target <\/code><\/pre>\n<p>  \u0421\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 systemd \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f:<\/p>\n<ol>\n<li>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u043a\u0430\u043a \u0432 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0442 mysqld);<\/li>\n<li>Respawn-\u043e\u043c \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f;<\/li>\n<li>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043e\u043f\u0446\u0438\u044f\u043c StandardOutput \u0438 StandardError, \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043b\u0443\u0436\u0431\u044b. \u0427\u0442\u043e\u0431\u044b \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043b\u043e\u0433, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c:\n<pre><code class=\"go\">log.Println(&quot;Server is preparing to start&quot;)<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>  \u0412\u043f\u0435\u0440\u0435\u0434\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f http-\u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u043e\u0442\u0434\u0430\u0447\u0438 \u0441\u0442\u0430\u0442\u0438\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, nginx. <\/p>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u043a\u0430\u0442 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043b\u043e\u0436\u0430\u0442\u0441\u044f \u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 linux-\u0441\u0438\u0441\u0442\u0435\u043c\u044b (yum\/dnf\/rpm), \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u044d\u0442\u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0439.<\/p>\n<h4><b>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430<\/b><\/h4>\n<p>  \u0414\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u043c \u0442\u0443\u043b\u043a\u0438\u0442\u043e\u043c <a href=\"http:\/\/www.gorillatoolkit.org\/\">Gorilla toolkit<\/a> \u0438 \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435, \u043f\u043e \u0441\u0443\u0442\u0438, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u0442\u0443\u043b\u043a\u0438\u0442.<\/p>\n<h5><b>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/b><\/h5>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0440\u043e\u0443\u0442\u0435\u0440\u043e\u0432, \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c. \u0414\u043b\u044f \u043a\u043e\u043d\u0441\u043e\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 Application:<\/p>\n<pre><code class=\"go\"> type MapRoutes map[string]Controller  type Application struct {     Doc AbstractPage     Config Config     DB SQL      routes MapRoutes }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0435\u0442\u043e\u0434\u044b Application<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\"> \/\/ Routes \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 URL'\u0430\u043c\u0438 func (app *Application) Routes(r MapRoutes) {     app.routes = r }  func (app *Application) Run() {     r := mux.NewRouter()     r.StrictSlash(true)      for url, ctrl := range app.routes {         r.HandleFunc(url, obs(ctrl))     }      http.Handle(&quot;\/&quot;, r)     listen := fmt.Sprintf(&quot;%s:%d&quot;, app.Config.Net.Listen_host, app.Config.Net.Listen_port)      log.Println(&quot;Server is started on&quot;, listen)     if err := http.ListenAndServe(listen, nil); err != nil {         log.Println(err)     } }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0431\u044a\u0435\u043a\u0442 Application \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0434\u0438\u043d:<\/p>\n<pre><code class=\"go\"> var appInstance *Application  \/\/ GetApplication \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Application func GetApplication() *Application {     if appInstance == nil {         appInstance = new(Application)          \/\/ Init code         appInstance.Config = loadConfig(&quot;config.ini&quot;)         appInstance.Doc = make(AbstractPage)         appInstance.routes = make(MapRoutes)         \/\/ ...     }      return appInstance }<\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e Application \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.go<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\"> package main  import ( \t&quot;interfaces\/app&quot; \t&quot;interfaces\/handlers&quot; \t&quot;log&quot; )  func init() { \tlog.SetFlags(log.LstdFlags | log.Lshortfile) }  func main() { \tlog.Println(&quot;Server is preparing to start&quot;) \tApplication := app.GetApplication()  \tif Application.Config.Site.Disabled { \t\tlog.Println(&quot;Site is disabled&quot;) \t\tApplication.Routes(app.MapRoutes{&quot;\/&quot;: handlers.HandleDisabled{}}) \t} else { \t\tApplication.Routes(app.MapRoutes{ \t\t\t&quot;\/&quot;: handlers.HandleHome{}, \t\t\t&quot;\/v1\/ajax\/&quot;: handlers.HandleAjax{}, \t\t\t\/\/ \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \t\t\t&quot;\/{url:.*}&quot;: handlers.Handle404{}, \t\t}) \t}  \tApplication.Run() \tlog.Println(&quot;Exit&quot;) } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h5><b>httpHandler \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c *Context<\/b><\/h5>\n<p>  \u0421\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0437\u0434\u0435\u0441\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u043e\u0443\u0442\u0435\u0440\u043e\u0432:<\/p>\n<pre><code class=\"go\"> for url, ctrl := range app.routes {     r.HandleFunc(url, obs(ctrl)) } <\/code><\/pre>\n<p>  \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 Router \u0438\u0437 \u0442\u0443\u043b\u043a\u0438\u0442\u0430 Gorilla \u0440\u043e\u0432\u043d\u043e \u043a\u0430\u043a \u0438 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u00abnet\/http\u00bb \u0440\u0430\u0431\u043e\u0442\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 (\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430) \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u0438\u043f\u0430 <u>func(http.ResponseWriter, *http.Request)<\/u>. \u041d\u0430\u043c \u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0438\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"go\"> func ProductHandler(ctx *Context) {     \/\/ ... } <\/code><\/pre>\n<p>  \u0433\u0434\u0435 *Context \u2014 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u0443\u043a\u0430\u043c\u0438, \u0441\u0435\u0441\u0441\u0438\u0435\u0439 \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e, \u0442\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0440\u0435\u043a\u0432\u0435\u0441\u0442\u0430 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u043d\u043e \u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0411\u0414, \u043a \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0442.\u0435. \u0438 \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443 Application. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0435\u0440\u0442\u043a\u0443 <u>obs(handler Controller) func(http.ResponseWriter, *http.Request)<\/u>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0432\u0438\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u2014 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Controller, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u0434\u043b\u044f <u>r.HandleFunc()<\/u> \u0432\u0438\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u0441\u0435 \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0435\u0447\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 *ContextApplication \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f obs(), Controller \u0438 HTTPController<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\"> type Controller interface {      GET(app *ContextApplication)     POST(app *ContextApplication)     PUT(app *ContextApplication)     DELETE(app *ContextApplication)     PATCH(app *ContextApplication)     OPTIONS(app *ContextApplication)     HEAD(app *ContextApplication)     TRACE(app *ContextApplication)     CONNECT(app *ContextApplication) }  \/\/ obs \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 func obs(handler Controller) func(http.ResponseWriter, *http.Request) {     return func(w http.ResponseWriter, req *http.Request) {           ctx := context.New(w, req)         app := GetApplication()         doc := app.Doc.Clone(&quot;&quot;)         doc[&quot;Ctx&quot;] = ctx         doc[&quot;User&quot;] = ctx.User()          contextApp := &ContextApplication{ctx, doc, app.Config, app.DB}          switch ctx.Input.Method() {             case &quot;GET&quot;:     handler.GET(contextApp);             case &quot;POST&quot;:    handler.POST(contextApp);             case &quot;PUT&quot;:     handler.PUT(contextApp);             case &quot;DELETE&quot;:  handler.DELETE(contextApp);             case &quot;PATCH&quot;:   handler.PATCH(contextApp);             case &quot;OPTIONS&quot;: handler.OPTIONS(contextApp);             case &quot;HEAD&quot;:    handler.HEAD(contextApp);             case &quot;TRACE&quot;:   handler.TRACE(contextApp);             case &quot;CONNECT&quot;: handler.CONNECT(contextApp);              default: http.Error(ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed)         }     } }  \/\/ HTTPController \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \/\/ \u0417\u0430\u0434\u0430\u0447\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b. type HTTPController struct {}  func (h HTTPController) GET(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }  func (h HTTPController) POST(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }  func (h HTTPController) PUT(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }  func (h HTTPController) DELETE(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }  func (h HTTPController) PATCH(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }  func (h HTTPController) OPTIONS(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }  func (h HTTPController) HEAD(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }  func (h HTTPController) TRACE(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }  func (h HTTPController) CONNECT(app *ContextApplication) {     http.Error(app.Ctx.Response(), &quot;Method not allowed&quot;, http.StatusMethodNotAllowed) }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">*ContextApplication<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\"> type ContextApplication struct {     Ctx *context.Context     Doc AbstractPage     Config Config     DB SQL } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h5><b>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/b><\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">HandleCustom<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\"> import (     &quot;interfaces\/app&quot; )  type HandleCustom struct {     app.HTTPController }  func (h HandleCustom) GET(app *app.ContextApplication) {     app.Ctx.SendHTML(&quot;html data here&quot;) }  func (h HandleCustom) POST(app *app.ContextApplication) { \t\/\/ and so on... } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e <u>app.HTTPController<\/u> \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (GET, POST \u0438 \u0442.\u043f.). \u0415\u0441\u043b\u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u0442\u043e \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u00abMethod not allowed\u00bb (\u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u043b\u044e\u0431\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435).<\/p>\n<h5><b>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/b><\/h5>\n<p>  Context \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438. \u041d\u0435 \u0431\u0443\u0434\u0443 \u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u044f\u0441\u043d\u043e \u043e \u0447\u0435\u043c \u0438\u0434\u0435\u0442 \u0440\u0435\u0447\u044c:<\/p>\n<pre><code class=\"go\"> func (c *Context) NotFound() \/\/ NotFound sends page with 404 http code from template tpls\/404.tpl func (c *Context) Redirect(url string) \/\/ Redirect sends http redirect with 301 code func (c *Context) Redirect303(url string) \/\/ Redirect303 sends http redirect with 303 code func (c *Context) SendJSON(data string) int \/\/ SendJSON sends json-content (data) func (c *Context) SendXML(data string) \/\/ SendXML sends xml-content (data) func (c *Context) GetCookie(key string) string \/\/ GetCookie return cookie from request by a given key. func (c *Context) SetCookie(name string, value string, others ...interface{}) \/\/ SetCookie set cookie for response. func (c *Context) CheckXsrfToken() bool \/\/ CheckXsrfToken \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 token func (c *Context) User() User \/\/ User \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f func (c *Context) Session(name string) (*Session, error) \/\/ Session \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u0435\u0441\u0441\u0438\u044e func (s *Session) Clear() \/\/ Clear \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e  \/\/ \u0438 \u0442.\u0434. <\/code><\/pre>\n<h5><b>\u0428\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440<\/b><\/h5>\n<p>  \u0412 \u0441\u043e\u0441\u0442\u0430\u0432\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 \u00abhtml\/template\u00bb. \u0415\u0433\u043e \u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0432 \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/p>\n<pre><code class=\"go\"> \/\/ loadTemplate load template from tpls\/%s.tpl func loadTemplate(Name string) *html.Template {     funcMap := html.FuncMap{         &quot;html&quot;: func(val string) html.HTML {             return html.HTML(val)         },         &quot;typo&quot;: func(val string) string {             return typo.Typo(val)         },         &quot;mod&quot;: func(args ...interface{}) interface{} {             if len(args) == 0 {                 return &quot;&quot;             }              name := args[0].(string)             ctx := new(context.Context)              if len(args) &gt; 1 {                 ctx = args[1].(*context.Context)             }              modules := reflect.ValueOf(modules.Get())             mod := modules.MethodByName(name)              if (mod == reflect.Value{}) {                 return &quot;&quot;             }              inputs := make([]reflect.Value, 0)             inputs = append(inputs, reflect.ValueOf(ctx))              ret := mod.Call(inputs)             return ret[0].Interface()         },     }      return html.Must(html.New(&quot;*&quot;).Funcs(funcMap).Delims(&quot;{{%&quot;, &quot;%}}&quot;).ParseFiles(&quot;tpls\/&quot; + Name + &quot;.tpl&quot;)) } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 AngularJS \u043c\u0435\u043d\u044f\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u0441 &quot;{{ }}&quot; \u043d\u0430 &quot;{{% %}}&quot;, \u0445\u043e\u0442\u044f, \u043f\u0440\u0438\u0437\u043d\u0430\u044e\u0441\u044c, \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u043e.<br \/>  \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e 3-\u0445 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 pipeline-\u0444\u0443\u043d\u043a\u0446\u0438\u0439:  <\/p>\n<ol>\n<li><u>html<\/u> \u2014 \u043c\u0435\u043d\u044f\u0435\u0442 \u0442\u0438\u043f \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043d\u0430 HTML, \u0447\u0442\u043e\u0431\u044b \u0448\u0430\u0431\u043b\u043e\u043d \u043d\u0435 \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b HTML-\u0441\u0442\u0440\u043e\u043a\u0438. \u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435:\n<pre><code class=\"html\">&lt;div&gt;{{% .htmlString | html %}}&lt;\/div&gt;<\/code><\/pre>\n<\/li>\n<li><u>typo<\/u> \u2014 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0442\u0438\u043f\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0435:\n<pre><code class=\"html\">&lt;h1&gt;{{% .title | typo %}}&lt;\/h1&gt;<\/code><\/pre>\n<\/li>\n<li><u>mod<\/u> \u2014 \u0437\u0430\u043f\u0443\u0441\u043a \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u0442\u0435\u043b\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:\n<pre><code class=\"html\">&lt;div&gt;{{% mod &quot;InformMenu&quot; %}}&lt;\/div&gt;<\/code><\/pre>\n<\/li>\n<\/ol>\n<pre><code class=\"go\">type AbstractPage map[string]interface{}<\/code><\/pre>\n<p>  AbstractPage \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0445 \u0432 template&#8217;\u0430\u0445. \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0417\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439  \u0432 \u043a\u043e\u0434\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\"> func (h HandleCustom) GET(app *app.ContextApplication) {     doc := app.Doc.Clone(&quot;custom&quot;) \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 AbstractPage, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c custom.tpl     doc[&quot;V1&quot;] = &quot;V1&quot;     doc[&quot;V2&quot;] = 555      result := doc.Compile()     app.Ctx.SendHTML(result) } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">custom.tpl<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"html\"> {{%define &quot;*&quot;%}} &lt;ul&gt;     &lt;li&gt;{{% .V1 %}}&lt;\/li&gt;     &lt;li&gt;{{% .V2 %}}&lt;\/li&gt; &lt;\/ul&gt; {{%end%}} <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  AbstractPage \u0438\u043c\u0435\u0435\u0442 2 \u043c\u0435\u0442\u043e\u0434\u0430:   <\/p>\n<ol>\n<li>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0435\u0442\u043e\u0434 Clone()<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\"> \/\/ Clone \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 AbstractPage c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 func (page AbstractPage) Clone(tplName string) AbstractPage {     doc := make(AbstractPage)     for k, v := range page {         doc[k] = v     }      doc[&quot;__tpl&quot;] = tplName     return doc } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 AbstractPage, \u043a\u043e\u043f\u0438\u0440\u0443\u044f \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0421\u043c\u044b\u0441\u043b \u044d\u0442\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 AbstractPage.<\/li>\n<li>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0435\u0442\u043e\u0434 Compile()<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"go\"> \/\/ Compile return page formatted with template from tpls\/%d.tpl func (page AbstractPage) Compile() string {     var data bytes.Buffer      for k, v := range page {         switch val := v.(type) {             case AbstractPage: {                 page[k] = html.HTML(val.Compile())             }             case func()string: {                 page[k] = val()             }         }     }      \/\/ \u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u043d\u0430\u044f (ctx \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0432 doc[&quot;Ctx&quot;])     getTpl(page[&quot;__tpl&quot;].(string)).Execute(&data, page)      return data.String() } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0433\u043e\u043d \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 HTML-\u043a\u043e\u0434.<\/li>\n<\/ol>\n<h4>\u0420\u0435\u0437\u044e\u043c\u0435<\/h4>\n<p>  \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0433\u0438\u0431\u043a\u043e \u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0438\u0440\u043e\u0434\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<p>  \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e Go \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043c\u0435\u043d\u044f \u0440\u0430\u0432\u043d\u043e\u0434\u0443\u0448\u043d\u044b\u043c, \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u0438 \u043c\u043d\u043e\u0433\u0438\u0445.<\/p>\n<h4>\u0421\u0441\u044b\u043b\u043a\u0438<\/h4>\n<p>  1. <a href=\"https:\/\/github.com\/dblokhin\/typo\">github.com\/dblokhin\/typo<\/a> \u2014 golang package \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0442\u0438\u043f\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c.             <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/260539\/\"> http:\/\/habrahabr.ru\/post\/260539\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>             \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Go. \u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u043d\u0438\u0439 \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u0441\u043a\u043e\u0440\u0435\u0435 \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0436\u0435 \u043d\u043e\u0432\u043e\u0438\u0441\u043f\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u044f\u0437\u044b\u043a\u0430 \u043a\u0430\u043a \u0438 \u044f. \u0425\u043e\u0442\u044f, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0441\u0432\u0435\u0436\u0438\u0435 \u0438\u0434\u0435\u0438 \u0432\u044b \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043d\u0430\u0439\u0434\u0435\u0442\u0435.<\/p>\n<p>  \u0423 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043e \u00ab\u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438\u00bb \u2014 \u044d\u0442\u043e \u0432\u0441\u0451 \u043f\u043b\u043e\u0434\u044b \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u0441\u0442\u0432\u0430 \u0438 \u0436\u0438\u0432\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430 \u043f\u0440\u0438 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u0438 \u0441 \u044f\u0437\u044b\u043a\u043e\u043c Golang.  <\/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-259551","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/259551","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=259551"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/259551\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=259551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=259551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=259551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}