gearman-go/client/id.go

38 lines
566 B
Go
Raw Normal View History

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