Layout
The cwgo tool supports the generation of MVC Layout at present, and more templates will be expanded for users to use in the future.
Code Structure
The MVC layout is automatically generated when the server code is generated using the cwgo tool. When using the demo in Getting Started, the generated HTTP project directory is as follows:
├── biz // business logic directory
│ ├── dal // data access layer
│ │ ├── init.go
│ │ ├── mysql
│ │ │ └── init.go
│ │ └── redis
│ │ └── init.go
│ ├── handler // view layer
│ │ └── hello
│ │ └── example
|
│ │ └── hello_service_test.go // single test file
│ ├── router // generated code related to routes defined in idl
│ │ ├── hello
│ │ │ └── example // hello/example corresponds to the namespace defined in thrift idl; for protobuf idl, it corresponds to the last level of go_package
│ │ │ ├── hello.go // The route registration code generated by cwgo for the route defined in hello.thrift; every update related idl will regenerate the file
│ │ │ └── middleware.go // Default middleware function, hz adds a middleware to each generated routing group by default; when updating, it will search for existing middleware in the current file and append new middleware at the end
│ │ └── register.go // call to register the routing definition in each idl file; when a new idl is added, it will automatically insert its routing registration call when updating; do not move
│ ├── service // service layer, where business logic is stored. When updating, the new method appends the file.
│ │ ├── hello_method.go // specific business logic
│ │ └── hello_method_test.go
│ └── utils // tool directory
│ └── resp.go
├── build.sh // compile script
├── conf // Store configuration files in different environments
│ └── ...
├── docker-compose.yaml
├── go.mod // go.mod file, if not specified on the command line, the relative path relative to GOPATH will be used as the module name by default
├── hertz_gen // Generate code related to IDL content
│ └── ...
├── idl
│ └── hello.thrift
├── main.go // program entry
├── readme.md
└── script // startup script
└── bootstrap.sh
The RPC project directory is as follows:
├── biz // business logic directory
│ ├── dal // data access layer
│ │ ├── init.go
│ │ ├── mysql
│ │ │ └── init.go
│ │ └── redis
│ │ └── init.go
│ └── service // service layer, where business logic is stored. When updating, the new method appends the file.
│ ├── HelloMethod.go
│ └── HelloMethod_test.go
├── build.sh
├── conf // Store configuration files in different environments
│ └── ...
├── docker-compose.yaml
├── go.mod // go.mod file, if not specified on the command line, the relative path relative to GOPATH will be used as the module name by default
├── handler.go // Business logic entry, will be fully covered when updated
├── idl
│ └── hello. thrift
├──kitex.yaml
├── kitex_gen // Generate code related to IDL content, do not touch
│ └── ...
├── main.go // program entry
├── readme.md
└── script // startup script
└── bootstrap.sh
Last modified
July 29, 2024
: docs(hertz): unified `app.HandlerFunc` style (#1112) (451f476)