Giter Club home page Giter Club logo

sponge's Introduction

English | 简体中文

Go Report codecov Go Reference Go Awesome Go License: MIT

Sponge is a powerful development framework that integrates automatic code generation, Gin and GRPC. Sponge has a rich set of code generation commands, and the generated different functional codes can be combined into a complete service (similar to how artificially broken sponge cells can automatically reassemble into a new complete sponge). From development, testing, API documentation to deployment, one-stop project development greatly improves development efficiency and reduces development difficulty, implementation of "low-code way" development projects.


If you are develop web service or microservice with CRUD APIs, you don't need to write any Go code can be compiled and deployed to the linux server, docker, k8s, just need to connect to the database (mysql、mongodb、postgresql、tidb、sqlite) to generate a complete backend service Go code.

If you develop generic web or microservices, just focus on the three core parts of define tables in the database, define api description information in the proto files, fill in business logic code in the generated template files, and the rest of the Go code is automatically generated by sponge.


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. SQL supports databases mysql, mongodb, postgresql, tidb, sqlite.

Generate Code Framework


Generate Code Framework Corresponding UI Interface


Microservice framework

Sponge is also a microservices framework, the framework diagram is shown 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.


Performance testing of http and grpc service code created by the microservices framework: 50 concurrent, 1 million total requests.

http-server

grpc-server

Click to view the test code.


Key Features


Project Code Directory Structure

The project code directory structure created by sponge follows the project-layout and is structured as follows. Supported repository types are monolithic application single repository (monolith), microservice multi-repository (multi-repo), microservice single repository (mono-repo).

.
├── api            # Directory for exposing external API interfaces, typically containing proto files and generated *.pb.go files. The directory structure is typically in the form `api/xxx/v1`, where v1 indicates the version.
├── assets         # Store various static resources, such as images, markdown files, etc.
├── cmd            # Program entry directory
│    └── serviceName
│         ├── initial     # Program initialization, consisting of three files: initApp initializes configurations, registerServers registers services (HTTP or grpc), and registerClose registers resource cleanup.
│         └── main.go     # Program entry file
├── configs        # Directory for configuration files
├── deployments    # Directory for deployment scripts, supporting Bare Metal, Docker and Kubernetes deployments.
├─ docs            # Directory for API interface Swagger documentation.
├── i(I)nternal       # Directory for business logic code, if the first letter is lowercase (internal), it means private code, if the first letter is capitalised (Internal), it means it can be reused by other code.
│    ├── cache        # Cache directory wrapped around business logic.
│    ├── config       # Directory for Go structure configuration files.
│    ├── dao          # Data access directory.
│    ├── ecode        # Directory for system error codes and custom business error codes.
│    ├── handler      # Directory for implementing HTTP business functionality (specific to web services).
│    ├── model        # Database model directory.
│    ├── routers      # HTTP routing directory.
│    ├── rpcclient    # Directory for client-side code that connects to grpc services.
│    ├── server       # Directory for creating services, including HTTP and grpc.
│    ├── service      # Directory for implementing grpc business functionality (specific to grpc services).
│    └── types        # Directory for defining request and response parameter structures for HTTP.
├── pkg            # Directory for shared libraries.
├── scripts        # Directory for scripts, including compilation, execution, code generation, and deployment scripts.
├── test           # Directory for scripts required for testing services  and test SQL.
└── third_party    # Directory for external helper programs, forked code, and other third-party tools.

Quick start

Installation sponge

Sponge can be installed on Windows, macOS, Linux and Docker environments. Click here for instructions on installing sponge.

Starting UI service

After installing the sponge, start the UI service:

sponge run

Access http://localhost:24631 in a local browser and manipulate the generated code on the UI page.

If you want to access it on a cross-host browser, you need to specify the host ip or domain name when starting the UI, example sponge run -a http://your_host_ip:24631. It is also possible to start the UI service on docker to support cross-host access, Click for instructions on starting the sponge UI service in docker.


Sponge Development Documentation

Detailed instructions for operating, configuring, and deploying a project using sponge development, Click here to view the sponge development documentation


Examples of use

Examples of create services

Examples of develop complete project

Distributed transaction examples


License

See the LICENSE file for licensing information.



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


