sponge

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 0 Imported by: 0

README

sponge 中文

Go Report codecov Go Reference Go

sponge is a microservice framework, a tool for quickly creating microservice code. sponge has a rich generating code commands, a total of 12 different functional code, these functional code can be combined into a complete service (similar to artificially broken sponge cells can be automatically reorganized into a new sponge ). Microservice code features include logging, service registration and discovery, registry, rate limiter, circuit breaker, trace, metrics monitoring, pprof performance analysis, statistics, caching, CICD. The code uses a decoupled layered structure and it's easy to add or replace functional code. As an efficiency-enhancing tool, commonly repeated code is basically generated automatically and only business logic code needs to be populated based on the generated template code examples.


sponge command framework

The generated code is based on three approaches Yaml, SQL DDL and Protocol buffers, each possessing different functional code generation, and the framework diagram of the generated code is shown in Figure 1-1.

Figure 1-1 spong generation code framework diagram


  • Yaml generates configuration files corresponding to go struct code.
  • SQL DDL generated code includes http, handler, dao, model, proto, rpc, service, divided into two types of web and rpc, web and rpc types have their own sub-modules, each module code can be generated separately, between the modules like an onion layer of independent decoupling. The code includes standardized CRUD (add, delete, change, check) business logic, which can be directly compiled and used.
    • web type code: Generate http service code including handler, dao, model three sub-module code, as shown in the diagram inward contain, the same principle, generate handler module code contains dao, model two sub-module code.
    • rpc type code: generate rpc service code including service, dao, model, protocol buffers four sub-modules, as shown in the diagram inwards contain, generate service module code including dao, model, protocol buffers three sub-module code.
  • The code generated by Protocol buffers includes http-pb, rpc-pb, rpc-gw-pb, also divided into web and rpc types, where http-pb, rpc-pb are usually used in combination with dao, model code generated by SQL DDL.
    • http-pb: http service code includes two sub-modules, router and handler template, excluding the operation database sub-module, and subsequent business logic code is filled to the handler template file.
    • rpc-pb: rpc service code includes service template a sub-module, not including the operation database module, subsequent business logic code filled to the service template file.
    • rpc-gw-pb: rpc gateway is actually an http service, including two submodules, router and service template, where the service template code is the business logic code related to calling the rpc service.

In the same folder, if the latest generated code is found to conflict with the original code, sponge will cancel the generation process and will not make any changes to the original code, so you don't have to worry about writing business logic code that is overwritten.


Microservices framework

The microservice code framework created by sponge is shown in Figure 1-2, which is a typical microservice hierarchy containing common service governance functions.

Figure 1-2 Microservices framework diagram


Microservices main functions:


The code directory structure follows project-layout, and the code directory structure is shown below.

.
├── api               # proto files and the generated *pb.go directory
├── assets            # Directory of other assets used with the repository (images, logos, etc.)
├── build             # Package and continuous integration directory
├── cmd               # Program entry directory
├── configs           # Directory for configuration files
├── deployments       # Configuration and template directories for IaaS, PaaS, system and container orchestrated deployments
├─ docs               # Design documentation and interface documentation directory
├── internal          # The code directory for private applications and libraries
│ ├── cache           # business wrapper based cache directory
│ ├── config          # The configuration file directory for the Go structure
│ ├── dao             # Data access directory
│ ├── ecode           # Custom business error code directory
│ ├── handler         # http's business function implementation directory
│ ├── model           # Database model directory
│ ├── routers         # http routing directory
│ ├── rpcclient       # The client directory to connect to the rpc service
│ ├── server          # Service entry, including http, rpc, etc.
│ ├── service         # rpc's business function implementation directory
│ └── types           # Directory of request and response types for http
├── pkg               # The directory of libraries that external applications can use
├── scripts           # A directory of scripts for performing various build, installation, analysis, etc. operations
├── test              # Additional external test procedures and test data
└── third_party       # External helpers, forked code, and other third-party tools

The web service and rpc service directory structures are basically the same, with some directories unique to the web service (routers, handlers, types in the internal directory) and some directories unique to the rpc service (services in the internal directory).


Documentation

If it's useful to you, give it a star ⭐.


License

See the LICENSE file for licensing information.

Documentation

Overview

Package sponge is a microservice framework, a tool for quickly creating microservice code. sponge has a rich generating code commands, a total of 12 different functional code, these functional code can be combined into a complete service (similar to artificially broken sponge cells can be automatically reorganized into a new sponge ). Microservice code features include logging, service registration and discovery, registry, rate limit, circuit breaker, trace, metrics monitoring, pprof performance analysis, statistics, caching, CICD. The code uses a decoupled layered structure and it's easy to add or replace functional code. As an efficiency-enhancing tool, commonly repeated code is basically generated automatically and only business logic code needs to be populated based on the generated template code examples.

https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/README.md

sponge -h
sponge a microservice framework, a tool for quickly creating microservice code.

Usage:
sponge [command]

Available Commands:
completion  Generate the autocompletion script for the specified shell
config         Generate go config codes from yaml file
help           Help about any command
init            Initialize sponge
micro        Generate proto, model, dao, service, rpc, rpc-gw, rpc-cli codes
tools         Managing sponge dependency tools
update      Update sponge to the latest version
web          Generate model, dao, handler, http codes

Directories

Path Synopsis
api
cmd
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag
internal
dao
pkg
app
container/group
Package group provides a sample lazy load container.
Package group provides a sample lazy load container.
jwt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL