diff --git a/biz/event.go b/biz/event.go index d21442f..218c079 100644 --- a/biz/event.go +++ b/biz/event.go @@ -3,10 +3,10 @@ package biz import ( "time" - "github.com/cuigh/auxo/data/guid" "github.com/cuigh/auxo/log" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/dao" + "github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/model" ) @@ -17,7 +17,7 @@ type eventBiz struct { } func (b *eventBiz) Create(event *model.Event) { - event.ID = guid.New() + event.ID = misc.NewID() event.Time = time.Now() do(func(d dao.Interface) { diff --git a/biz/registry.go b/biz/registry.go index 4f06f9f..553e436 100644 --- a/biz/registry.go +++ b/biz/registry.go @@ -3,9 +3,9 @@ package biz import ( "time" - "github.com/cuigh/auxo/data/guid" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/dao" + "github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/model" ) @@ -15,7 +15,7 @@ type registryBiz struct { } func (b *registryBiz) Create(registry *model.Registry, user web.User) (err error) { - registry.ID = guid.New() + registry.ID = misc.NewID() registry.CreatedAt = time.Now() registry.UpdatedAt = registry.CreatedAt diff --git a/biz/role.go b/biz/role.go index 1044a46..c1a4f88 100644 --- a/biz/role.go +++ b/biz/role.go @@ -3,9 +3,9 @@ package biz import ( "time" - "github.com/cuigh/auxo/data/guid" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/dao" + "github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/model" ) @@ -24,7 +24,7 @@ func (b *roleBiz) List() (roles []*model.Role, err error) { func (b *roleBiz) Create(role *model.Role, user web.User) (err error) { do(func(d dao.Interface) { - role.ID = guid.New() + role.ID = misc.NewID() role.CreatedAt = time.Now() role.UpdatedAt = role.CreatedAt err = d.RoleCreate(role) diff --git a/biz/template.go b/biz/template.go index 3c257d5..f928b60 100644 --- a/biz/template.go +++ b/biz/template.go @@ -4,9 +4,9 @@ import ( "encoding/json" "time" - "github.com/cuigh/auxo/data/guid" "github.com/cuigh/auxo/net/web" "github.com/cuigh/swirl/dao" + "github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/model" ) @@ -25,7 +25,7 @@ func (b *templateBiz) List(args *model.TemplateListArgs) (tpls []*model.Template func (b *templateBiz) Create(tpl *model.Template, user web.User) (err error) { do(func(d dao.Interface) { - tpl.ID = guid.New() + tpl.ID = misc.NewID() err = d.TemplateCreate(tpl) if err == nil { Event.CreateServiceTemplate(model.EventActionCreate, tpl.ID, tpl.Name, user) diff --git a/biz/user.go b/biz/user.go index 4394075..8226162 100644 --- a/biz/user.go +++ b/biz/user.go @@ -6,12 +6,12 @@ import ( "net" "time" - "github.com/cuigh/auxo/data/guid" "github.com/cuigh/auxo/errors" "github.com/cuigh/auxo/log" "github.com/cuigh/auxo/net/web" "github.com/cuigh/auxo/security/password" "github.com/cuigh/swirl/dao" + "github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/model" "github.com/go-ldap/ldap" ) @@ -38,7 +38,7 @@ func (b *userBiz) GetByName(loginName string) (user *model.User, err error) { } func (b *userBiz) Create(user *model.User, ctxUser web.User) (err error) { - user.ID = guid.New() + user.ID = misc.NewID() user.Status = model.UserStatusActive user.CreatedAt = time.Now() user.UpdatedAt = user.CreatedAt @@ -172,7 +172,7 @@ func (b *userBiz) Login(name, pwd string) (token string, err error) { session := &model.Session{ UserID: user.ID, - Token: guid.New(), + Token: misc.NewID(), UpdatedAt: time.Now(), } session.Expires = session.UpdatedAt.Add(time.Hour * 24) @@ -353,20 +353,3 @@ func (b *userBiz) Authorize(user web.User, h web.HandlerInfo) bool { } return false } - -// -//func (b *userBiz) Find(key string) string { -// b.locker.Lock() -// defer b.locker.Unlock() -// -// return b.tickets[key] -//} -// -//func (b *userBiz) setTicket(name string) (key string) { -// b.locker.Lock() -// defer b.locker.Unlock() -// -// key = guid.New() -// b.tickets[key] = name -// return -//} diff --git a/dao/mongo/stack.go b/dao/mongo/stack.go index 7088a03..a7d2d87 100644 --- a/dao/mongo/stack.go +++ b/dao/mongo/stack.go @@ -3,7 +3,7 @@ package mongo import ( "time" - "github.com/cuigh/auxo/data/guid" + "github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/model" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" @@ -29,7 +29,7 @@ func (d *Dao) ArchiveList(args *model.ArchiveListArgs) (archives []*model.Archiv } func (d *Dao) ArchiveCreate(archive *model.Archive) (err error) { - archive.ID = guid.New() + archive.ID = misc.NewID() archive.CreatedAt = time.Now() archive.UpdatedAt = archive.CreatedAt diff --git a/misc/util.go b/misc/util.go index ae3d546..c82fff8 100644 --- a/misc/util.go +++ b/misc/util.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/cuigh/auxo/data/guid" "github.com/cuigh/auxo/util/i18n" ) @@ -35,6 +36,10 @@ var Funcs = map[string]interface{}{ }, } +func NewID() string { + return guid.New().String() +} + func Message(lang string) func(key string, args ...interface{}) string { t, err := i18n.Find(lang, "en") if err != nil {