nirvana icon indicating copy to clipboard operation
nirvana copied to clipboard

Recommended structures for Nirvana projects

Open supereagle opened this issue 4 years ago • 1 comments

Is this a BUG REPORT or FEATURE REQUEST?:

Uncomment only one, leave it on its own line:

/kind bug /kind feature

What happened:

We did discuss this before, the proposed (slightly modified) structure is:

.                                   #
├── Gopkg.toml                      #
├── Makefile                        #
├── README.md                       # 
├── apis                            # 存放 apidocs (swagger json)
│   ├── api.v1.json                 #
│   └── api.v2.json                 #
├── bin                             # 存放编译后的二进制文件
│   └── nirvana-myproject           #
├── build                           # 存放 Dockerfile
│   └── nirvana-myproject           #
│       └── Dockerfile              #
├── cmd                             # 存放项目的启动命令
│   └── nirvana-myproject           #
│       └── main.go                 #
├── nirvana.yaml                    #
├── pkg                             # 存放 api 需要用到的结构体与相应的 converters, 按版本区分
│   ├── apis                        #
│   │   └── v1                      #
│   │       ├── converters          #
│   │       │   └── converters.go   #
│   │       └── types.go            #
│   │       ├── descriptors          #
│   │           ├── descriptors.go      #
│   │           └── message.go          # 对应 message 业务逻辑的 API 定义
│   ├── filters                     # 存放 HTTP Request 过滤器
│   │   └── filter.go               #
│   ├── handler                     # 存放 API 需要用到的逻辑处理
│   │   └── message.go              #
│   ├── middlewares                 # 存放中间件
│   │   └── middlewares.go          #
│   ├── modifiers                   # 存放 Definition 修改器
│   │   └── modifiers.go            #
│   └── version                     # 项目版本信息目录
│       └── version.go              #
└── vendor        

Refer to the discussion for details.

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

supereagle avatar Apr 30 '20 10:04 supereagle

As with @ddysher's comments at nirvana-practice, I have no problem with the current structure in nirvana-template-project repo, except that the handler directory should be renamed to handlers.

Strictly speaking, handler/middlewares/modifiers should all be moved into pkg/apis/v1 (e.g. you can't say for sure that modifiers won't touch any v1 data structure).

But this makes the code hard to reason about. I'd vote for current structure and keep it as is. The pkg/apis is only used for user-facing structures and routes.

iawia002 avatar Jun 02 '20 07:06 iawia002