chore: update

main
zggsong 2 years ago
parent 761ad266f4
commit 1460ba8cbd

@ -1,6 +1,7 @@
package common package common
import ( import (
"expenses/util"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -14,7 +15,7 @@ var Log *log.Logger
// //
// @Description: 初始化Logger // @Description: 初始化Logger
func Init() { func Init() {
exists, _ := pathExists("./log") exists, _ := util.PathExists("./log")
if !exists { if !exists {
_ = os.Mkdir("./log", 0755) _ = os.Mkdir("./log", 0755)
} }
@ -51,20 +52,3 @@ func Init() {
} }
} }
// pathExists
//
// @Description: 判断路径是否存在
// @param path
// @return bool
// @return error
func pathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil { //文件或者目录存在
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

@ -2,6 +2,8 @@ package dto
import "expenses/model" import "expenses/model"
// UserDto
// @Description: 简化业务数据
type UserDto struct { type UserDto struct {
Name string `json:"name"` Name string `json:"name"`
Telephone string `json:"telephone"` Telephone string `json:"telephone"`

@ -10,3 +10,7 @@ type User struct {
Telephone string `json:"telephone";gorm:"type:varchar(11);not null;unique"` Telephone string `json:"telephone";gorm:"type:varchar(11);not null;unique"`
Password string `json:"password";gorm:"type:varchar(20);not null"` Password string `json:"password";gorm:"type:varchar(20);not null"`
} }
func (u *User) TableName() string {
return "user"
}

@ -2,6 +2,7 @@ package util
import ( import (
"math/rand" "math/rand"
"os"
"time" "time"
) )
@ -20,3 +21,20 @@ func RandomString(length int) string {
} }
return string(result) return string(result)
} }
// PathExists
//
// @Description: 判断路径是否存在
// @param path
// @return bool
// @return error
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil { //文件或者目录存在
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

Loading…
Cancel
Save