From 1460ba8cbd2c15f295301a7a51e389e6d19cf419 Mon Sep 17 00:00:00 2001 From: zggsong Date: Thu, 9 Feb 2023 17:16:12 +0800 Subject: [PATCH] chore: update --- server/common/logger.go | 20 ++------------------ server/dto/user_dto.go | 2 ++ server/model/user.go | 4 ++++ server/util/util.go | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/server/common/logger.go b/server/common/logger.go index 03f5777..1a26450 100644 --- a/server/common/logger.go +++ b/server/common/logger.go @@ -1,6 +1,7 @@ package common import ( + "expenses/util" "fmt" "io" "log" @@ -14,7 +15,7 @@ var Log *log.Logger // // @Description: 初始化Logger func Init() { - exists, _ := pathExists("./log") + exists, _ := util.PathExists("./log") if !exists { _ = 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 -} diff --git a/server/dto/user_dto.go b/server/dto/user_dto.go index 85e2528..c13f1a4 100644 --- a/server/dto/user_dto.go +++ b/server/dto/user_dto.go @@ -2,6 +2,8 @@ package dto import "expenses/model" +// UserDto +// @Description: 简化业务数据 type UserDto struct { Name string `json:"name"` Telephone string `json:"telephone"` diff --git a/server/model/user.go b/server/model/user.go index 80f216b..0a5844a 100644 --- a/server/model/user.go +++ b/server/model/user.go @@ -10,3 +10,7 @@ type User struct { Telephone string `json:"telephone";gorm:"type:varchar(11);not null;unique"` Password string `json:"password";gorm:"type:varchar(20);not null"` } + +func (u *User) TableName() string { + return "user" +} diff --git a/server/util/util.go b/server/util/util.go index 14c7da1..28eb2a5 100644 --- a/server/util/util.go +++ b/server/util/util.go @@ -2,6 +2,7 @@ package util import ( "math/rand" + "os" "time" ) @@ -20,3 +21,20 @@ func RandomString(length int) string { } 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 +}