<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國際加速解決方案。 廣告
                [TOC] ## 參考bilibili ``` . ├── app │ ├── admin │ │ └── foo/../ │ │ ├── cmd │ │ │ └── main.go │ │ ├── configs │ │ │ ├── http.conf │ │ │ ├── memcache.conf │ │ │ ├── mysql.con │ │ │ └── redis.con │ │ ├── internal │ │ │ ├── dao │ │ │ │ ├── dao.go │ │ │ │ └── user.go │ │ │ ├── model │ │ │ ├── server │ │ │ │ └── http │ │ │ │ └── router.go │ │ │ │ └── user.go │ │ │ └── service │ │ └── api │ │ └── api.proto │ ├── job │ │ └── foo/../ │ │ ├── cmd │ │ │ └── main.go │ │ ├── configs │ │ │ ├── http.conf │ │ │ ├── memcache.conf │ │ │ ├── mysql.con │ │ │ └── redis.con │ │ ├── internal │ │ │ ├── dao │ │ │ ├── model │ │ │ ├── server │ │ │ │ └── http │ │ │ └── service │ │ └── api │ │ └── api.proto │ ├── common │ └── service ├── library │ ├── cache │ │ ├── cache │ │ └── memcache │ ├── conf │ ├── container │ ├── database │ │ ├── orm │ │ ├── sql │ │ └── tidb │ ├── ecode │ │ └── pd │ ├── log │ ├── net │ │ ├── http │ │ ├── rpc │ │ └── strace │ └── text │ └── translate └── buid └── root.sh ``` ## 要點 1. library 是對第三方庫的封裝,或自己實現的基礎庫 2. app 中的調用的庫盡量引用 library 中,而非外部庫 3. app中的模塊,可根據實際模塊大小,來進行拆封到更細 4. 用gorm等工具并且不考慮數據庫兼容問題時,推薦還是用原生sql,且只獲取想要字段,并在 model 目錄做結構體映射 ## 模塊講解 ### 對 foo 模塊詳解 #### dao dao 模塊用來管理數據層的服務 如 dao.go在 ``` type Dao struct { db *sql.DB redis *redis.Pool redisExpire int32 mc *memcache.Pool mcExpire int32 } ``` user.go 對 sql的具體操作 ``` const ( _loadNotify = "SELECT n.id,topic.cluster,topic.topic,a.group,n.callback,n.concurrent,n.filter,n.mtime FROM notify AS n LEFT JOIN auth2 as a ON a.id=n.gid LEFT JOIN topic ON a.topic_id=topic.id WHERE n.state=1 AND n.zone=?" ) // LoadNotify load all notify config. func (d *Dao) LoadNotify(c context.Context, zone string) (ns []*model.Watcher, err error) { rows, err := d.db.Query(c, _loadNotify, zone) if err != nil { return } defer rows.Close() for rows.Next() { n := new(model.Watcher) if err = rows.Scan(&n.ID, &n.Cluster, &n.Topic, &n.Group, &n.Callback, &n.Concurrent, &n.Filter, &n.Mtime); err != nil { return } ns = append(ns, n) } return } ``` #### model 存放 dao 中獲取到的model ``` type Watcher struct { ID int64 Cluster string Topic string Group string Offset string Callback string Filter bool Concurrent int // concurrent goroutine for sub. } ``` #### http http 用來存放與http 相關的服務 1. http 的路由,及handle 2. handle的具體內部實現放在 service 中 router.php ``` ... project := version.Group("/projects") { project.GET("/favorite", favoriteProjects) project.POST("/favorite/edit", editFavorite) project.GET("/common", queryCommonProjects) } ... ``` project.go ``` ... func favoriteProjects(ctx *bm.Context) { var ( req = &model.Pagination{} err error userName string ) if err = ctx.Bind(req); err != nil { ctx.JSON(nil, err) return } if userName, err = getUsername(ctx); err != nil { ctx.JSON(nil, err) return } // 最終的生成在 service 處理 ctx.JSON(srv.FavoriteProjects(ctx, req, userName)) } ... ``` service/foo.go ``` ... func (s *Service) FavoriteProjects(c context.Context, req *model.Pagination, userName string) (resp *model.FavoriteProjectsResp, err error) { // code } ... ``` #### service 1. 把所有的服務都掛載 service 中 2. 對 handle 的具體實現放入service 中 ``` type Service struct { c *conf.Config dao *dao.Dao transferChan *fanout.Fanout cron *cron.Cron } ``` ## 可以使用
                  <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>

                              哎呀哎呀视频在线观看