A Powerful Golang Productivity Tool, Golang can also “Low-Code Development”
Tags: go, web, microservices
Published: 2023-04-13 07:26:40

[sponge](https://github.com/zhufuyi/sponge) is a powerful golang productivity tool that integrates `automatic code generation`, `web and microservices frameworks`, `basic development framework`. sponge has a wealth of generating code commands, generating different functional code can be combined into a complete service (similar to the way that artificially broken sponge cells can automatically recombine into a new sponge). The code is decoupled and modularly designed, it is easy to build a complete project from development to deployment, so that you develop web or microservices project easily, golang can also be "low-code development".

<br>

If you are developing a web or microservice with a simple CRUD API interface, you don't need to write a single line of golang code to compile and deploy to servers, dockers, k8s, and the complete service code is generated by sponge.

If you develop a generic web or microservice, you need to manually write code in addition to defining the data table, defining the api interface in the proto file, and filling in the specific business logic code in the generated template file. Other golang codes are generated by sponge.

<br>

Repo：[https://github.com/zhufuyi/sponge](https://github.com/zhufuyi/sponge)  
Docs：[https://go-sponge.com/](https://go-sponge.com)  

<br>

### sponge generates the code framework

sponge is mainly based on **SQL** and **Protobuf** two ways to generate code, each way has to generate code for different functions.

**Generate code framework:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2427fx6ai3wqg84556kv.png)

<br>

**Generate code framework corresponding UI interface:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h0n6y72jh2j4mhcm2sac.png)

<br>

### Services framework

sponge generated microservice code framework is shown in the figure below, which is a typical microservice hierarchical structure, with high performance, high scalability, contains commonly used service governance features, you can easily replace or add their own service governance features.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cirllg2rldt15h46u590.png)

<br>

### Egg model for complete service code

The sponge separates the two major parts of code during the process of generating web service code. It isolates the business logic from the non-business logic. For example, consider the entire web service code as an egg. The eggshell represents the web service framework code, while both the albumen and yolk represent the business logic code. The yolk is the core of the business logic (manually written code). It includes defining MySQL tables, defining API interfaces, and writing specific logic code.On the other hand, the albumen acts as a bridge connecting the core business logic code to the web framework code (automatically generated, no manual writing needed). This includes the registration of route code generated from proto files, handler method function code, parameter validation code, error codes, Swagger documentation, and more.

Egg model profiling diagram for `⓷Web services created based on protobuf`:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iq2zdbrp2zaj2she52r8.png)

This is the egg model for web service code, and there are egg models for microservice (grpc) code, and grpc gateway service code described in [sponge documentation](https://go-sponge.com/learn-about-sponge?id=%f0%9f%8f%b7project-code-egg-model).

<br>

### Quick start

**Installation sponge:**

sponge can be installed on Windows, macOS, and Linux environments. Click here to view [Installation Instructions](https://github.com/zhufuyi/sponge/blob/main/assets/install-en.md).

After installing the sponge, start the UI service:

```bash
sponge run
```

Visit `http://localhost:24631` in your browser, generate code by manipulating it on the page.

<br>

### Examples of use

#### Simple examples

No specific business logic code is included.

- [1_web-gin-CRUD](https://github.com/zhufuyi/sponge_examples/tree/main/1_web-gin-CRUD)
- [2_micro-grpc-CRUD](https://github.com/zhufuyi/sponge_examples/tree/main/2_micro-grpc-CRUD)
- [3_web-gin-protobuf](https://github.com/zhufuyi/sponge_examples/tree/main/3_web-gin-protobuf)
- [4_micro-grpc-protobuf](https://github.com/zhufuyi/sponge_examples/tree/main/4_micro-grpc-protobuf)
- [5_micro-gin-rpc-gateway](https://github.com/zhufuyi/sponge_examples/tree/main/5_micro-gin-rpc-gateway)
- [6_micro-cluster-demo](https://github.com/zhufuyi/sponge_examples/tree/main/6_micro-cluster)

#### Complete project examples

- [7_community-single](https://github.com/zhufuyi/sponge_examples/tree/main/7_community-single)
- [8_community-cluster](https://github.com/zhufuyi/sponge_examples/tree/main/8_community-cluster)

<br>