Add user dir & file

This commit is contained in:
Wancat
2022-11-04 23:06:32 +08:00
parent bca1735393
commit 9f99aad680
6 changed files with 149 additions and 109 deletions

28
user.go Normal file
View File

@@ -0,0 +1,28 @@
package main
import (
"os"
"path"
)
type User struct {
IsLogin bool
Email string `form:"email" binding:"required"`
Password string `form:"password" binding:"required"`
}
func (u *User) Dir() string {
dir := path.Join(DATA_DIR, u.Email)
if err := os.MkdirAll(dir, 0755); err != nil {
panic(err)
}
return dir
}
func (u *User) FilePath(name string) string {
return path.Join(DATA_DIR, u.Email, name)
}
func (u *User) File(name string) (*os.File, error) {
return os.OpenFile(u.FilePath(name), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
}