diff --git a/cloud/api.go b/core/cloud/api.go similarity index 100% rename from cloud/api.go rename to core/cloud/api.go diff --git a/cloud/commCloud/api.go b/core/cloud/commCloud/api.go similarity index 95% rename from cloud/commCloud/api.go rename to core/cloud/commCloud/api.go index a062668..f69b37a 100644 --- a/cloud/commCloud/api.go +++ b/core/cloud/commCloud/api.go @@ -1,7 +1,7 @@ package commCloud import ( - "GoClouds/cloud" + "GoClouds/core/cloud" hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol" ) diff --git a/cloud/commCloud/comm.go b/core/cloud/commCloud/comm.go similarity index 100% rename from cloud/commCloud/comm.go rename to core/cloud/commCloud/comm.go diff --git a/cloud/userCloud/api.go b/core/cloud/userCloud/api.go similarity index 95% rename from cloud/userCloud/api.go rename to core/cloud/userCloud/api.go index d74b147..434f0b7 100644 --- a/cloud/userCloud/api.go +++ b/core/cloud/userCloud/api.go @@ -1,7 +1,7 @@ package userCloud import ( - "GoClouds/cloud" + "GoClouds/core/cloud" hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol" ) diff --git a/cloud/userCloud/user.go b/core/cloud/userCloud/user.go similarity index 100% rename from cloud/userCloud/user.go rename to core/cloud/userCloud/user.go diff --git a/core/comm/const.go b/core/comms/const.go similarity index 96% rename from core/comm/const.go rename to core/comms/const.go index b088a11..3b381fc 100644 --- a/core/comm/const.go +++ b/core/comms/const.go @@ -1,4 +1,4 @@ -package comm +package comms import "regexp" diff --git a/core/comm/db.go b/core/comms/db.go similarity index 98% rename from core/comm/db.go rename to core/comms/db.go index 1c5dd47..f0e18c1 100644 --- a/core/comm/db.go +++ b/core/comms/db.go @@ -1,4 +1,4 @@ -package comm +package comms import ( "context" diff --git a/core/utils/code.go b/core/utils/code.go index 52b1c4d..22c2acd 100644 --- a/core/utils/code.go +++ b/core/utils/code.go @@ -1,7 +1,7 @@ package utils import ( - "GoClouds/core/comm" + "GoClouds/core/comms" "fmt" "math/rand" "strings" @@ -20,7 +20,7 @@ func GenValidateCode(width int) string { return sb.String() } func HideUserName(name string) string { - if comm.REG_Phone.MatchString(name) { + if comms.REG_Phone.MatchString(name) { return name[:3] + "****" + name[7:] } return name diff --git a/go.mod b/go.mod index 2e40df7..9e82fc3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gin-gonic/gin v1.7.1 github.com/go-sql-driver/mysql v1.5.0 github.com/mgr9525/HyperByte-Transfer-Protocol v0.0.0-20210422034730-0b85fcf3afe0 - github.com/mgr9525/go-cloud v1.0.6-0.20210423015030-36e66c1af5ed + github.com/mgr9525/go-cloud v1.0.6-0.20210423020002-1f8b2e313a5a github.com/mgr9525/go-ruisutil v1.0.8-0.20210317093428-f69295935056 github.com/qiniu/qmgo v0.9.2 github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index 008e2e3..7f86bcd 100644 --- a/go.sum +++ b/go.sum @@ -99,8 +99,8 @@ github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/ github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= github.com/mgr9525/HyperByte-Transfer-Protocol v0.0.0-20210422034730-0b85fcf3afe0 h1:pnIfNO1DHHY5QSTZZD6bIJa2yDoI+saVY4YaQd8EdA8= github.com/mgr9525/HyperByte-Transfer-Protocol v0.0.0-20210422034730-0b85fcf3afe0/go.mod h1:U2OZ06VD1PHu3ZLZ8tuEHooaOZnoke/4ZKAZfL44bUQ= -github.com/mgr9525/go-cloud v1.0.6-0.20210423015030-36e66c1af5ed h1:xKrlH7FB5iVaWlOhk8Pyfb2KalXDWc3oYHxh9RgnQKQ= -github.com/mgr9525/go-cloud v1.0.6-0.20210423015030-36e66c1af5ed/go.mod h1:VkCKgivVD2OX75Zwh+AO3zuJyxGCsuo0zdy+UXCYy9I= +github.com/mgr9525/go-cloud v1.0.6-0.20210423020002-1f8b2e313a5a h1:7vvaTEyYxLI864HvDEdqHFHYIn/m6k4sxGwUe4wj4Pw= +github.com/mgr9525/go-cloud v1.0.6-0.20210423020002-1f8b2e313a5a/go.mod h1:VkCKgivVD2OX75Zwh+AO3zuJyxGCsuo0zdy+UXCYy9I= github.com/mgr9525/go-ruisutil v1.0.8-0.20210317093428-f69295935056 h1:JhXsFUB3mFWwiDc8c//E/6cUazJUX1lIiLgiM0asNjA= github.com/mgr9525/go-ruisutil v1.0.8-0.20210317093428-f69295935056/go.mod h1:qXUWVKpHdwoxR0KERCkvL1JH2DETY6b5TMG9t6g9Pls= github.com/mgr9525/logrus-file-hook v0.0.0-20210315103109-42681d084c3b h1:sGrxWDbhC2XpDKOLdNrYVo3Ga9YIFMr0AfjnP2gli0o= diff --git a/service/dao.go b/service/dao.go index 6eb99cf..dc449a1 100644 --- a/service/dao.go +++ b/service/dao.go @@ -1,9 +1,9 @@ package service import ( - "GoClouds/core/comm" + "GoClouds/core/comms" gocloud "github.com/mgr9525/go-cloud" ) -var MgoParamDao = gocloud.NewDaoMgo(&comm.DbMongo, "Data", "param") -var MgoUserInfoDao = gocloud.NewDaoMgo(&comm.DbMongo, "Data", "userInfo") +var MgoParamDao = gocloud.NewDaoMgo(&comms.DbMongo, "Data", "param") +var MgoUserInfoDao = gocloud.NewDaoMgo(&comms.DbMongo, "Data", "userInfo") diff --git a/service/mgoService/info.go b/service/mgoService/info.go index 3bd9ca0..909ee92 100644 --- a/service/mgoService/info.go +++ b/service/mgoService/info.go @@ -30,7 +30,7 @@ func GetUserInfoUid(uid string) *models.MgoUserInfo { } else { e.Nick = utils.HideUserName(usr.Name) } - _, err = ses.C().InsertOne(context.Background(), e) + _, err = ses.C().InsertOne(nil, e) if err != nil { return nil } diff --git a/service/mgoService/param.go b/service/mgoService/param.go index 088f62b..7189ff5 100644 --- a/service/mgoService/param.go +++ b/service/mgoService/param.go @@ -56,7 +56,7 @@ func SetParam(key string, val map[string]interface{}, tits ...string) bool { var err error ses := service.MgoParamDao.GetSession() if isup { - err = ses.C().UpdateId(nil, e.Id, bson.M{"$set": bson.M{"value": e.Value, "title": e.Title}}) + err = ses.UpdateId(nil, e.Id, bson.M{"value": e.Value, "title": e.Title}) } else { _, err = ses.C().InsertOne(nil, e) } diff --git a/service/sysService/role.go b/service/sysService/role.go index 1d2f586..70ec53a 100644 --- a/service/sysService/role.go +++ b/service/sysService/role.go @@ -1,7 +1,7 @@ package sysService import ( - "GoClouds/core/comm" + "GoClouds/core/comms" "GoClouds/models" "strings" "xorm.io/builder" @@ -9,7 +9,7 @@ import ( func FindRole(xid string) *models.SysRole { e := new(models.SysRole) - ok, err := comm.DbSysHelper.GetDB().Where("xid=?", xid).Get(e) + ok, err := comms.DbSysHelper.GetDB().Where("xid=?", xid).Get(e) if err != nil { return nil } @@ -20,7 +20,7 @@ func FindRole(xid string) *models.SysRole { } func FindPermission(xid string) *models.SysPermssion { e := new(models.SysPermssion) - ok, err := comm.DbSysHelper.GetDB().Where("xid=?", xid).Get(e) + ok, err := comms.DbSysHelper.GetDB().Where("xid=?", xid).Get(e) if err != nil { return nil } @@ -36,7 +36,7 @@ func FindPermissions(xids string) string { rets := "" permssions := make([]*models.SysPermssion, 0) - err := comm.DbSysHelper.GetDB().Where(builder.In("xid", strings.Split(xids, ","))).Find(&permssions) + err := comms.DbSysHelper.GetDB().Where(builder.In("xid", strings.Split(xids, ","))).Find(&permssions) if err == nil { ln := len(permssions) for i, o := range permssions { diff --git a/service/userService/role.go b/service/userService/role.go index 7b2a223..d8a2793 100644 --- a/service/userService/role.go +++ b/service/userService/role.go @@ -1,7 +1,7 @@ package userService import ( - "GoClouds/core/comm" + "GoClouds/core/comms" "GoClouds/models" "GoClouds/modeluis" "GoClouds/service/sysService" @@ -13,7 +13,7 @@ import ( func FindTreePermission() []*modeluis.TreePermssion { rets := make([]*modeluis.TreePermssion, 0) - err := comm.DbSysHelper.GetDB().Where("parent is null or parent=''").OrderBy("sort ASC,id ASC").Find(&rets) + err := comms.DbSysHelper.GetDB().Where("parent is null or parent=''").OrderBy("sort ASC,id ASC").Find(&rets) if err != nil { println("findPermChilds err:" + err.Error()) return nil @@ -30,7 +30,7 @@ func findPermChilds(parent *modeluis.TreePermssion, upms map[string]bool) { return } childs := make([]*modeluis.TreePermssion, 0) - err := comm.DbSysHelper.GetDB().Where("parent=?", parent.Xid).OrderBy("sort ASC,id ASC").Find(&childs) + err := comms.DbSysHelper.GetDB().Where("parent=?", parent.Xid).OrderBy("sort ASC,id ASC").Find(&childs) if err != nil { println("findPermChilds err:" + err.Error()) return @@ -56,7 +56,7 @@ func FindUPermissions(uid string) []*modeluis.SysPermssion { userRole := FindUserRole(uid) //comm.DbSysHelper.GetDB().SqlTemplateClient("role.stpl") //rids:=strings.Split(userRole.RoleCodes,",") - ses := comm.DbSysHelper.GetDB().Where("xid='common'") + ses := comms.DbSysHelper.GetDB().Where("xid='common'") if len(userRole.RoleCodes) > 0 { rcds := strings.Split(userRole.RoleCodes, ",") ses.Or(builder.In("xid", rcds)) @@ -72,7 +72,7 @@ func FindUPermissions(uid string) []*modeluis.SysPermssion { continue } permssions := make([]*modeluis.SysPermssion, 0) - ses := comm.DbSysHelper.GetDB().Where(builder.In("xid", strings.Split(role.Perms, ","))) + ses := comms.DbSysHelper.GetDB().Where(builder.In("xid", strings.Split(role.Perms, ","))) err := ses.Find(&permssions) if err != nil { println("FindUserPermission err:" + err.Error()) @@ -106,12 +106,12 @@ func FindUPermissions(uid string) []*modeluis.SysPermssion { } func FindUserRole(uid string) *models.SysUserRole { userRole := new(models.SysUserRole) - ok, err := comm.DbSysHelper.GetDB().Where("user_code=?", uid).Get(userRole) + ok, err := comms.DbSysHelper.GetDB().Where("user_code=?", uid).Get(userRole) if err != nil { println("FindUserPermission err:" + err.Error()) } else if !ok { userRole.UserCode = uid - comm.DbSysHelper.GetDB().Insert(userRole) + comms.DbSysHelper.GetDB().Insert(userRole) } return userRole } @@ -125,7 +125,7 @@ func FindUserRoles(uid string) []*modeluis.SysURole { } } roles := make([]*modeluis.SysURole, 0) - err := comm.DbSysHelper.GetDB().Where("xid!='common'").Find(&roles) + err := comms.DbSysHelper.GetDB().Where("xid!='common'").Find(&roles) if err != nil { println("FindUserRoles:" + err.Error()) } @@ -140,7 +140,7 @@ func FindUserPermission(uid string) map[string]bool { userRole := FindUserRole(uid) //comm.DbSysHelper.GetDB().SqlTemplateClient("role.stpl") //rids:=strings.Split(userRole.RoleCodes,",") - ses := comm.DbSysHelper.GetDB().Where("xid='common'") + ses := comms.DbSysHelper.GetDB().Where("xid='common'") if len(userRole.RoleCodes) > 0 { rcds := strings.Split(userRole.RoleCodes, ",") ses.Or(builder.In("xid", rcds)) @@ -156,7 +156,7 @@ func FindUserPermission(uid string) map[string]bool { continue } permssions := make([]*models.SysPermssion, 0) - ses := comm.DbSysHelper.GetDB().Where(builder.In("xid", strings.Split(role.Perms, ","))) + ses := comms.DbSysHelper.GetDB().Where(builder.In("xid", strings.Split(role.Perms, ","))) if len(userRole.Limits) > 0 { rcds := strings.Split(userRole.Limits, ",") ses.And(builder.NotIn("xid", rcds)) diff --git a/service/userService/user.go b/service/userService/user.go index 247221c..f30cb2d 100644 --- a/service/userService/user.go +++ b/service/userService/user.go @@ -1,7 +1,7 @@ package userService import ( - "GoClouds/core/comm" + "GoClouds/core/comms" "GoClouds/models" "github.com/sirupsen/logrus" ) @@ -11,7 +11,7 @@ func FindXid(id string) *models.SysUser { return nil } e := new(models.SysUser) - ok, err := comm.DbSysHelper.GetDB().Where("xid=?", id).Get(e) + ok, err := comms.DbSysHelper.GetDB().Where("xid=?", id).Get(e) if err != nil { logrus.Info("FindUserXid err:", err.Error()) return nil @@ -23,7 +23,7 @@ func FindXid(id string) *models.SysUser { } func FindName(name string) *models.SysUser { e := new(models.SysUser) - ok, err := comm.DbSysHelper.GetDB().Where("name=?", name).Get(e) + ok, err := comms.DbSysHelper.GetDB().Where("name=?", name).Get(e) if err != nil { logrus.Info("FindName err:", err.Error()) return nil diff --git a/service/utilService/mids.go b/service/utilService/mids.go index 522ebc8..8e4eb89 100644 --- a/service/utilService/mids.go +++ b/service/utilService/mids.go @@ -1,7 +1,7 @@ package utilService import ( - "GoClouds/cloud/userCloud" + "GoClouds/core/cloud/userCloud" "GoClouds/models" "github.com/gin-gonic/gin" ) diff --git a/webs/sys/main.go b/webs/sys/main.go index 62866de..b818065 100644 --- a/webs/sys/main.go +++ b/webs/sys/main.go @@ -1,7 +1,7 @@ package main import ( - "GoClouds/core/comm" + "GoClouds/core/comms" "GoClouds/models" "GoClouds/webs/sys/route" "GoClouds/webs/sys/routehb" @@ -34,7 +34,7 @@ func main() { } func initFuns() error { - err := comm.InitDb() + err := comms.InitDb() if err != nil { return err } @@ -55,12 +55,12 @@ func initFuns() error { return nil } func SyncTable() error { - if comm.DbSysHelper.GetDB() == nil { + if comms.DbSysHelper.GetDB() == nil { return nil } - isext, err := comm.DbSysHelper.GetDB().IsTableExist(models.SysUser{}) + isext, err := comms.DbSysHelper.GetDB().IsTableExist(models.SysUser{}) if err == nil && !isext { - comm.DbSysHelper.GetDB().ImportFile("my.sql") + comms.DbSysHelper.GetDB().ImportFile("my.sql") } return nil } diff --git a/webs/sys/routehb/user.go b/webs/sys/routehb/user.go index f21a3aa..f80389b 100644 --- a/webs/sys/routehb/user.go +++ b/webs/sys/routehb/user.go @@ -2,12 +2,11 @@ package routehb import ( "GoClouds/core/bean/sysBean" - "GoClouds/core/comm" + "GoClouds/core/comms" "GoClouds/core/utils" "GoClouds/models" "GoClouds/service" "GoClouds/service/userService" - "context" "fmt" hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol" gocloud "github.com/mgr9525/go-cloud" @@ -60,7 +59,7 @@ func (UserRPC) Login(c *hbtp.Context, m *sysBean.LoginReq) { } if len(usr.Xid) <= 0 { usr.Xid = fmt.Sprintf("%d", usr.Id) - comm.DbSysHelper.GetDB().Cols("xid").Where("id=?", usr.Id).Update(usr) + comms.DbSysHelper.GetDB().Cols("xid").Where("id=?", usr.Id).Update(usr) } if usr.Pass != strings.ToUpper(ruisUtil.Md5String(m.Pass)) { ret.Errs = "密码错误" @@ -73,7 +72,7 @@ func (UserRPC) Login(c *hbtp.Context, m *sysBean.LoginReq) { }*/ usr.Logintm = time.Now() - comm.DbSysHelper.GetDB().Cols("logintm").Where("xid=?", usr.Xid).Update(usr) + comms.DbSysHelper.GetDB().Cols("logintm").Where("xid=?", usr.Xid).Update(usr) ret.Stat = 1 ret.Uid = usr.Id @@ -103,7 +102,7 @@ func (UserRPC) Reg(c *hbtp.Context, m *sysBean.RegReq) { } ne.Times = time.Now() ne.Logintm = time.Now() - _, err := comm.DbSysHelper.GetDB().Insert(ne) + _, err := comms.DbSysHelper.GetDB().Insert(ne) if err != nil { logrus.Debug("nes SysUser insert err:" + err.Error()) c.ResString(hbtp.ResStatusErr, "插入用户错误!!") @@ -118,7 +117,7 @@ func (UserRPC) Reg(c *hbtp.Context, m *sysBean.RegReq) { } else { info.Nick = fmt.Sprintf("U%s", utils.GenValidateCode(7)) } - _, err = service.MgoUserInfoDao.GetSession().C().InsertOne(context.Background(), info) + _, err = service.MgoUserInfoDao.GetSession().C().InsertOne(nil, info) if err != nil { c.ResString(hbtp.ResStatusErr, "qmgo err:"+err.Error()) return @@ -149,7 +148,7 @@ func (UserRPC) Forgot(c *hbtp.Context, m *sysBean.LoginReq) { } ne.Pass = strings.ToUpper(ruisUtil.Md5String(m.Pass)) - _, err := comm.DbSysHelper.GetDB().Cols("pass").Where("id=?", ne.Id).Update(ne) + _, err := comms.DbSysHelper.GetDB().Cols("pass").Where("id=?", ne.Id).Update(ne) if err != nil || ne.Id <= 0 { ret.Errs = "修改用户错误" c.ResJson(hbtp.ResStatusOk, ret) @@ -192,7 +191,7 @@ func (UserRPC) Uppass(c *hbtp.Context, m *sysBean.UppassReq) { } ne.Pass = strings.ToUpper(ruisUtil.Md5String(m.NPass)) - _, err := comm.DbSysHelper.GetDB().Cols("pass").Where("id=?", ne.Id).Update(ne) + _, err := comms.DbSysHelper.GetDB().Cols("pass").Where("id=?", ne.Id).Update(ne) if err != nil || ne.Id <= 0 { ret.Errs = "修改用户错误" c.ResJson(hbtp.ResStatusOk, ret)