gearman-go/client/id.go

36 lines
517 B
Go
Raw Normal View History

package client
import (
2013-08-29 16:51:23 +08:00
"github.com/mikespook/golib/autoinc"
"labix.org/v2/mgo/bson"
"strconv"
)
type IdGenerator interface {
2013-08-29 16:51:23 +08:00
Id() string
}
// ObjectId
2013-08-29 16:51:23 +08:00
type objectId struct{}
func (id *objectId) Id() string {
2013-08-29 16:51:23 +08:00
return bson.NewObjectId().Hex()
}
func NewObjectId() IdGenerator {
2013-08-29 16:51:23 +08:00
return &objectId{}
}
// AutoIncId
type autoincId struct {
2013-08-29 16:51:23 +08:00
*autoinc.AutoInc
}
func (id *autoincId) Id() string {
2013-08-29 16:51:23 +08:00
return strconv.Itoa(id.AutoInc.Id())
}
func NewAutoIncId() IdGenerator {
2013-08-29 16:51:23 +08:00
return &autoincId{autoinc.New(1, 1)}
}