sponge's People

Contributors

cbot918 avatar gitter-badger avatar zhufuyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sponge's Issues

sponge init 失败

$ sponge init
initialize sponge ......
❌ upgrade sponge binary.
Error: go: github.com/zhufuyi/sponge/cmd/sponge@latest: module github.com/zhufuyi/sponge/cmd/sponge: Get "https://proxy.golang.org/github.com/zhufuyi/sponge/cmd/sponge/@v/list": dial tcp 172.217.160.113:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

有使用过goframe吗?

有使用过goframe吗?某些功能可能使用gf 更容易实现

考虑出一版基于goframe的不

Mac M1 install sponge failed

Describe the bug
Mac M1 install sponge failed

The error is

 > go install github.com/zhufuyi/sponge/cmd/sponge@latest
 # github.com/shoenig/go-m1cpu
 ../../pkg/mod/github.com/shoenig/[email protected]/cpu.go:65:33: error: use of undeclared identifier 'kIOMainPortDefault'; did you mean 'kIOMasterPortDefault'?
    IOServiceGetMatchingServices(kIOMainPortDefault, matching, &iter);
                                 ^~~~~~~~~~~~~~~~~~
                                 kIOMasterPortDefault
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:103:19: note: 'kIOMasterPortDefault' declared here
 const mach_port_t kIOMasterPortDefault;
  • OS: MacOS 11.2.3

一定要go1.20版本?

go.opentelemetry.io/otel/internal/global

../../../golang/pkg/mod/go.opentelemetry.io/[email protected]/internal/global/handler.go:44:18: undefined: atomic.Pointer
../../../golang/pkg/mod/go.opentelemetry.io/[email protected]/internal/global/internal_logging.go:30:25: undefined: atomic.Pointer
note: module requires Go 1.20

Screenshots
If applicable, add screenshots to help explain your problem.

Environments (please complete the following information):

  • OS: [e.g. Linux]
  • sponge version [e.g. 1.1.1]

More description
Add any other context about the problem here.

使用postgres数据库床建一个项目失败

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is

  2. The error is
    有可能是数据库字段类型的错误?

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
image
image

Environments (please complete the following information):

  • OS: windows
  • sponge version v1.6.2

More description
Add any other context about the problem here.
如图所示

集成组件更新

sponge是一个很优秀的开发框架,提供了多种内置组件和快速开发方式。不过内置的组件较多来带的问题是:如果涉及到内置组件,比如gin或Consul的版本更新,请问这种组件更新一般如何处理比较好?如果直接使用更新组件版本是否会影响sponge框架逻辑?

能不能将生成代码的功能拆分成一个工具,独立使用

我有一个类似的功能, 直接用 golang 定义接口然后生成代码
https://github.com/mei-rune/gogen/blob/master/intro.md

但是我不喜欢它, 当初也想过用 protoc 生成, 但因为已有功能的原因没有用 protoc , 现在发现了这个,请问能不能将 代码生成拆分出来, 成为一个独立的工具。
这样子,我们可以在原来的框架下无痛引入这个工具来提高效率。

创建http-pb项目时,make proto命令出现错误

Describe the bug

我在通过命令创建项目时,make proto出现错误。

执行的命令如下:

  1. sponge web http-pb --module-name=tidy --server-name=tidy --project-name=tidy --protobuf-file=./tidy.proto --out=./generate

  2. sponge web handler-pb --db-dsn='root:123456@(127.0.0.1:3306)/tidy' --db-table=task,target --out=./generate --module-name=github.com/Rvn0xsy/tidy

在执行第二条命令时,出现如下错误:

go: found github.com/zhufuyi/sponge/pkg/gin/validator in github.com/zhufuyi/sponge v1.5.0
go: found github.com/zhufuyi/sponge/pkg/jwt in github.com/zhufuyi/sponge v1.5.0
go: found github.com/zhufuyi/sponge/pkg/gotest in github.com/zhufuyi/sponge v1.5.0
go: found github.com/zhufuyi/sponge/pkg/gofile in github.com/zhufuyi/sponge v1.5.0
gofmt -s -w .
api/types/types.proto: File not found.
api/tidy/v1/target.proto:5:1: Import "api/types/types.proto" was not found or had errors.
api/tidy/v1/target.proto:231:3: "types.Params" is not defined.
make: *** [Makefile:81:proto] 错误 1

