mirror of
https://github.com/cuigh/swirl
synced 2024-12-29 07:12:11 +00:00
Better handling for ID generation
This commit is contained in:
parent
16bc28897d
commit
ec3796d339
@ -3,10 +3,10 @@ package biz
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cuigh/auxo/data/guid"
|
|
||||||
"github.com/cuigh/auxo/log"
|
"github.com/cuigh/auxo/log"
|
||||||
"github.com/cuigh/auxo/net/web"
|
"github.com/cuigh/auxo/net/web"
|
||||||
"github.com/cuigh/swirl/dao"
|
"github.com/cuigh/swirl/dao"
|
||||||
|
"github.com/cuigh/swirl/misc"
|
||||||
"github.com/cuigh/swirl/model"
|
"github.com/cuigh/swirl/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ type eventBiz struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *eventBiz) Create(event *model.Event) {
|
func (b *eventBiz) Create(event *model.Event) {
|
||||||
event.ID = guid.New()
|
event.ID = misc.NewID()
|
||||||
event.Time = time.Now()
|
event.Time = time.Now()
|
||||||
|
|
||||||
do(func(d dao.Interface) {
|
do(func(d dao.Interface) {
|
||||||
|
@ -3,9 +3,9 @@ package biz
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cuigh/auxo/data/guid"
|
|
||||||
"github.com/cuigh/auxo/net/web"
|
"github.com/cuigh/auxo/net/web"
|
||||||
"github.com/cuigh/swirl/dao"
|
"github.com/cuigh/swirl/dao"
|
||||||
|
"github.com/cuigh/swirl/misc"
|
||||||
"github.com/cuigh/swirl/model"
|
"github.com/cuigh/swirl/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ type registryBiz struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *registryBiz) Create(registry *model.Registry, user web.User) (err error) {
|
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.CreatedAt = time.Now()
|
||||||
registry.UpdatedAt = registry.CreatedAt
|
registry.UpdatedAt = registry.CreatedAt
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ package biz
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cuigh/auxo/data/guid"
|
|
||||||
"github.com/cuigh/auxo/net/web"
|
"github.com/cuigh/auxo/net/web"
|
||||||
"github.com/cuigh/swirl/dao"
|
"github.com/cuigh/swirl/dao"
|
||||||
|
"github.com/cuigh/swirl/misc"
|
||||||
"github.com/cuigh/swirl/model"
|
"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) {
|
func (b *roleBiz) Create(role *model.Role, user web.User) (err error) {
|
||||||
do(func(d dao.Interface) {
|
do(func(d dao.Interface) {
|
||||||
role.ID = guid.New()
|
role.ID = misc.NewID()
|
||||||
role.CreatedAt = time.Now()
|
role.CreatedAt = time.Now()
|
||||||
role.UpdatedAt = role.CreatedAt
|
role.UpdatedAt = role.CreatedAt
|
||||||
err = d.RoleCreate(role)
|
err = d.RoleCreate(role)
|
||||||
|
@ -4,9 +4,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cuigh/auxo/data/guid"
|
|
||||||
"github.com/cuigh/auxo/net/web"
|
"github.com/cuigh/auxo/net/web"
|
||||||
"github.com/cuigh/swirl/dao"
|
"github.com/cuigh/swirl/dao"
|
||||||
|
"github.com/cuigh/swirl/misc"
|
||||||
"github.com/cuigh/swirl/model"
|
"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) {
|
func (b *templateBiz) Create(tpl *model.Template, user web.User) (err error) {
|
||||||
do(func(d dao.Interface) {
|
do(func(d dao.Interface) {
|
||||||
tpl.ID = guid.New()
|
tpl.ID = misc.NewID()
|
||||||
err = d.TemplateCreate(tpl)
|
err = d.TemplateCreate(tpl)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
Event.CreateServiceTemplate(model.EventActionCreate, tpl.ID, tpl.Name, user)
|
Event.CreateServiceTemplate(model.EventActionCreate, tpl.ID, tpl.Name, user)
|
||||||
|
23
biz/user.go
23
biz/user.go
@ -6,12 +6,12 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cuigh/auxo/data/guid"
|
|
||||||
"github.com/cuigh/auxo/errors"
|
"github.com/cuigh/auxo/errors"
|
||||||
"github.com/cuigh/auxo/log"
|
"github.com/cuigh/auxo/log"
|
||||||
"github.com/cuigh/auxo/net/web"
|
"github.com/cuigh/auxo/net/web"
|
||||||
"github.com/cuigh/auxo/security/password"
|
"github.com/cuigh/auxo/security/password"
|
||||||
"github.com/cuigh/swirl/dao"
|
"github.com/cuigh/swirl/dao"
|
||||||
|
"github.com/cuigh/swirl/misc"
|
||||||
"github.com/cuigh/swirl/model"
|
"github.com/cuigh/swirl/model"
|
||||||
"github.com/go-ldap/ldap"
|
"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) {
|
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.Status = model.UserStatusActive
|
||||||
user.CreatedAt = time.Now()
|
user.CreatedAt = time.Now()
|
||||||
user.UpdatedAt = user.CreatedAt
|
user.UpdatedAt = user.CreatedAt
|
||||||
@ -172,7 +172,7 @@ func (b *userBiz) Login(name, pwd string) (token string, err error) {
|
|||||||
|
|
||||||
session := &model.Session{
|
session := &model.Session{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
Token: guid.New(),
|
Token: misc.NewID(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
session.Expires = session.UpdatedAt.Add(time.Hour * 24)
|
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
|
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
|
|
||||||
//}
|
|
||||||
|
@ -3,7 +3,7 @@ package mongo
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cuigh/auxo/data/guid"
|
"github.com/cuigh/swirl/misc"
|
||||||
"github.com/cuigh/swirl/model"
|
"github.com/cuigh/swirl/model"
|
||||||
"gopkg.in/mgo.v2"
|
"gopkg.in/mgo.v2"
|
||||||
"gopkg.in/mgo.v2/bson"
|
"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) {
|
func (d *Dao) ArchiveCreate(archive *model.Archive) (err error) {
|
||||||
archive.ID = guid.New()
|
archive.ID = misc.NewID()
|
||||||
archive.CreatedAt = time.Now()
|
archive.CreatedAt = time.Now()
|
||||||
archive.UpdatedAt = archive.CreatedAt
|
archive.UpdatedAt = archive.CreatedAt
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cuigh/auxo/data/guid"
|
||||||
"github.com/cuigh/auxo/util/i18n"
|
"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 {
|
func Message(lang string) func(key string, args ...interface{}) string {
|
||||||
t, err := i18n.Find(lang, "en")
|
t, err := i18n.Find(lang, "en")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user