代码规范化
parent
f12f001664
commit
0a2783b4a2
34
README.md
34
README.md
|
@ -1,39 +1,9 @@
|
||||||
# background
|
# background
|
||||||
|
|
||||||
#### 介绍
|
#### 介绍
|
||||||
开源的后台管理前后端
|
开源的后台管理前后端
|
||||||
后端采用go+gin+ redis
|
后端采用go+gin+ redis
|
||||||
前端采用vue+iview框架
|
前端采用vue+iview框架
|
||||||
|
|
||||||
#### 软件架构
|
|
||||||
软件架构说明
|
|
||||||
|
|
||||||
|
|
||||||
#### 安装教程
|
#### 安装教程
|
||||||
|
|
||||||
1. xxxx
|
|
||||||
2. xxxx
|
|
||||||
3. xxxx
|
|
||||||
|
|
||||||
#### 使用说明
|
|
||||||
|
|
||||||
1. xxxx
|
|
||||||
2. xxxx
|
|
||||||
3. xxxx
|
|
||||||
|
|
||||||
#### 参与贡献
|
|
||||||
|
|
||||||
1. Fork 本仓库
|
|
||||||
2. 新建 Feat_xxx 分支
|
|
||||||
3. 提交代码
|
|
||||||
4. 新建 Pull Request
|
|
||||||
|
|
||||||
|
|
||||||
#### 码云特技
|
|
||||||
|
|
||||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
|
||||||
2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)
|
|
||||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目
|
|
||||||
4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
|
|
||||||
5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
|
||||||
6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileController struct {
|
type FileController struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *FileController) OnUpload(c *gin.Context) {
|
func (this *FileController) OnUpload(c *gin.Context) {
|
||||||
|
@ -27,7 +26,7 @@ func (this *FileController) OnUpload(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *FileController) OnDownLoad(c *gin.Context) {
|
func (this *FileController) OnDownLoad(c *gin.Context) {
|
||||||
file, header, err := c.Request.FormFile("upload")
|
file, header, err := c.Request.FormFile("upload")
|
||||||
filename := header.Filename
|
filename := header.Filename
|
||||||
fmt.Println(header.Filename)
|
fmt.Println(header.Filename)
|
||||||
|
|
|
@ -17,8 +17,8 @@ import (
|
||||||
"user/config"
|
"user/config"
|
||||||
"user/db"
|
"user/db"
|
||||||
)
|
)
|
||||||
type MailController struct {
|
|
||||||
|
|
||||||
|
type MailController struct {
|
||||||
}
|
}
|
||||||
type RespJson struct {
|
type RespJson struct {
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
|
@ -236,7 +236,7 @@ func OnSendEmailTpl(c *gin.Context) {
|
||||||
//content :网页模板的参数 key-value结构
|
//content :网页模板的参数 key-value结构
|
||||||
//temp_data 模板内具体要替换的变量名字 Key-value结构
|
//temp_data 模板内具体要替换的变量名字 Key-value结构
|
||||||
//generate 是否生成静态html
|
//generate 是否生成静态html
|
||||||
func (this *MailController)OnSendEmailCode(c *gin.Context) {
|
func (this *MailController) OnSendEmailCode(c *gin.Context) {
|
||||||
var req ReqSendEmail
|
var req ReqSendEmail
|
||||||
var resp RespJson
|
var resp RespJson
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fatih/structs"
|
"github.com/fatih/structs"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/tommy351/gin-sessions"
|
"github.com/tommy351/gin-sessions"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"user/config"
|
"user/config"
|
||||||
"user/db"
|
"user/db"
|
||||||
"user/logs"
|
"user/logs"
|
||||||
"user/model"
|
"user/model"
|
||||||
"user/redis"
|
"user/redis"
|
||||||
)
|
)
|
||||||
type UserController struct{
|
|
||||||
|
|
||||||
|
type UserController struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReqSendEmailCode struct {
|
type ReqSendEmailCode struct {
|
||||||
|
@ -45,7 +45,7 @@ type RespBase struct {
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *UserController)Auth(c *gin.Context) {
|
func (this *UserController) Auth(c *gin.Context) {
|
||||||
var resp RespBase
|
var resp RespBase
|
||||||
var statuscode int
|
var statuscode int
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ func (this *UserController) GetUser(c *gin.Context) {
|
||||||
// @Param department_id query string false "name search by q"
|
// @Param department_id query string false "name search by q"
|
||||||
// @Param permission_type query string false "name search by q"
|
// @Param permission_type query string false "name search by q"
|
||||||
// @Router /api/users [get]
|
// @Router /api/users [get]
|
||||||
func (this *UserController) Users(c *gin.Context) {
|
func (this *UserController) Users(c *gin.Context) {
|
||||||
var statuscode int
|
var statuscode int
|
||||||
var resp RespBase
|
var resp RespBase
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ func (this *UserController) SerarchUsers(c *gin.Context) {
|
||||||
resp.Msg = "OK"
|
resp.Msg = "OK"
|
||||||
resp.Data = dat
|
resp.Data = dat
|
||||||
}
|
}
|
||||||
func CreateVerify(length int32) string {
|
func CreateVerify(length int32) string {
|
||||||
strAry := []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
strAry := []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
||||||
result := string("")
|
result := string("")
|
||||||
for i := int32(0); i < length; i++ {
|
for i := int32(0); i < length; i++ {
|
||||||
|
@ -212,7 +212,7 @@ func CreateVerify(length int32) string {
|
||||||
* @param {Number} length 取Token的长度
|
* @param {Number} length 取Token的长度
|
||||||
* @return {string} 获取的Token
|
* @return {string} 获取的Token
|
||||||
*/
|
*/
|
||||||
func createToken(length int32) string {
|
func createToken(length int32) string {
|
||||||
strAry := []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_'}
|
strAry := []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_'}
|
||||||
result := string("")
|
result := string("")
|
||||||
for i := int32(0); i < length; i++ {
|
for i := int32(0); i < length; i++ {
|
||||||
|
@ -434,7 +434,7 @@ func Reader2Json(r io.ReadCloser) string {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendExternalEmail(msg interface{}) error {
|
func SendExternalEmail(msg interface{}) error {
|
||||||
req := make(map[string]interface{}, 1)
|
req := make(map[string]interface{}, 1)
|
||||||
req["type"] = "text"
|
req["type"] = "text"
|
||||||
req["action"] = "smtp-sys"
|
req["action"] = "smtp-sys"
|
||||||
|
@ -510,7 +510,7 @@ func (this *UserController) SendEmailCode(c *gin.Context) {
|
||||||
//判断邮箱是否存在
|
//判断邮箱是否存在
|
||||||
var users []model.Users
|
var users []model.Users
|
||||||
e = db.GetMysqlClient().Query2("select * from users where email_adress = ?", &users, req.EmailAdress)
|
e = db.GetMysqlClient().Query2("select * from users where email_adress = ?", &users, req.EmailAdress)
|
||||||
if nil != e{
|
if nil != e {
|
||||||
log.Print(e.Error())
|
log.Print(e.Error())
|
||||||
resp.Msg = "email address error"
|
resp.Msg = "email address error"
|
||||||
return
|
return
|
||||||
|
|
7
main.go
7
main.go
|
@ -16,7 +16,7 @@ var (
|
||||||
mailContoller = controller.MailController{}
|
mailContoller = controller.MailController{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitConfig() {
|
func InitConfig() {
|
||||||
e := config.Init("user.yaml")
|
e := config.Init("user.yaml")
|
||||||
if nil != e {
|
if nil != e {
|
||||||
log.Println(e.Error())
|
log.Println(e.Error())
|
||||||
|
@ -30,14 +30,14 @@ func InitMysql() {
|
||||||
db.Init()
|
db.Init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func InitRedis() {
|
func InitRedis() {
|
||||||
e := config.InitRedis()
|
e := config.InitRedis()
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func InitLogs() {
|
func InitLogs() {
|
||||||
logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile)
|
logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile)
|
||||||
}
|
}
|
||||||
func CORSMiddleware(c *gin.Context) {
|
func CORSMiddleware(c *gin.Context) {
|
||||||
|
@ -57,7 +57,6 @@ func CORSMiddleware(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
InitConfig()
|
InitConfig()
|
||||||
InitLogs()
|
InitLogs()
|
||||||
|
|
Loading…
Reference in New Issue