我的tidy.proto文件内容如下:

syntax = "proto3";

package api.tidy.v1;

import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option go_package = "tidy/api/user/v1;v1";

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  host: "localhost:8080"
  base_path: ""
  info: {
    title: "user api docs";
    version: "2.0";
  };
  schemes: HTTP;
  schemes: HTTPS;
  consumes: "application/json";
  produces: "application/json";
};

service user {
  rpc Login(LoginRequest) returns (LoginReply) {
    option (google.api.http) = {
      post: "/api/v1/login"
      body: "*"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
      summary: "登录",
      description: "使用邮箱登录",
    };
  }
}

message LoginRequest {
  string email = 1;
  string password = 2;
}

message LoginReply {
  string token = 1;
}

根据大致意思能够了解到,是Import "api/types/types.proto" 这个文件缺失,这个文件貌似没有生成。

sponge的版本:

$ sponge -v
sponge version v1.5.0

有一个小疑问。。

在视频中我看到比方说有三个rpc服务,一个网关服务,然后通过网关服务去调用rpc服务。
如果我有这样一个需求,我不需要网关服务,我有一个protobuff生成的web服务,里面都是暴露给前台的接口,这个时候我其中一个接口想调用一个rpc服务,这个可以通过代码自动生成去实现么?

如果可以的话还有一个问题,比方说名称相同的情况,web服务有一个叫user.proto文件而rpc服务中也有一个叫user.proto的文件,当然,如果两个服务都是同一个项目组去做可以通过命名的方式去做区分,但是也有可能是两个不同的项目组,这样同名的情况应该怎么办?

下载代码报错

根据sql生成web服务,点击下载代码提示
Internal Server Error, exec: "sponge": cannot run executable found relative to current directory

  • OS: WIn11
  • sponge version 1.5.16

建议支持pgsql

建议支持下pgsql,或完全兼容gorm所支持的那几种数据库

代码生成为空文件夹

按照文档生成项目结构目录,文件下载后解压为空文档。
按照安装流程对比了几次,没有发现缺漏步骤,不知是什么问题,或者哪里可以看到文件生成的日志。

如何使用goland运行和Debug生成出来的项目

Is your feature request related to a problem? Please describe.
刚刚接触到go语言,想了解一下如何在goland中运行和debug生成出来的项目,目前配置好会报grep错误,我猜测可能是goland默认终端使用的是cmd,而不是cmder。

Describe the solution you'd like
A clear and concise description of what you want to happen.
我想在goland中直接运行生产出来的项目
目前我的配置
image
运行时报的错
image

大佬能做成类似gin vue admin 内种 带页面的吗,快速开发脚手架

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

sponge init panic

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is
go version go1.21.0 darwin/arm64
  1. The error is
sponge init
panic: cgroup cpu init failed!err:=not implemented yet

goroutine 1 [running]:
github.com/zhufuyi/sponge/pkg/shield/cpu.init.0()
	/Users/user/go/pkg/mod/github.com/zhufuyi/[email protected]/pkg/shield/cpu/stat.go:33 +0xfc

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environments (please complete the following information):

  • OS: [mac os]
  • sponge version [1.5.5]

More description
Add any other context about the problem here.

生成文档时swag会报错

Describe the bug
生成文档时swag会报错

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is

// @title ChatGPT_MJ_aggregation_next api docs
// @description http server api docs
// @schemes http https
// @Version 2.0
// @host localhost:8080
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @description "Type Bearer your-jwt-token" to Value
func main() {
initial.InitApp()
services := initial.CreateServices()
closes := initial.Close(services)

a := app.New(services, closes)
a.Run()

}

2. The error is

// @description "Type Bearer your-jwt-token" to Value

3.将// @description "Type Bearer your-jwt-token" to Value 改成
// @description Type Bearer your-jwt-token to Value  可以解决

go install sponge error

Describe the bug
https://go-sponge.com/zh-cn/quick-start?id=%e5%ae%89%e8%a3%85-sponge
根据文档的安装步骤,安装sponge的时候报错。

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is
 go version

 go version go1.20.4 darwin/arm64
  1. The error is
