docs: add doc for gen apis and mocks

Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
He Weiwei 2020-08-24 09:23:03 +00:00
parent 2ab4fbefd6
commit b689fddcd0

View File

@ -77,6 +77,20 @@ The folder graph below shows the structure of the source code folder `harbor/src
│   ├── secret │   ├── secret
│   ├── security │   ├── security
│   └── utils │   └── utils
├── controller # Source code for the controllers used by the API handlers.
│   ├── artifact
│   ├── blob
│   ├── event
│   ├── icon
│   ├── p2p
│   ├── project
│   ├── proxy
│   ├── quota
│   ├── repository
│   ├── scan
│   ├── scanner
│   ├── tag
│   ├── task
├── core # Source code for the main busines logic. Contains rest apis and all service infomation. ├── core # Source code for the main busines logic. Contains rest apis and all service infomation.
│   ├── api │   ├── api
│   ├── auth │   ├── auth
@ -112,6 +126,12 @@ The folder graph below shows the structure of the source code folder `harbor/src
│   └── src # General web page UI code of Harbor │   └── src # General web page UI code of Harbor
├── registryctl # Source code contains the main logic to handle registry. ├── registryctl # Source code contains the main logic to handle registry.
├── replication # Source code contains the main logic of replication. ├── replication # Source code contains the main logic of replication.
├── server # Source code for the APIs.
│   ├── handler
│   ├── middleware
│   ├── registry
│   ├── router
│   ├── v2.0
├── testing # Some utilities to handle testing. ├── testing # Some utilities to handle testing.
└── vendor # Go code dependencies └── vendor # Go code dependencies
├── github.com ├── github.com
@ -142,7 +162,7 @@ Harbor backend is written in [Go](http://golang.org/). If you don't have a Harbo
Ensure your GOPATH and PATH have been configured in accordance with the Go environment instructions. Ensure your GOPATH and PATH have been configured in accordance with the Go environment instructions.
**Dependency Management:** Harbor uses [dep](https://github.com/golang/dep) for dependency management of go code. The official maintainers will take the responsibility for managing the code in `vendor` directory. Please don't try to submit a PR to update the dependency code, open an issue instead. If your PR requires a change in the vendor code please make sure you discuss it with the maintainers in advance. **Dependency Management:** Harbor uses [Go modules](https://github.com/golang/go/wiki/Modules) for dependency management of go code. The official maintainers will take the responsibility for managing the code in `vendor` directory. Please don't try to submit a PR to update the dependency code, open an issue instead. If your PR requires a change in the vendor code please make sure you discuss it with the maintainers in advance.
#### Web #### Web
@ -250,6 +270,10 @@ npm run test
To build the code, please refer to [build](https://goharbor.io/docs/2.0.0/build-customize-contribute/compile-guide/) guideline. To build the code, please refer to [build](https://goharbor.io/docs/2.0.0/build-customize-contribute/compile-guide/) guideline.
**Note**: from v2.0, Harbor uses [go-swagger](https://github.com/go-swagger/go-swagger) to generate API server from Swagger 2.0 (aka [OpenAPI 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md)). To add or change the APIs, first update the `api/v2.0/swagger.yaml` file, then run `make gen_apis` to generate the API server, finally, implement or update the API handlers in `src/server/v2.0/handler` package.
As now Harbor uses `controller/manager/dao` programming model, we suggest to use [testify mock](github.com/stretchr/testify/mock) to test `controller` and `manager`. Harbor integrates [mockery](https://github.com/vektra/mockery) to generate mocks for golang interfaces using the testify mock package. To generate mocks for the interface, first add `//go:generate mockery xxx` comment with mockery command in the subpackages of `src/testing`, then run `make gen_mocks` to generate mocks.
### Keep sync with upstream ### Keep sync with upstream