123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561 |
- <!DOCTYPE HTML>
- <html lang="" >
- <head>
- <meta charset="UTF-8">
- <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
- <title>开发规范 · GitBook</title>
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="description" content="">
- <meta name="generator" content="GitBook 3.2.3">
-
-
-
-
- <link rel="stylesheet" href="../gitbook/style.css">
-
-
-
- <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
-
-
-
- <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
-
-
-
- <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
-
-
-
- <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
-
-
-
- <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
-
-
-
-
-
-
- <link rel="stylesheet" href="../res/remove_publish.css">
-
-
-
-
-
-
-
-
-
-
-
-
-
- <meta name="HandheldFriendly" content="true"/>
- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
- <meta name="apple-mobile-web-app-capable" content="yes">
- <meta name="apple-mobile-web-app-status-bar-style" content="black">
- <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
- <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
-
- <link rel="next" href="test.html" />
-
-
- <link rel="prev" href="design.html" />
-
- </head>
- <body>
-
- <div class="book">
- <div class="book-summary">
-
-
- <div id="book-search-input" role="search">
- <input type="text" placeholder="Type to search" />
- </div>
-
- <nav role="navigation">
-
- <ul class="summary">
-
-
-
-
- <li>
- <a href="/BaseService/docCentor/raw/master/_book/index.html" target="_blank" class="custom-link">首页</a>
- </li>
-
-
-
- <li class="divider"></li>
-
-
-
-
-
- <li class="chapter " data-level="1.1" data-path="../">
-
- <a href="../">
-
-
- 首页
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.2" data-path="../info.html">
-
- <a href="../info.html">
-
-
- 协作信息
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3" data-path="../cooperation.html">
-
- <a href="../cooperation.html">
-
-
- 协作流程
-
- </a>
-
-
- <ul class="articles">
-
-
- <li class="chapter " data-level="1.3.1" data-path="design.html">
-
- <a href="design.html">
-
-
- 设计规范
-
- </a>
-
-
- </li>
-
- <li class="chapter active" data-level="1.3.2" data-path="dev.html">
-
- <a href="dev.html">
-
-
- 开发规范
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.3" data-path="test.html">
-
- <a href="test.html">
-
-
- 测试规范
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.4" data-path="devops.html">
-
- <a href="devops.html">
-
-
- 运维规范
-
- </a>
-
-
- </li>
-
- </ul>
-
- </li>
-
- <li class="chapter " data-level="1.4" data-path="../share/share.html">
-
- <a href="../share/share.html">
-
-
- 经验分享
-
- </a>
-
-
- <ul class="articles">
-
-
- <li class="chapter " data-level="1.4.1" data-path="../share/nodejs.html">
-
- <a href="../share/nodejs.html">
-
-
- windows下nodejs和npm的安装
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.2" data-path="../share/golang.html">
-
- <a href="../share/golang.html">
-
-
- golang相关资料
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.3" data-path="../share/webbase.html">
-
- <a href="../share/webbase.html">
-
-
- 前端基础
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.4" data-path="../share/web.html">
-
- <a href="../share/web.html">
-
-
- 前端相关资料
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.5" data-path="../share/devops.html">
-
- <a href="../share/devops.html">
-
-
- 运维资料
-
- </a>
-
-
- </li>
-
- </ul>
-
- </li>
-
- <li class="chapter " data-level="1.5" data-path="../devtools.html">
-
- <a href="../devtools.html">
-
-
- 开发工具
-
- </a>
-
-
- </li>
-
-
- <li class="divider"></li>
- <li>
- <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
- Published with GitBook
- </a>
- </li>
- </ul>
- </nav>
-
-
- </div>
- <div class="book-body">
-
- <div class="body-inner">
-
-
- <div class="book-header" role="navigation">
-
- <!-- Title -->
- <h1>
- <i class="fa fa-circle-o-notch fa-spin"></i>
- <a href=".." >开发规范</a>
- </h1>
- </div>
- <div class="page-wrapper" tabindex="-1" role="main">
- <div class="page-inner">
-
- <div id="book-search-results">
- <div class="search-noresults">
-
- <section class="normal markdown-section">
-
- <h1 id="开发规范">开发规范</h1>
- <h4 id="git建议提交规范">git建议提交规范</h4>
- <ul>
- <li><code>feat</code> 增加功能</li>
- <li><code>fix</code> 修复问题/BUG</li>
- <li><code>style</code> 代码风格相关无影响运行结果的</li>
- <li><code>perf</code> 优化/性能提升</li>
- <li><code>refactor</code> 重构</li>
- <li><code>revert</code> 撤销修改</li>
- <li><code>test</code> 测试相关</li>
- <li><code>docs</code> 文档/注释</li>
- <li><code>chore</code> 依赖更新/脚手架配置修改等</li>
- <li><code>workflow</code> 工作流改进</li>
- <li><code>ci</code> 持续集成</li>
- <li><code>types</code> 类型定义文件更改</li>
- <li><code>wip</code> 开发中</li>
- <li><code>test</code> 测试用例,包括单元测试、集成测试等</li>
- </ul>
- <h4 id="命名规范">命名规范</h4>
- <ul>
- <li>文件名:全部小写,除单元测试外,不使用_或-</li>
- <li>私有变量名:驼峰命名,见名知义,首先英文,首字母小写,尽量避免[数字 _ -]。</li>
- <li>函数、常量、公开变量名:驼峰式命名,可公开访问的的必须首字母大写</li>
- <li>在for,if等循环或分支时,推荐单字母命名来标识参数</li>
- </ul>
- <h4 id="项目设计">项目设计</h4>
- <ul>
- <li>项目需求讲解完后需求进行前后端设计</li>
- <li>设计内容可包括概念、模型、接口、重点逻辑/流程、架构等</li>
- <li>输出为md文件,可引用外部地方链接、图片。如接口可在yapi中。md可导出pdf、作图建议使用plantuml</li>
- <li>项目中需要新增修改数据库表(含mysql、mongodb、es等)时,需要与基础服务小组进行沟通。<blockquote>
- <p>基础服务小组主要负责架构设计、数据库模型管理、基础能力、中台项目开发等。</p>
- </blockquote>
- </li>
- </ul>
- <h4 id="单元测试">单元测试</h4>
- <ul>
- <li>项目开始过程要进行单元测试编写、提测前进行帽烟测试</li>
- <li>业务逻辑层必须写单元测试</li>
- <li>覆盖所有对外提供的业务方法,建议和单元测试一一对应</li>
- <li>输入和输出建议做成对应数组,方便批量执行测试</li>
- <li>api接口层单元测试,可使用postman、yapi、apifox等工具进行</li>
- </ul>
- <h4 id="代码走查">代码走查</h4>
- <ul>
- <li>项目提测前后进行代码走查,<a href="https://www.kdocs.cn/l/coMmiUiLogbb" target="_blank">走查表</a></li>
- <li>由项目负责人、其他开发成员进行走查</li>
- <li>走查参考以下接口表格进行</li>
- </ul>
- <pre><code>| 事项 | 考虑 | 实现 | 事项 | 考虑 | 实现 | 事项 | 考虑 | 实现 | 事项 | 考虑 | 实现 |
- | :--- | --- | --- | :--- | --- | --- | :--- | --- | --- | :--- | --- | --- |
- | 1.接口参数校验 | ✅ | ✅ | 2.新旧接口兼容 | - | - | 3.扩展性 | - | - | 4.防重提交处理 | ✅ | ✅ |
- | 5.重点接口,线程池 | - | - | 6.第三方接口异常、超时处理 | - | - | 7.高并发下熔断和降级处理 | - | - | 8.关键代码日志记录 | - | - |
- | 9.功能单一性 | - | - | 10.高并发场景,异步设计 | - | - | 11.高耗时,串行改并行 | - | - | 12.接口合并,批量处理接口 | - | - |
- | 13.高性能,适当使用缓存 | - | - | 14.高性能,冷热数据分离 | - | - | 15.可变化需求,参数化适配 | - | - | 16.接口幂等性 | - | - |
- | 17.读写分离,主从延时 | - | - | 18.接口返回数据,量大需要分页 | - | - | 19.SQL优化 | - | - | 20.代码锁的粒度 | - | - |
- | 21.接口状态、错误明确 | ✅ | ✅ | 22.接口异常处理 | ✅ | ✅ | 23.优化程序逻辑 | - | - | 24.注意大文件、大事务、大对象 对系统资源的耗用 | - | - |
- | 25.高访问接口限流 | - | - | 26.运行时异常处理(空值、下标越界等) | - | - | 27.接口安全性 | ✅ | ✅ | 28.分布式事务保障 | - | - |
- | 29.事务失效处理 | - | - | 30.使用设计模式 | - | - | 31.考虑线性安全 | - | - | 32.接口定义清晰易懂,命名规范 | ✅ | ✅ |
- | 33.接口的版本控制 | - | - | 34.代码规范 | ✅ | ✅ | 35.接口正确性 | ✅ | ✅ | 36.接口设计沟通(后端、前端) | - | - |
- | 37.map读写问题 | - | - | | | | | | | | | |
- </code></pre><h4 id="其他">其他</h4>
- <ul>
- <li><p>配置文件使用json、yaml,优选使用yaml(精简了引号、括号,增加注释、复用,新一代配置文件标准)</p>
- </li>
- <li><p>makefile文件编写,便于开发、编译、单元测试检查</p>
- <blockquote>
- <p>样例: </p>
- </blockquote>
- </li>
- </ul>
- <pre><code>#首行.PHONY命令忽略之前执行命令的结果
- .PHONY: all clean test check lint cover build_mac build_liniux build_win help
- #定义变量
- BIN_MAC_FILE=./bin/gotest_mac
- BIN_LINUX_FILE=./bin/gotest
- BIN_WIN_FILE=./bin/gotest.exe
- #执行所有动作
- all:clean check cover build_mac build_liniux build_win
- #清理动作
- clean:
- go clean
- rm -f ./bin/*
- #格式化动作
- check:
- go fmt ./
- go vet ./
- go fix ./
- #跑静态分析
- lint:
- golangci-lint run --enable-all
- #跑单元测试
- test:
- go test ./...
- #跑统计单元测试覆盖率
- cover:
- go test ./... -coverprofile xx.out
- go tool cover -html=xx.out
- #跑编译mac目标文件
- build_mac:
- export GOOS=drawin
- export GOARCH=amd64
- go build -ldflags="-s -w" -o ${BIN_MAC_FILE} ./main.go
- #跑编译linux目标文件
- build_liniux:
- export GOOS=linux
- export GOARCH=amd64
- go build -ldflags="-s -w" -o ${BIN_LINUX_FILE} ./main.go
- #跑编译linux目标文件
- build_win:
- export GOOS=windows
- export GOARCH=amd64
- go build -ldflags="-s -w" -o ${BIN_WIN_FILE} ./main.go
- #显示帮助
- help:
- @echo "make all 执行清理、静态检查、单元测试、单元测试覆盖统计、打包、制作Docker镜像"
- @echo "make clean 清理"
- @echo "make check vet代码静态检查"
- @echo "make lint lint代码静态检查"
- @echo "make test 单元测试"
- @echo "make cover 单元测试"
- @echo "make buildmac 编译Mac可执行文件"
- @echo "make buildlinux 编译Linux可执行文件"
- </code></pre><blockquote>
- <p>make windows安装,可使用:<a href="https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/sjlj/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0.7z)" target="_blank">Mingw-w64</a> 下载解压然后加入环境变量(复制出来一个make.exe)。
- 或者使用git自带的加入环境变量(在安装目录找到对应bin目录)。</p>
- </blockquote>
- <ul>
- <li>dockerfile、deploy
- 后续完善</li>
- </ul>
- <footer class="page-footer"><span class="copyright">jianyu360 all right reserved,powered by Gitbook</span><span class="footer-modification">修改时间:
- 2022-06-23 15:43:07
- </span></footer>
-
- </section>
-
- </div>
- <div class="search-results">
- <div class="has-results">
-
- <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
- <ul class="search-results-list"></ul>
-
- </div>
- <div class="no-results">
-
- <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
-
- </div>
- </div>
- </div>
- </div>
- </div>
-
- </div>
-
-
- <a href="design.html" class="navigation navigation-prev " aria-label="Previous page: 设计规范">
- <i class="fa fa-angle-left"></i>
- </a>
-
-
- <a href="test.html" class="navigation navigation-next " aria-label="Next page: 测试规范">
- <i class="fa fa-angle-right"></i>
- </a>
-
-
-
- </div>
- <script>
- var gitbook = gitbook || [];
- gitbook.push(function() {
- gitbook.page.hasChanged({"page":{"title":"开发规范","level":"1.3.2","depth":2,"next":{"title":"测试规范","level":"1.3.3","depth":2,"path":"cooperation/test.md","ref":"./cooperation/test.md","articles":[]},"previous":{"title":"设计规范","level":"1.3.1","depth":2,"path":"cooperation/design.md","ref":"./cooperation/design.md","articles":[]},"dir":"ltr"},"config":{"plugins":["emphasize","-highlight","tbfed-pagefooter","chapter-fold","-sharing"],"styles":{"website":"./res/remove_publish.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"jianyu360","modify_label":"修改时间:","modify_format":"YYYY-MM-DD HH:mm:ss"},"emphasize":{},"chapter-fold":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"links":{"sidebar":{"首页":"/BaseService/docCentor/raw/master/_book/index.html"}},"gitbook":"*"},"file":{"path":"cooperation/dev.md","mtime":"2022-06-23T07:43:07.760Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-06-23T07:44:07.915Z"},"basePath":"..","book":{"language":""}});
- });
- </script>
- </div>
-
- <script src="../gitbook/gitbook.js"></script>
- <script src="../gitbook/theme.js"></script>
-
-
- <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
-
-
-
- <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
-
-
-
- <script src="../gitbook/gitbook-plugin-search/search.js"></script>
-
-
-
- <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
-
-
-
- <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
-
-
-
- <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
-
-
- </body>
- </html>
|