go install github.com/zhufuyi/sponge/cmd/sponge@latest

# github.com/zhufuyi/sponge/cmd/sponge
ld: warning: '/private/var/folders/jx/41jbkxb92y7cmh1cs8kznr6w0000gn/T/go-link-3333539147/go.o' has malformed LC_DYSYMTAB, expected 129 undefined symbols to start at index 43311, found 221 undefined symbols starting at index 76

on ubuntu, "sponge init" got chmod issue, it probably used some wrong linux command

sponge init

initialize sponge ......
✔ upgraded sponge binary.
❌ upgrade template code.
Error: execute command failed, /bin/chmod: cannot access '/home/eric/.sponge/api': Permission denied
/bin/chmod: cannot access '/home/eric/.sponge/go.sum': Permission denied
/bin/chmod: cannot access '/home/eric/.sponge/doc.go': Permission denied
/bin/chmod: cannot access '/home/eric/.sponge/internal': Permission denied

Then I checked the permission of ~/.sponge, it's mess:

eric@eric-pc:~$ ll .sponge/
ls: cannot access '.sponge/api': Permission denied
ls: cannot access '.sponge/go.sum': Permission denied
ls: cannot access '.sponge/doc.go': Permission denied
ls: cannot access '.sponge/internal': Permission denied
ls: cannot access '.sponge/Makefile-for-http': Permission denied
ls: cannot access '.sponge/Makefile': Permission denied
ls: cannot access '.sponge/.gitignore': Permission denied
ls: cannot access '.sponge/third_party': Permission denied
ls: cannot access '.sponge/cmd': Permission denied
ls: cannot access '.sponge/.': Permission denied
ls: cannot access '.sponge/docs': Permission denied
ls: cannot access '.sponge/codecov.yml': Permission denied
ls: cannot access '.sponge/..': Permission denied
ls: cannot access '.sponge/.golangci.yml': Permission denied
ls: cannot access '.sponge/scripts': Permission denied
ls: cannot access '.sponge/Jenkinsfile': Permission denied
ls: cannot access '.sponge/deployments': Permission denied
ls: cannot access '.sponge/examples': Permission denied
ls: cannot access '.sponge/test': Permission denied
ls: cannot access '.sponge/LICENSE': Permission denied
ls: cannot access '.sponge/configs': Permission denied
ls: cannot access '.sponge/README.md': Permission denied
ls: cannot access '.sponge/go.mod': Permission denied
ls: cannot access '.sponge/.github': Permission denied
ls: cannot access '.sponge/pkg': Permission denied
ls: cannot access '.sponge/assets': Permission denied
total 0
d????????? ? ? ? ?            ? ./
d????????? ? ? ? ?            ? ../
d????????? ? ? ? ?            ? api/
d????????? ? ? ? ?            ? assets/
d????????? ? ? ? ?            ? cmd/
-????????? ? ? ? ?            ? codecov.yml
d????????? ? ? ? ?            ? configs/
d????????? ? ? ? ?            ? deployments/
-????????? ? ? ? ?            ? doc.go
d????????? ? ? ? ?            ? docs/
d????????? ? ? ? ?            ? examples/
d????????? ? ? ? ?            ? .github/
-????????? ? ? ? ?            ? .gitignore
-????????? ? ? ? ?            ? .golangci.yml
-????????? ? ? ? ?            ? go.mod
-????????? ? ? ? ?            ? go.sum
d????????? ? ? ? ?            ? internal/
-????????? ? ? ? ?            ? Jenkinsfile
-????????? ? ? ? ?            ? LICENSE
-????????? ? ? ? ?            ? Makefile
-????????? ? ? ? ?            ? Makefile-for-http
d????????? ? ? ? ?            ? pkg/
-????????? ? ? ? ?            ? README.md
d????????? ? ? ? ?            ? scripts/
d????????? ? ? ? ?            ? test/
d????????? ? ? ? ?            ? third_party/

移除表前缀

Is your feature request related to a problem? Please describe.
表 ue_proxy希望生成的model等,不使用UeProxy而是使用Proxy,不要Ue前缀

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.