Merge pull request #42 from anserme/master

fix(代码生成工具):  windows support

- 新增 windows bat 文件  
- 新增 en.md 文件
This commit is contained in:
新亮笔记
2021-06-22 16:15:36 +08:00
committed by GitHub
8 changed files with 169 additions and 9 deletions
+51
View File
@@ -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)
@@ -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)
@@ -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)
+45
View File
@@ -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.
+10
View File
@@ -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.
+22
View File
@@ -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.
+13
View File
@@ -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.
+8
View File
@@ -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.