This commit is contained in:
新亮
2021-06-12 16:19:29 +08:00
parent 6d9a07f5dd
commit a3607106d3
20 changed files with 84 additions and 46 deletions
+36
View File
@@ -0,0 +1,36 @@
# FROM 基于 golang:1.15-alpine
FROM golang:1.15-alpine AS builder
# ENV 设置环境变量
ENV GOPATH=/opt/repo
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.io,direct
# ADD 源路径 目标路径
COPY . $GOPATH/src/github.com/xinliangnote/go-gin-api
# RUN 执行 go build .
RUN cd $GOPATH/src/github.com/xinliangnote/go-gin-api && go build .
# FROM 基于 alpine:latest
FROM alpine:latest
# RUN 设置代理镜像
RUN echo -e http://mirrors.ustc.edu.cn/alpine/v3.13/main/ > /etc/apk/repositories
# RUN 设置 Asia/Shanghai 时区
RUN apk --no-cache add tzdata && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
# COPY 源路径 目标路径 从镜像中 COPY
COPY --from=builder /opt/repo/src/github.com/xinliangnote/go-gin-api /opt
# EXPOSE 设置端口映射
EXPOSE 9999/tcp
# WORKDIR 设置工作目录
WORKDIR /opt
# CMD 设置启动命令
CMD ["./go-gin-api", "-env", "fat"]
+2 -1
View File
@@ -3,7 +3,8 @@ package mysql
import (
"fmt"
"github.com/pkg/errors"
"github.com/xinliangnote/go-gin-api/pkg/errors"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/schema"
+11 -11
View File
@@ -1,36 +1,36 @@
package configs
const (
// 项目版本
// ProjectVersion 项目版本
ProjectVersion = "v1.2.6"
// 项目名称
// ProjectName 项目名称
ProjectName = "go-gin-api"
// 项目端口
// ProjectPort 项目端口
ProjectPort = ":9999"
// 项目日志存放文件
// ProjectLogFile 项目日志存放文件
ProjectLogFile = "./logs/" + ProjectName + "-access.log"
// 项目安装完成标识
// ProjectInstallMark 项目安装完成标识
ProjectInstallMark = "INSTALL.lock"
// 登录验证 TokenHeader 中传递的参数
// HeaderLoginToken 登录验证 Token,Header 中传递的参数
HeaderLoginToken = "Token"
// 签名验证 TokenHeader 中传递的参数
// HeaderSignToken 签名验证 Token,Header 中传递的参数
HeaderSignToken = "Authorization"
// 签名验证 DateHeader 中传递的参数
// HeaderSignTokenDate 签名验证 Date,Header 中传递的参数
HeaderSignTokenDate = "Authorization-Date"
// Redis Key 前缀 - 防止重复提交
// RedisKeyPrefixRequestID Redis Key 前缀 - 防止重复提交
RedisKeyPrefixRequestID = ProjectName + ":request-id:"
// Redis Key 前缀 - 登录用户信息
// RedisKeyPrefixLoginUser Redis Key 前缀 - 登录用户信息
RedisKeyPrefixLoginUser = ProjectName + ":login-user:"
// Redis Key 前缀 - 签名验证信息
// RedisKeyPrefixSignature Redis Key 前缀 - 签名验证信息
RedisKeyPrefixSignature = ProjectName + ":signature:"
)
+1 -1
View File
@@ -1,6 +1,6 @@
package code
// 错误时返回结构
// Failure 错误时返回结构
type Failure struct {
Code int `json:"code"` // 业务码
Message string `json:"message"` // 描述信息
+1 -2
View File
@@ -4,8 +4,7 @@ import (
"context"
"github.com/xinliangnote/go-gin-api/internal/graph/model"
"github.com/pkg/errors"
"github.com/xinliangnote/go-gin-api/pkg/errors"
)
func (r *queryResolver) BySex(ctx context.Context, sex string) ([]*model.User, error) {
+1 -1
View File
@@ -14,11 +14,11 @@ import (
"github.com/xinliangnote/go-gin-api/pkg/color"
"github.com/xinliangnote/go-gin-api/pkg/env"
"github.com/xinliangnote/go-gin-api/pkg/errno"
"github.com/xinliangnote/go-gin-api/pkg/errors"
"github.com/xinliangnote/go-gin-api/pkg/trace"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
cors "github.com/rs/cors/wrapper/gin"
ginSwagger "github.com/swaggo/gin-swagger"
+1 -1
View File
@@ -5,8 +5,8 @@ import (
"time"
"github.com/xinliangnote/go-gin-api/configs"
"github.com/xinliangnote/go-gin-api/pkg/errors"
"github.com/pkg/errors"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/schema"
@@ -9,9 +9,8 @@ import (
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
"github.com/xinliangnote/go-gin-api/pkg/errno"
"github.com/xinliangnote/go-gin-api/pkg/errors"
"github.com/xinliangnote/go-gin-api/pkg/token"
"github.com/pkg/errors"
)
const reSubmitMark = "1"
@@ -27,11 +27,13 @@ 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)
// runtime.GOOS = linux or darwin
command := exec.Command("/bin/bash", "-c", shellPath)
command := new (exec.Cmd)
if runtime.GOOS == "windows" {
command = exec.Command("cmd", "/C", shellPath)
} else {
// runtime.GOOS = linux or darwin
command = exec.Command("/bin/bash", "-c", shellPath)
}
var stderr bytes.Buffer
@@ -25,11 +25,13 @@ func (h *handler) HandlerExecute() core.HandlerFunc {
shellPath := fmt.Sprintf("%s %s", handlergenSh, req.Name)
// runtime.GOOS = linux or darwin
command := exec.Command("/bin/bash", "-c", shellPath)
command := new (exec.Cmd)
if runtime.GOOS == "windows" {
command = exec.Command("cmd", "/C", shellPath)
} else {
// runtime.GOOS = linux or darwin
command = exec.Command("/bin/bash", "-c", shellPath)
}
var stderr bytes.Buffer
@@ -12,11 +12,13 @@ func (h *handler) Restart() core.HandlerFunc {
return func(c core.Context) {
shellPath := "./scripts/restart.sh"
// runtime.GOOS = linux or darwin
command := exec.Command("/bin/bash", "-c", shellPath)
command := new (exec.Cmd)
if runtime.GOOS == "windows" {
command = exec.Command("cmd", "/C", shellPath)
} else {
// runtime.GOOS = linux or darwin
command = exec.Command("/bin/bash", "-c", shellPath)
}
var stderr bytes.Buffer
+6 -6
View File
@@ -1,21 +1,21 @@
package ddm
// 手机号 132****7986
// Mobile 手机号 132****7986
type Mobile string
// 银行卡号 622888******5676
// BankCard 银行卡号 622888******5676
type BankCard string
// 身份证号 1******7
// IDCard 身份证号 1******7
type IDCard string
// 姓名 *鸿章
// IDName 姓名 *鸿章
// TODO:参考 https://blog.thinkeridea.com/201910/go/efficient_string_truncation.html
// Deprecated:有更好的性能选择
type IDName string
// 密码 ******
// PassWord 密码 ******
type PassWord string
// 邮箱 l***w@gmail.com
// Email 邮箱 l***w@gmail.com
type Email string
+1 -3
View File
@@ -2,8 +2,6 @@ package errno
import (
"encoding/json"
"github.com/pkg/errors"
)
var _ Error = (*err)(nil)
@@ -43,7 +41,7 @@ func NewError(httpCode, businessCode int, msg string) Error {
func (e *err) i() {}
func (e *err) WithErr(err error) Error {
e.Err = errors.WithStack(err)
e.Err = err
return e
}
+2 -2
View File
@@ -20,8 +20,8 @@ type Error interface {
t()
}
var _ (Error) = (*item)(nil)
var _ (fmt.Formatter) = (*item)(nil)
var _ Error = (*item)(nil)
var _ fmt.Formatter = (*item)(nil)
type item struct {
msg string
+3 -1
View File
@@ -5,8 +5,10 @@ var _ Hash = (*hash)(nil)
type Hash interface {
i()
// hashids
// HashidsEncode 加密
HashidsEncode(params []int) (string, error)
// HashidsDecode 解密
HashidsDecode(hash string) ([]int, error)
}
+1 -2
View File
@@ -8,9 +8,8 @@ import (
httpURL "net/url"
"time"
"github.com/xinliangnote/go-gin-api/pkg/errors"
"github.com/xinliangnote/go-gin-api/pkg/trace"
"github.com/pkg/errors"
)
const (
+1 -1
View File
@@ -108,7 +108,7 @@ func WithTimeLayout(timeLayout string) Option {
}
}
// WithEnableConsole write log to os.Stdout or os.Stderr
// WithDisableConsole WithEnableConsole write log to os.Stdout or os.Stderr
func WithDisableConsole() Option {
return func(opt *option) {
opt.disableConsole = true
+2 -2
View File
@@ -28,10 +28,10 @@ var methods = map[string]bool{
type Signature interface {
i()
// 生成签名
// Generate 生成签名
Generate(path string, method string, params url.Values) (authorization, date string, err error)
// 验证签名
// Verify 验证签名
Verify(authorization, date string, path string, method string, params url.Values) (ok bool, err error)
}
+1 -2
View File
@@ -9,9 +9,8 @@ import (
"net/url"
"strings"
"github.com/xinliangnote/go-gin-api/pkg/errors"
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
"github.com/pkg/errors"
)
// Generate
+1 -2
View File
@@ -10,9 +10,8 @@ import (
"strings"
"time"
"github.com/xinliangnote/go-gin-api/pkg/errors"
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
"github.com/pkg/errors"
)
func (s *signature) Verify(authorization, date string, path string, method string, params url.Values) (ok bool, err error) {