From 8ca47f743d14d94cfa2462f4c0407d4ae6bc0dd7 Mon Sep 17 00:00:00 2001 From: anserme Date: Tue, 22 Jun 2021 15:19:08 +0800 Subject: [PATCH 1/2] Add en.md --- en.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 en.md diff --git a/en.md b/en.md new file mode 100644 index 0000000..099e8c3 --- /dev/null +++ b/en.md @@ -0,0 +1,51 @@ +## What is go-gin-api? + +`go-gin-api` is a modular design API framework based on [Gin](https://github.com/gin-gonic/gin), which encapsulates commonly used functions, is simple to use, and is committed to fast business Research and development, while adding more restrictions, restrict the development members of the project team, avoid chaos, disorder and free and arbitrary coding. + +For reference and learning at this stage, please be cautious when using it in a production environment! + +Features: +1. Rate-limitd APIs supported by [rate](https://golang.org/x/time/rate) +1. Email notification when panic occurs +1. Cross-Origin Resource Sharing supported by [cors](https://github.com/rs/cors) +1. Metrics monitoring and alerting by [Prometheus](https://github.com/prometheus/client_golang) +1. Automatically generate RESTful API documentation supported by [Swagger](https://github.com/swaggo/gin-swagger) +1. GraphQL supported by [GraphQL](https://github.com/99designs/gqlgen) +1. Trace project internal invoking +1. Visualized performance analysis supported by [pprof](https://github.com/gin-contrib/pprof) +1. Industry standard RFC 7519 method for authentication supported by [jwt](https://github.com/dgrijalva/jwt-go) +1. Uniformly defined error codes supported by errno +1. Blazing fast, structured, leveled logging system by [zap](https://go.uber.org/zap) +1. Complete configuration solution supported by [viper](https://github.com/spf13/viper) +1. Developer Friendly ORM library supported by [gorm](https://gorm.io/gorm) +1. Redis supported by [go-redis](https://github.com/go-redis/redis) +1. Standard RESTful API return value +1. CURD code generator , controller generator, etc. +1. Web interface, supported by [Light Year Admin template](https://gitee.com/yinqi/Light-Year-Admin-Using-Iframe) + + + +## Index + +The go-gin-api document consists of the following main parts: + +- Requirements +- Getting started +- Directory Structure +- Core package +- Component guide +- Toolkit + +**Detailed documentation:[https://www.yuque.com/xinliangnote/go-gin-api/ngc3x5](https://www.yuque.com/xinliangnote/go-gin-api/ngc3x5)** + +## Others + +To check Jaeger code, [v1.0](https://github.com/xinliangnote/go-gin-api/releases/tag/v1.0),documentation:[jaeger.md](https://github.com/xinliangnote/go-gin-api/blob/master/docs/jaeger.md) 。 + +## Comtributing + +Help us with translating `go-gin-api` to your native language. + +## Learning together + +![](https://github.com/xinliangnote/Go/blob/master/00-基础语法/images/qr.jpg) \ No newline at end of file From 2c5683cd1414740ab1776fe9d8868479ca309552 Mon Sep 17 00:00:00 2001 From: anserme Date: Tue, 22 Jun 2021 15:20:07 +0800 Subject: [PATCH 2/2] fix windows support --- .../generator_handler/func_gormexecute.go | 14 ++++-- .../generator_handler/func_handlerexecute.go | 15 ++++--- scripts/gormgen.bat | 45 +++++++++++++++++++ scripts/gqlgen.bat | 10 +++++ scripts/handlergen.bat | 22 +++++++++ scripts/init.bat | 13 ++++++ scripts/swagger.bat | 8 ++++ 7 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 scripts/gormgen.bat create mode 100644 scripts/gqlgen.bat create mode 100644 scripts/handlergen.bat create mode 100644 scripts/init.bat create mode 100644 scripts/swagger.bat diff --git a/internal/web/controller/generator_handler/func_gormexecute.go b/internal/web/controller/generator_handler/func_gormexecute.go index bfed5f4..48a7d7b 100644 --- a/internal/web/controller/generator_handler/func_gormexecute.go +++ b/internal/web/controller/generator_handler/func_gormexecute.go @@ -3,8 +3,10 @@ package generator_handler import ( "bytes" "fmt" + "os" "os/exec" "runtime" + "strings" "github.com/xinliangnote/go-gin-api/configs" "github.com/xinliangnote/go-gin-api/internal/pkg/core" @@ -14,9 +16,12 @@ type gormExecuteRequest struct { Tables string `form:"tables"` } -const gormgenSh = "./scripts/gormgen.sh" - func (h *handler) GormExecute() core.HandlerFunc { + dir, _ := os.Getwd() + projectPath := strings.Replace(dir, "\\", "/", -1) + gormgenSh := projectPath + "/scripts/gormgen.sh" + gormgenBat := projectPath + "/scripts/gormgen.bat" + return func(c core.Context) { req := new(gormExecuteRequest) if err := c.ShouldBindPostForm(req); err != nil { @@ -26,11 +31,12 @@ func (h *handler) GormExecute() core.HandlerFunc { mysqlConf := configs.Get().MySQL.Read shellPath := fmt.Sprintf("%s %s %s %s %s %s", gormgenSh, mysqlConf.Addr, mysqlConf.User, mysqlConf.Pass, mysqlConf.Name, req.Tables) + batPath := fmt.Sprintf("%s %s %s %s %s %s", gormgenBat, mysqlConf.Addr, mysqlConf.User, mysqlConf.Pass, mysqlConf.Name, req.Tables) - command := new (exec.Cmd) + command := new(exec.Cmd) if runtime.GOOS == "windows" { - command = exec.Command("cmd", "/C", shellPath) + command = exec.Command("cmd", "/C", batPath) } else { // runtime.GOOS = linux or darwin command = exec.Command("/bin/bash", "-c", shellPath) diff --git a/internal/web/controller/generator_handler/func_handlerexecute.go b/internal/web/controller/generator_handler/func_handlerexecute.go index 6a82102..e6014e5 100644 --- a/internal/web/controller/generator_handler/func_handlerexecute.go +++ b/internal/web/controller/generator_handler/func_handlerexecute.go @@ -3,8 +3,10 @@ package generator_handler import ( "bytes" "fmt" + "os" "os/exec" "runtime" + "strings" "github.com/xinliangnote/go-gin-api/internal/pkg/core" ) @@ -13,22 +15,25 @@ type handlerExecuteRequest struct { Name string `form:"name"` } -const handlergenSh = "./scripts/handlergen.sh" - func (h *handler) HandlerExecute() core.HandlerFunc { + dir, _ := os.Getwd() + projectPath := strings.Replace(dir, "\\", "/", -1) + handlergenSh := projectPath + "/scripts/handlergen.sh" + handlergenBat := projectPath + "./scripts/handlergen.bat" + return func(c core.Context) { req := new(handlerExecuteRequest) if err := c.ShouldBindPostForm(req); err != nil { c.Payload("参数传递有误") return } - shellPath := fmt.Sprintf("%s %s", handlergenSh, req.Name) + batPath := fmt.Sprintf("%s %s", handlergenBat, req.Name) - command := new (exec.Cmd) + command := new(exec.Cmd) if runtime.GOOS == "windows" { - command = exec.Command("cmd", "/C", shellPath) + command = exec.Command("cmd", "/C", batPath) } else { // runtime.GOOS = linux or darwin command = exec.Command("/bin/bash", "-c", shellPath) diff --git a/scripts/gormgen.bat b/scripts/gormgen.bat new file mode 100644 index 0000000..aa47c81 --- /dev/null +++ b/scripts/gormgen.bat @@ -0,0 +1,45 @@ +@echo off +chcp 65001 +echo. +echo Regenerating file +echo. +go run -v ./cmd/mysqlmd/main.go -addr %1 -user %2 -pass %3 -name %4 -tables %5 +if %errorlevel% == 1 ( +echo. +echo failed!!! +exit 1 +) +echo. +echo create curd code : +echo. +go build -o gormgen ./cmd/gormgen/main.go +if %errorlevel% == 1 ( +echo. +echo failed!!! +exit 1 +) + +move gormgen $GOPATH/bin +if %errorlevel% == 1 ( +echo. +echo failed!!! +exit 1 +) + +go generate ./... +if %errorlevel% == 1 ( +echo. +echo failed!!! +exit 1 +) +echo. +echo Formatting code +echo. +go run -v ./cmd/mfmt/main.go +if %errorlevel% == 1 ( +echo. +echo failed!!! +exit 1 +) +echo. +echo Done. diff --git a/scripts/gqlgen.bat b/scripts/gqlgen.bat new file mode 100644 index 0000000..9e7e0ab --- /dev/null +++ b/scripts/gqlgen.bat @@ -0,0 +1,10 @@ +@echo off +chcp 65001 +echo. +echo Regenerating gqlgen file +echo. +del internal/graph/generated/generated.go internal/graph/model/generated.go internal/graph/resolvers/generated/generated.go +go run -v github.com/99designs/gqlgen $1 +echo. +echo Done. +echo. \ No newline at end of file diff --git a/scripts/handlergen.bat b/scripts/handlergen.bat new file mode 100644 index 0000000..1680462 --- /dev/null +++ b/scripts/handlergen.bat @@ -0,0 +1,22 @@ +@echo off +chcp 65001 +echo. +echo Regenerating handler file +echo. +go run -v ./cmd/handlergen/main.go -handler %1 +if %errorlevel% == 1 ( +echo. +echo failed!!! +exit 1 +) +echo. +echo Formatting code +echo. +go run -v ./cmd/mfmt/main.go +if %errorlevel% == 1 ( +echo. +echo failed!!! +exit 1 +) +echo. +echo Done. diff --git a/scripts/init.bat b/scripts/init.bat new file mode 100644 index 0000000..1975951 --- /dev/null +++ b/scripts/init.bat @@ -0,0 +1,13 @@ +@echo off +chcp 65001 +echo. +echo Init db +echo. +go run -v ./cmd/init/db/main.go -addr %1 -user %2 -pass %3 -name %4 +if %errorlevel% == 1 ( +echo. +echo failed!!! +exit 1 +) +echo. +echo Done. \ No newline at end of file diff --git a/scripts/swagger.bat b/scripts/swagger.bat new file mode 100644 index 0000000..0f22073 --- /dev/null +++ b/scripts/swagger.bat @@ -0,0 +1,8 @@ +@echo off +chcp 65001 +echo. +echo Regenerating swagger doc +echo. +go run -v github.com/swaggo/swag/cmd/swag init +echo. +echo Done. \ No newline at end of file