sponge

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 0 Imported by: 0

README

English | 简体中文

Go Report codecov Go Reference Go

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".


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:


Generate code framework corresponding UI interface:


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.


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:

This is the egg model for web service code, and there are egg models for microservice (gRPC) code, and rpc gateway service code described in sponge documentation.


Quick start

Installation sponge:

sponge can be installed on Windows, macOS, and Linux environments. Click here to view Installation Instructions.

After installing the sponge, start the UI service:

sponge run

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


Documentation

sponge documentation


Examples of use

Simple examples (excluding business logic code)
Full project examples (including business logic code)

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


License

See the LICENSE file for licensing information.


How to contribute

You are more than welcome to join us, raise an Issue or Pull Request.

Pull Request instructions.

  1. Fork the code
  2. Create your own branch: git checkout -b feat/xxxx
  3. Commit your changes: git commit -am 'feat: add xxxxx'
  4. Push your branch: git push origin feat/xxxx
  5. Commit your pull request

Documentation

Overview

Package sponge is a powerful tool for generating web and microservice code, a microservice framework based on gin and grpc encapsulation, and an open source framework for rapid application development.

Usage:

sponge [command]

Available Commands:

completion    Generate the autocompletion script for the specified shell
config        Generate go config code from yaml file
help          Help about any command
init          Initialize sponge
merge         Merge the generated code into the template file
micro         Generate proto, model, cache, dao, service, rpc, rpc-gw, rpc-cli code
patch         Command set for patching server code
run           Open the sponge UI interface
tools         Managing sponge dependency tools
upgrade       Upgrade sponge to the latest version
web           Generate model, cache, dao, handler, web code

Flags:

-h, --help      help for sponge
-v, --version   version for sponge

Use "sponge [command] --help" for more information about a command.

Directories

