Better handling for ID generation

This commit is contained in:
cuigh 2017-12-01 16:04:20 +08:00
parent 16bc28897d
commit ec3796d339
7 changed files with 18 additions and 30 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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
//}

View File

@ -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

View File

@ -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 {