<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                做任何事情都需要做好規劃,那么我們在開發博客系統之前,同樣需要做好項目的規劃,如何設置目錄結構,如何理解整個項目的流程圖,當我們理解了應用的執行過程,那么接下來的設計編碼就會變得相對容易了 ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/13.1.md#gopath以及項目設置)gopath以及項目設置 假設指定gopath是文件系統的普通目錄名,當然我們可以隨便設置一個目錄名,然后將其路徑存入GOPATH。前面介紹過GOPATH可以是多個目錄:在window系統設置環境變量;在linux/MacOS系統只要輸入終端命令`export gopath=/home/astaxie/gopath`,但是必須保證gopath這個代碼目錄下面有三個目錄pkg、bin、src。新建項目的源碼放在src目錄下面,現在暫定我們的博客目錄叫做beeblog,下面是在window下的環境變量和目錄結構的截圖: [![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/13.1.gopath.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/13.1.gopath.png?raw=true) 圖13.1 環境變量GOPATH設置 [![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/13.1.gopath2.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/13.1.gopath2.png?raw=true) 圖13.2 工作目錄在$gopath/src下 ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/13.1.md#應用程序流程圖)應用程序流程圖 博客系統是基于模型-視圖-控制器這一設計模式的。MVC是一種將應用程序的邏輯層和表現層進行分離的結構方式。在實踐中,由于表現層從Go中分離了出來,所以它允許你的網頁中只包含很少的腳本。 * 模型 (Model) 代表數據結構。通常來說,模型類將包含取出、插入、更新數據庫資料等這些功能。 * 視圖 (View) 是展示給用戶的信息的結構及樣式。一個視圖通常是一個網頁,但是在Go中,一個視圖也可以是一個頁面片段,如頁頭、頁尾。它還可以是一個 RSS 頁面,或其它類型的“頁面”,Go實現的template包已經很好的實現了View層中的部分功能。 * 控制器 (Controller) 是模型、視圖以及其他任何處理HTTP請求所必須的資源之間的中介,并生成網頁。 下圖顯示了項目設計中框架的數據流是如何貫穿整個系統: [![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/13.1.flow.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/13.1.flow.png?raw=true) 圖13.3 框架的數據流 1. main.go作為應用入口,初始化一些運行博客所需要的基本資源,配置信息,監聽端口。 2. 路由功能檢查HTTP請求,根據URL以及method來確定誰(控制層)來處理請求的轉發資源。 3. 如果緩存文件存在,它將繞過通常的流程執行,被直接發送給瀏覽器。 4. 安全檢測:應用程序控制器調用之前,HTTP請求和任一用戶提交的數據將被過濾。 5. 控制器裝載模型、核心庫、輔助函數,以及任何處理特定請求所需的其它資源,控制器主要負責處理業務邏輯。 6. 輸出視圖層中渲染好的即將發送到Web瀏覽器中的內容。如果開啟緩存,視圖首先被緩存,將用于以后的常規請求。 ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/13.1.md#目錄結構)目錄結構 根據上面的應用程序流程設計,博客的目錄結構設計如下: ~~~ |——main.go 入口文件 |——conf 配置文件和處理模塊 |——controllers 控制器入口 |——models 數據庫處理模塊 |——utils 輔助函數庫 |——static 靜態文件目錄 |——views 視圖庫 ~~~ ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/13.1.md#框架設計)框架設計 為了實現博客的快速搭建,打算基于上面的流程設計開發一個最小化的框架,框架包括路由功能、支持REST的控制器、自動化的模板渲染,日志系統、配置管理等。 ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/13.1.md#總結)總結 本小節介紹了博客系統從設置GOPATH到目錄建立這樣的基礎信息,也簡單介紹了框架結構采用的MVC模式,博客系統中數據流的執行流程,最后通過這些流程設計了博客系統的目錄結構,至此,我們基本完成一個框架的搭建,接下來的幾個小節我們將會逐個實現。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看