Go- project structure and code organization

Brief introduction

做大量的输入,通过对比、借鉴,加上自己的经验,产出一个尽可能优的方案。

Excellent example of the structure of the open source community projects

因为最新的 Go 版本已经使用 module 作为版本依赖,所以,所有项目的 vendor 我都忽略,建议直接使用 module 来管理依赖,而且较好的解决某些库国内访问不了的问题,参考:https://studygolang.com/topics/8737

Docker

https://github.com/moby/moby

├── api      // 存放对外公开的 API 规则
├── builder  // 存放构建脚本等
├── cli      // 命令行的主要逻辑 
├── cmd      // 存放可执行程序,main 包放这个目录中
├── contrib  // 存放一些有用的脚本或文件,但不是项目的核心部分
├── docs    // 存放文档
├── internal // 只在本项目使用的包(私有)
├── pkg     // 本项目以及其他项目可以使用的包(公有)
├── plugin  // 提供插件功能

Kubernetes

https://github.com/kubernetes/kubernetes

├── api
├── build  // 存放构建脚本等
├── cmd
├── docs
├── pkg
├── plugin
├── test    // 单元测试之外的测试程序、测试数据
├── third_party // 经过修改的第三方的代码

gogs

https://github.com/gogs/gogs

├── cmd
├── conf    // 对配置进行解析
├── docker  // 存放 docker 脚本
├── models  // MVC 中的 model
├── pkg
├── public  // 静态公共资源,实际项目会将其存入 CDN
├── routes  // 路由
├── scripts // 脚本文件
├── templates // 存放模板文件
``

### influxdb
https://github.com/influxdata/influxdb

Cmd ├──
├── Docker
├── docs
├── HTTP // store HTTP Handler, the equivalent of the MVC the Controller
├── Internal
├── Models
├── pkg
├── scripts
`` `

Open Source Project Summary

Overall, these outstanding open source project, there is no uniform way consistent directory structure, but in general, there are some common areas, which have ** https://github.com/golang-standards/project-layout ** This project.

Guess you like

Origin www.cnblogs.com/Paul-watermelon/p/11230197.html