优化完善

This commit is contained in:
李寻欢 2021-08-22 00:13:00 +08:00
parent 2f1b34b9b3
commit 9a035c729b
25 changed files with 52 additions and 49 deletions

4
.env
View File

@ -11,4 +11,6 @@ MYSQL_PWD=casbin123
MYSQL_DB=casbin_demo MYSQL_DB=casbin_demo
# 阿里云通信配置 # 阿里云通信配置
ALI_SMS_KEY=LTAI5tBExwETRZcVcpogQCp7 ALI_SMS_KEY=LTAI5tBExwETRZcVcpogQCp7
ALI_SMS_SECRET=afZPFabUs5Vmjr3W6R7reI3dNaGa8o ALI_SMS_SECRET=afZPFabUs5Vmjr3W6R7reI3dNaGa8o
# JWT 口令
JWT_SECRET=bgx6yCtxziJ3it37

View File

@ -3,10 +3,10 @@ package controller
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
. "go_api_tmpl/core" . "goweb/core"
. "go_api_tmpl/global" . "goweb/global"
"go_api_tmpl/repository" "goweb/repository"
"go_api_tmpl/utils" "goweb/utils"
"math/rand" "math/rand"
"net/http" "net/http"
"time" "time"
@ -47,6 +47,7 @@ func GetSmsCodeController(ctx *gin.Context) {
} }
err = RedisConn.SetWithTimeout(phoneKey, code, "600") err = RedisConn.SetWithTimeout(phoneKey, code, "600")
if err != nil { if err != nil {
Log.Errorf("保存验证码到Redis失败: %v", err.Error())
R(ctx).FailWithMessage("验证码发送失败,请稍后重试") R(ctx).FailWithMessage("验证码发送失败,请稍后重试")
return return
} }

View File

@ -3,7 +3,7 @@ package global
import ( import (
"fmt" "fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi" "github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
"go_api_tmpl/config" "goweb/config"
) )
type aliSmsBot struct{} type aliSmsBot struct{}

View File

@ -2,10 +2,10 @@ package global
import ( import (
"fmt" "fmt"
. "go_api_tmpl/config"
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/logger" "gorm.io/gorm/logger"
. "goweb/config"
"log" "log"
"os" "os"
"time" "time"

2
go.mod
View File

@ -1,4 +1,4 @@
module go_api_tmpl module goweb
go 1.16 go 1.16

View File

@ -2,8 +2,8 @@ package handle
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go_api_tmpl/global" "goweb/global"
"go_api_tmpl/repository" "goweb/repository"
) )
// SaveAllRoute 保存入库所有接口路由信息 // SaveAllRoute 保存入库所有接口路由信息

View File

@ -5,7 +5,7 @@ import (
"github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/model" "github.com/casbin/casbin/v2/model"
gormAdapter "github.com/casbin/gorm-adapter/v3" gormAdapter "github.com/casbin/gorm-adapter/v3"
"go_api_tmpl/global" "goweb/global"
) )
// Casbin 初始化Casbin的RABC模型 // Casbin 初始化Casbin的RABC模型

View File

@ -1,8 +1,8 @@
package initialization package initialization
import ( import (
. "go_api_tmpl/global" . "goweb/global"
"go_api_tmpl/repository" "goweb/repository"
) )
// DatabaseTable 初始化数据库表结构 // DatabaseTable 初始化数据库表结构

View File

@ -1,8 +1,8 @@
package initialization package initialization
import ( import (
"go_api_tmpl/config" "goweb/config"
"go_api_tmpl/global" "goweb/global"
) )
func Init() { func Init() {

View File

@ -3,8 +3,8 @@ package initialization
import ( import (
"fmt" "fmt"
"github.com/garyburd/redigo/redis" "github.com/garyburd/redigo/redis"
"go_api_tmpl/config" "goweb/config"
"go_api_tmpl/global" "goweb/global"
"time" "time"
) )

10
main.go
View File

@ -2,11 +2,11 @@ package main
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go_api_tmpl/core" "goweb/core"
"go_api_tmpl/handle" "goweb/handle"
"go_api_tmpl/initialization" "goweb/initialization"
"go_api_tmpl/middleware" "goweb/middleware"
"go_api_tmpl/route" "goweb/route"
) )
func main() { func main() {

View File

@ -3,8 +3,8 @@ package middleware
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go_api_tmpl/core" "goweb/core"
. "go_api_tmpl/global" . "goweb/global"
"net/http" "net/http"
) )

View File

@ -3,9 +3,9 @@ package middleware
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt" "github.com/golang-jwt/jwt"
"go_api_tmpl/core" "goweb/core"
"go_api_tmpl/global" "goweb/global"
"go_api_tmpl/utils" "goweb/utils"
"net/http" "net/http"
) )

View File

@ -2,7 +2,7 @@ package middleware
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go_api_tmpl/global" "goweb/global"
"time" "time"
) )

View File

@ -3,9 +3,9 @@ package middleware
import ( import (
"bytes" "bytes"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go_api_tmpl/core" "goweb/core"
"go_api_tmpl/model" "goweb/model"
"go_api_tmpl/repository" "goweb/repository"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"time" "time"

View File

@ -2,8 +2,8 @@ package repository
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
. "go_api_tmpl/global" . "goweb/global"
"go_api_tmpl/model" "goweb/model"
) )
type apisRepository struct{} type apisRepository struct{}

View File

@ -1,8 +1,8 @@
package repository package repository
import ( import (
"go_api_tmpl/global" "goweb/global"
"go_api_tmpl/model" "goweb/model"
) )
type menuRepository struct{} type menuRepository struct{}

View File

@ -1,8 +1,8 @@
package repository package repository
import ( import (
"go_api_tmpl/global" "goweb/global"
"go_api_tmpl/model" "goweb/model"
) )
type requestLogRepository struct{} type requestLogRepository struct{}

View File

@ -1,8 +1,8 @@
package repository package repository
import ( import (
"go_api_tmpl/global" "goweb/global"
"go_api_tmpl/model" "goweb/model"
) )
type roleMenuRepository struct{} type roleMenuRepository struct{}

View File

@ -1,8 +1,8 @@
package repository package repository
import ( import (
"go_api_tmpl/global" "goweb/global"
"go_api_tmpl/model" "goweb/model"
) )
type roleRepository struct{} type roleRepository struct{}

View File

@ -1,8 +1,8 @@
package repository package repository
import ( import (
"go_api_tmpl/global" "goweb/global"
"go_api_tmpl/model" "goweb/model"
) )
type userRepository struct{} type userRepository struct{}

View File

@ -1,8 +1,8 @@
package repository package repository
import ( import (
"go_api_tmpl/global" "goweb/global"
"go_api_tmpl/model" "goweb/model"
) )
type userRoleRepository struct{} type userRoleRepository struct{}

View File

@ -2,7 +2,7 @@ package route
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go_api_tmpl/controller" "goweb/controller"
) )
// 初始化登录相关接口路由 // 初始化登录相关接口路由

View File

@ -2,7 +2,7 @@ package route
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go_api_tmpl/core" "goweb/core"
) )
func InitRoute(app *gin.Engine) { func InitRoute(app *gin.Engine) {

View File

@ -2,8 +2,8 @@ package route
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go_api_tmpl/core" "goweb/core"
"go_api_tmpl/middleware" "goweb/middleware"
) )
func initTestRoute(r *gin.RouterGroup) { func initTestRoute(r *gin.RouterGroup) {