sponge is a powerful code generation tool, a microservices framework based on gin and gRPC.
Go to file
2022-10-19 23:43:52 +08:00
.github optimize code 2022-10-19 23:43:52 +08:00
api improve test doce 2022-10-13 22:28:23 +08:00
assets update README 2022-10-12 19:48:27 +08:00
build update deploy 2022-10-07 23:16:56 +08:00
cmd optimize code 2022-10-19 23:43:52 +08:00
configs optimize code 2022-10-19 23:43:52 +08:00
deployments optimize code 2022-10-19 23:43:52 +08:00
docs feat: implement sponge commands 2022-10-17 23:11:21 +08:00
internal optimize code 2022-10-19 23:43:52 +08:00
pkg optimize code 2022-10-19 23:43:52 +08:00
scripts optimize code 2022-10-19 23:43:52 +08:00
test add github workflows 2022-10-09 22:26:28 +08:00
third_party init 2022-09-19 23:24:11 +08:00
.gitignore optimize code 2022-10-19 23:43:52 +08:00
.golangci.yml optimize code 2022-10-19 23:43:52 +08:00
doc.go feat: implement sponge commands 2022-10-17 23:11:21 +08:00
go.mod feat: implement sponge commands 2022-10-17 23:11:21 +08:00
go.sum feat: implement sponge commands 2022-10-17 23:11:21 +08:00
Jenkinsfile update deploy 2022-10-07 23:16:56 +08:00
LICENSE Initial commit 2022-09-19 23:18:08 +08:00
Makefile optimize code 2022-10-19 23:43:52 +08:00
README.md optimize code 2022-10-19 23:43:52 +08:00

sponge

Go Report codecov Go Reference Go License: MIT

sponge is a microservices framework for quickly creating http or grpc code. Generate codes config, ecode, model, dao, handler, router, http, proto, service, grpc from SQL DDL, these codes can be combined into complete services (similar to how a broken sponge cell can automatically reorganize into a new sponge).

Features :


The directory structure follows golang-standards/project-layout.

.
├── api            # Grpc's proto file and corresponding code
├── assets         # Other assets used with the repository (images, logos, etc.)
├── build          # Packaging and continuous integration
├── cmd            # The application's directory
├── configs        # Directory of configuration files
├── deployments    # IaaS, PaaS, system and container orchestration deployment configurations and templates
├─ docs            # Design documentation and interface documentation
├── internal       # Private application and library code
│ ├── cache        # Business wrapper-based cache
│ ├── config       # Go struct for config file mapping
│ ├── dao          # Data access
│ ├── ecode        # Custom business error codes
│ ├── handler      # Business function implementation for http
│ ├── model        # Database model
│ ├── routers      # Http routing
│ ├── server       # Service entry, including http and grpc servers
│ ├── service      # Business function implementation for grpc
│ └── types        # Request and response types for http
├── pkg            # library code that external applications can use
├── scripts        # Scripts for performing various build, install, analysis, etc. operations
├── test           # Additional external test applications and test data
└── third_party    # External helpers, forked code and other third party tools

The development specification follows the Uber Go Language Coding Specification.


Quick start

Install

go install github.com/zhufuyi/sponge/cmd/sponge@latest

sponge update

Quickly create a http project

Creating a new http server

(1) Generate http server code

sponge http --module-name=account --server-name=account --project-name=account --repo-addr=zhufuyi --db-dsn=root:123456@(127.0.0.1:3306)/test --db-table=student

(2) Modify the configuration file configs/<service name>.yml

  • Modify the redis configuration
  • If the field enableTracing is true, the jaeger address must be set
  • If the field enableRegistryDiscovery is true, the etcd address must be set

(3) Generate swagger documentation

make docs

(4) Start up the server

Way 1: Run locally in the binary

make run

Copy http://localhost:8080/swagger/index.html to your browser and test the api interface.

Way 2: Run in docker. Prerequisite: docker and docker-compose are already installed.

# Build the docker image
make docker-image

# Start the service
make deploy-docker

# Check the status of the service, if it is healthy, it started successfully
cd deployments/docker-compose
docker-compose ps

Way 3: Run in k8s. Prerequisite: docker and kubectl are already installed.

# Build the image
make image-build REPO_HOST=zhufuyi TAG=latest

# Push the image to the remote image repository and delete the local image after a successful upload
make image-push REPO_HOST=zhufuyi TAG=latest

# Deploy k8s
kubectl apply -f deployments/kubernetes/
make deploy-k8s

# Check the status of the service
kubectl get -f account-deployment.yml

You can also use Jenkins to automatically build deployments to k8s.


Creating a new handler

sponge handler --module-name=account --db-dsn=root:123456@(127.0.0.1:3306)/test --db-table=teacher --out=./account

Start up the server

make docs && make run

Copy http://localhost:8080/swagger/index.html to your browser and test the api interface.


Quick create a grpc project

Creating a new grpc server

(1) Generate grpc server code

sponge grpc --module-name=account --server-name=account --project-name=account --repo-addr=zhufuyi --db-dsn=root:123456@(127.0.0.1:3306)/test --db-table=student

(2) Modify the configuration file configs/.yml

  • Modify the redis configuration
  • If the field enableTracing is true, the jaeger address must be set
  • If the field enableRegistryDiscovery is true, the etcd address must be set

(3) Generating grpc code

make proto

(4) Start up the server

Way 1: Run locally in the binary

make run

Use IDE to open the file internal/service/<table name>_client_test.go to test the api interface of grpc, you can copy the pressure test report to your browser to view it. Or use the go test command to execute the test cases.

Way 2: Run in docker

# Build the docker image
make docker-image

# Start the service
make deploy-docker

# Check the status of the service, if it is healthy, it started successfully
cd deployments/docker-compose
docker-compose ps

Way 3: Run in k8s

# Build the image
make image-build REPO_HOST=zhufuyi TAG=latest

# Push the image to the remote image repository and delete the local image after a successful upload
make image-push REPO_HOST=zhufuyi TAG=latest

# Deploy k8s
kubectl apply -f deployments/kubernetes/
make deploy-k8s

# Check the status of the service
kubectl get -f account-deployment.yml

You can also use Jenkins to automatically build deployments to k8s.


Creating a new service

sponge service --module-name=account --server-name=account --db-dsn=root:123456@(127.0.0.1:3306)/test --db-table=teacher --out=./account

Start up the server

make proto && make run

Use IDE to open the file internal/service/<table name>_client_test.go to test the api interface of grpc.