MetaEgg Framework Template
https://github.com/Jinglever/meta-egg/releases
Install protoc:
wget https://github.com/protocolbuffers/protobuf/releases/download/v21.8/protoc-21.8-linux-x86_64.zip
mkdir -p /usr/local/protoc
sudo unzip protoc-21.8-linux-x86_64.zip -d /usr/local/protoc
sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin/protoc
make init
make generate
P.S. Maybe you need to run go mod tidy
several times.
make build
make run
P.S. You need to copy and modify configs/<project-name>.yml
to configs/<project-name>-local.yml
before run.
.
├── api -------------------------- API Generated by protoc
├── build
│ └── bin ---------------------- Binary Generated by go build
├── cmd -------------------------- Main Entry
├── configs ---------------------- Configs such as <project-name>.yml
├── docs ------------------------- Documents such as swagger
├── gen
│ ├── model -------------------- Model Generated by meta-egg
│ └── repo --------------------- Repo Generated by meta-egg
├── go.mod
├── go.sum
├── internal
│ ├── biz ---------------------- Business Logic, file name is basically the same as table name
│ ├── common
│ │ ├── cerror --------------- Custom Error, feel free to define your own error
│ │ ├── constraint ----------- Constraint, such as timezone, time format, etc.
│ │ ├── contexts ------------- Contexts, such as session, trace, etc.
│ │ └── resource ------------- Resource, such as db, redis, grpc client, etc.
│ ├── config ------------------- golang struct for config file, function to load config file, etc.
│ ├── handler
│ │ ├── grpc ----------------- GRPC Handler, file name is basically the same as table name
│ │ └── http ----------------- HTTP Handler, file name is basically the same as table name
│ ├── repo --------------------- Repo Interface, file name is basically the same as table name
│ ├── server
│ │ ├── grpc ----------------- GRPC Server, with middleware
│ │ └── http ----------------- HTTP Server, with middleware, router, etc.
│ └── usecase ------------------ UseCase, something quite like biz, but more complex so that it needs to be separated
├── LICENSE
├── Makefile
├── _manifest -------------------- Manifest for meta-egg
├── pkg -------------------------- Common Packages
├── proto ------------------------ Protobuf Files, including xx_error.proto for custom error
├── README.md
├── sql -------------------------- SQL Files, including schema.sql for table schema
└── third_party ------------------ Third Party, such as proto files, sdk for grpc client, etc.
layers from top to bottom:
- cmd
- config
- server
- handler
- usecase
- biz
- repo
- model
- common
You should not import packages from bottom to top, such as import repo
in model
, import biz
in repo
, etc.
- Modify manifest file
_manifest/<project-name>.xml
- Run
meta-egg db
to generate_manifest/sql/schema.sql
and_manifest/sql/inc.sql
. Ifinc.sql
is not empty, you need to run it manually in your database. Then you should copyschema.sql
tosql/schema.sql
to maintain the latest schema. - Run
meta-egg update
to updategen/model
andgen/repo
- if new file in
repo
,biz
,usecase
, maybe you need to modifyProviderSet
inbase.go
in their folder. - Run
make generate
to updateapi
,docs
,wire_gen.go
,repo/mock
, etc.
- Modify proto file
proto/<project-name>.proto
- Run
make pb
to updateapi
- Or, for http, you can just modify
handler/http/<table-name>.go
andserver/http/router.go
to add new api. - Then Run
make swag
to updatedocs
Special thanks to @ZZH @WZQ @GTJ @HQ for their contributions to the framework design.