Path Synopsis
api
cmd
protoc-gen-go-gin
Package main is to generate *.go(tmpl), *_router.go, *_http.go, *_router.pb.go,files.
Package main is to generate *.go(tmpl), *_router.go, *_http.go, *_router.pb.go,files.
protoc-gen-go-gin/internal/generate/handler
Package handler is to generate template code, router code, and error code.
Package handler is to generate template code, router code, and error code.
protoc-gen-go-gin/internal/generate/router
Package router is to generate gin router code.
Package router is to generate gin router code.
protoc-gen-go-gin/internal/generate/service
Package service is to generate template code, router code, and error code.
Package service is to generate template code, router code, and error code.
protoc-gen-go-gin/internal/parse
Package parse is parsed proto file to struct
Package parse is parsed proto file to struct
protoc-gen-go-rpc-tmpl
Package main is to generate *.go(tmpl), *_client_test.go, *_rpc.go files.
Package main is to generate *.go(tmpl), *_client_test.go, *_rpc.go files.
protoc-gen-go-rpc-tmpl/internal/generate/service
Package service is to generate template code, test code, and error code.
Package service is to generate template code, test code, and error code.
protoc-gen-go-rpc-tmpl/internal/parse
Package parse is parsed proto file to struct
Package parse is parsed proto file to struct
serverNameExample_grpcExample
Package main is the grpc server of the application.
Package main is the grpc server of the application.
serverNameExample_grpcExample/initial
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
serverNameExample_grpcGwPbExample
Package main is the grpc gateway server of the application.
Package main is the grpc gateway server of the application.
serverNameExample_grpcGwPbExample/initial
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
serverNameExample_grpcPbExample
Package main is the grpc server of the application.
Package main is the grpc server of the application.
serverNameExample_grpcPbExample/initial
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
serverNameExample_httpExample
Package main is the http server of the application.
Package main is the http server of the application.
serverNameExample_httpExample/initial
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
serverNameExample_httpPbExample
Package main is the http server of the application.
Package main is the http server of the application.
serverNameExample_httpPbExample/initial
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
serverNameExample_mixExample
Package main is the http and grpc server of the application.
Package main is the http and grpc server of the application.
serverNameExample_mixExample/initial
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
Package initial is the package that starts the service to initialize the service, including the initialization configuration, service configuration, connecting to the database, and resource release needed when shutting down the service.
sponge
Package main sponge is a powerful tool for generating web and microservice code, a microservice framework based on gin and grpc encapsulation, and an open source framework for rapid application development.
Package main sponge is a powerful tool for generating web and microservice code, a microservice framework based on gin and grpc encapsulation, and an open source framework for rapid application development.
sponge/commands
Package commands are subcommands of the sponge command.
Package commands are subcommands of the sponge command.
sponge/commands/generate
Package generate is to generate code, including model, cache, dao, handler, http, service, rpc, rpc-gw, rpc-cli code.
Package generate is to generate code, including model, cache, dao, handler, http, service, rpc, rpc-gw, rpc-cli code.
sponge/commands/merge
Package merge is merge the generated code into the template file, you don't worry about it affecting the logic code you have already written, in case of accidents, you can find the pre-merge code in the directory /tmp/sponge_merge_backup_code
Package merge is merge the generated code into the template file, you don't worry about it affecting the logic code you have already written, in case of accidents, you can find the pre-merge code in the directory /tmp/sponge_merge_backup_code
sponge/commands/patch
Package patch is command set for patching server code.
Package patch is command set for patching server code.
sponge/server
Package server is a sponge UI service that contains the front-end pages.
Package server is a sponge UI service that contains the front-end pages.
Package configs used to locate config file.
Package configs used to locate config file.
internal
cache
Package cache is a package that unifies the definition of caching, supporting both redis and local caching.
Package cache is a package that unifies the definition of caching, supporting both redis and local caching.
config
Package config is a package that parses configuration files into structures, and supports parsing yaml, json and toml files., code generated by https://github.com/liuzw3018/sponge.
Package config is a package that parses configuration files into structures, and supports parsing yaml, json and toml files., code generated by https://github.com/liuzw3018/sponge.
dao
Package dao is the data access object, the code for database operation is unified here.
Package dao is the data access object, the code for database operation is unified here.
ecode
Package ecode is the package that unifies the definition of http error codes or grpc error codes here.
Package ecode is the package that unifies the definition of http error codes or grpc error codes here.
handler
Package handler is a package of http request processing business logic.
Package handler is a package of http request processing business logic.
model
Package model is the initial database driver and define the data structures corresponding to the tables.
Package model is the initial database driver and define the data structures corresponding to the tables.
routers
Package routers is a package dedicated to registering routes, and supports both manual route registration and automatic route registration.
Package routers is a package dedicated to registering routes, and supports both manual route registration and automatic route registration.
rpcclient
Package rpcclient is the rpc client package, used to connect to grpc server, rich plugin support by default, such as service discovery, load balancing, link tracking and so on.
Package rpcclient is the rpc client package, used to connect to grpc server, rich plugin support by default, such as service discovery, load balancing, link tracking and so on.
server
Package server is a package that holds the http or grpc service.
Package server is a package that holds the http or grpc service.
service
Package service A grpc server-side or client-side package that handles business logic.
Package service A grpc server-side or client-side package that handles business logic.
types
Package types define the structure of request parameters and respond results in this package
Package types define the structure of request parameters and respond results in this package
pkg
app
Package app is starting and stopping services gracefully, using golang.org/x/sync/errgroup to ensure that multiple services are started properly at the same time.
Package app is starting and stopping services gracefully, using golang.org/x/sync/errgroup to ensure that multiple services are started properly at the same time.
cache
Package cache is memory and redis cache libraries.
Package cache is memory and redis cache libraries.
conf
Package conf is parsing yaml, json, toml configuration files to go struct.
Package conf is parsing yaml, json, toml configuration files to go struct.
consulcli
Package consulcli is connecting to the consul service client.
Package consulcli is connecting to the consul service client.
container/group
Package group provides a sample lazy load container.
Package group provides a sample lazy load container.
encoding
Package encoding Provides encoding and decoding of json, protobuf and gob.
Package encoding Provides encoding and decoding of json, protobuf and gob.
encoding/json
Package json is a JSON encoding and decoding.
Package json is a JSON encoding and decoding.
encoding/proto
Package proto is a protobuf encoding and decoding.
Package proto is a protobuf encoding and decoding.
errcode
Package errcode is used for http and grpc error codes, include system-level error codes and business-level error codes
Package errcode is used for http and grpc error codes, include system-level error codes and business-level error codes
etcdcli
Package etcdcli is use for connecting to the etcd service
Package etcdcli is use for connecting to the etcd service
gin/handlerfunc
Package handlerfunc is used for public http request handler.
Package handlerfunc is used for public http request handler.
gin/middleware
Package middleware is gin middleware plugin.
Package middleware is gin middleware plugin.
gin/middleware/metrics
Package metrics is gin metrics library, collect five metrics, "uptime", "http_request_count_total", "http_request_duration_seconds", "http_request_size_bytes", "http_response_size_bytes".
Package metrics is gin metrics library, collect five metrics, "uptime", "http_request_count_total", "http_request_duration_seconds", "http_request_size_bytes", "http_response_size_bytes".
gin/prof
Package prof is used for gin profiling.
Package prof is used for gin profiling.
gin/response
Package response provides wrapper gin returns json data in the same format.
Package response provides wrapper gin returns json data in the same format.
gin/swagger
Package swagger is gin swagger library.
Package swagger is gin swagger library.
gin/validator
Package validator is gin request parameter check library.
Package validator is gin request parameter check library.
gobash
Package gobash provides the ability to execute commands, scripts, executables in the go environment with live log output.
Package gobash provides the ability to execute commands, scripts, executables in the go environment with live log output.
gofile
Package gofile is file and directory management libraries.
Package gofile is file and directory management libraries.
gohttp
Package gohttp is http request client, which only supports returning json format.
Package gohttp is http request client, which only supports returning json format.
goredis
Package goredis is a library wrapped on top of github.com/go-redis/redis.
Package goredis is a library wrapped on top of github.com/go-redis/redis.
gotest
Package gotest is a library that simulates the testing of cache, dao and handler.
Package gotest is a library that simulates the testing of cache, dao and handler.
grpc/benchmark
Package benchmark is compression testing of rpc methods and generation of reported results.
Package benchmark is compression testing of rpc methods and generation of reported results.
grpc/grpccli
Package grpccli is grpc client with support for service discovery, logging, load balancing, trace, metrics, retries, circuit breaker.
Package grpccli is grpc client with support for service discovery, logging, load balancing, trace, metrics, retries, circuit breaker.
grpc/gtls
Package gtls provides grpc secure connectivity, supporting both server-only authentication and client-server authentication.
Package gtls provides grpc secure connectivity, supporting both server-only authentication and client-server authentication.
grpc/gtls/certfile
Package certfile is used to locate the certificate file.
Package certfile is used to locate the certificate file.
grpc/interceptor
Package interceptor provides commonly used grpc client-side and server-side interceptors.
Package interceptor provides commonly used grpc client-side and server-side interceptors.
grpc/keepalive
Package keepalive is setting grpc keepalive parameters.
Package keepalive is setting grpc keepalive parameters.
grpc/metrics
Package metrics is grpc's server-side and client-side metrics can continue to be captured using prometheus.
Package metrics is grpc's server-side and client-side metrics can continue to be captured using prometheus.
grpc/resolve
Package resolve is setting grpc client-side load balancing policy.
Package resolve is setting grpc client-side load balancing policy.
jwt
Package jwt is token generation and validation.
Package jwt is token generation and validation.
jy2struct
Package jy2struct is a library for generating go struct code, supporting json and yaml.
Package jy2struct is a library for generating go struct code, supporting json and yaml.
krand
Package krand is a library for generating random strings, integers, floating point numbers.
Package krand is a library for generating random strings, integers, floating point numbers.
logger
Package logger is log library encapsulated in https://github.com/uber-go/zap
Package logger is log library encapsulated in https://github.com/uber-go/zap
mysql
Package mysql is a library wrapped on top of gorm.io/gorm, with added features such as link tracing, paging queries, etc.
Package mysql is a library wrapped on top of gorm.io/gorm, with added features such as link tracing, paging queries, etc.
mysql/query
Package query is a library for mysql query, support for complex conditional paging queries.
Package query is a library for mysql query, support for complex conditional paging queries.
nacoscli
Package nacoscli provides for getting the configuration from the nacos configuration center and parse it into a structure.
Package nacoscli provides for getting the configuration from the nacos configuration center and parse it into a structure.
prof
Package prof is wrap the official `net/http/pprof` route and add the profile io wait time route.
Package prof is wrap the official `net/http/pprof` route and add the profile io wait time route.
rabbitmq
Package rabbitmq is a go wrapper for rabbitmq
Package rabbitmq is a go wrapper for rabbitmq
rabbitmq/consumer
Package consumer is the generic consumer-side processing logic for the four modes direct, topic, fanout, headers
Package consumer is the generic consumer-side processing logic for the four modes direct, topic, fanout, headers
rabbitmq/producer
Package producer is the generic producer-side processing logic for the four modes direct, topic, fanout, headers.
Package producer is the generic producer-side processing logic for the four modes direct, topic, fanout, headers.
replacer
Package replacer is a library of replacement file content, supports replacement of files in local directories and embedded directory files via embed.
Package replacer is a library of replacement file content, supports replacement of files in local directories and embedded directory files via embed.
servicerd/discovery
Package discovery is service discovery library, supports etcd, consul and nacos.
Package discovery is service discovery library, supports etcd, consul and nacos.
servicerd/registry
Package registry is service registry library, supports etcd, consul and nacos.
Package registry is service registry library, supports etcd, consul and nacos.
servicerd/registry/consul
Package consul is registered as a service using consul.
Package consul is registered as a service using consul.
servicerd/registry/etcd
Package etcd is registered as a service using etcd.
Package etcd is registered as a service using etcd.
servicerd/registry/nacos
Package nacos is registered as a service using nacos.
Package nacos is registered as a service using nacos.
shield/circuitbreaker
Package circuitbreaker is an adaptive circuit breaker library, support for use in gin middleware and grpc interceptors.
Package circuitbreaker is an adaptive circuit breaker library, support for use in gin middleware and grpc interceptors.
shield/cpu
Package cpu is a library that calculates cpu and memory usage.
Package cpu is a library that calculates cpu and memory usage.
shield/ratelimit
Package ratelimit is an adaptive rate limit library, support for use in gin middleware and grpc interceptors.
Package ratelimit is an adaptive rate limit library, support for use in gin middleware and grpc interceptors.
shield/window
Package window is a library that calculates windows cpu and memory usage.
Package window is a library that calculates windows cpu and memory usage.
sql2code
Package sql2code provides for generating code for different purposes according to sql, support generating json, gorm model, update parameter, request parameter code, sql can be obtained from parameter, file, db three ways, priority from high to low.
Package sql2code provides for generating code for different purposes according to sql, support generating json, gorm model, update parameter, request parameter code, sql can be obtained from parameter, file, db three ways, priority from high to low.
sql2code/parser
Package parser is a library that parses to go structures based on sql and generates the code needed based on the template.
Package parser is a library that parses to go structures based on sql and generates the code needed based on the template.
stat
Package stat provides for counting system and process cpu and memory information, alarm notification support.
Package stat provides for counting system and process cpu and memory information, alarm notification support.
stat/cpu
Package cpu is a library that counts system and process cpu usage.
Package cpu is a library that counts system and process cpu usage.
stat/mem
Package mem is a library that counts system and process memory usage.
Package mem is a library that counts system and process memory usage.
tracer
Package tracer is a library wrapped in go.opentelemetry.io/otel.
Package tracer is a library wrapped in go.opentelemetry.io/otel.
utils
Package utils is a library of commonly used utility functions.
Package utils is a library of commonly used utility functions.

Jump to

Keyboard shortcuts

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