36 lines
517 B
Go
36 lines
517 B
Go
package client
|
|
|
|
import (
|
|
"github.com/mikespook/golib/autoinc"
|
|
"labix.org/v2/mgo/bson"
|
|
"strconv"
|
|
)
|
|
|
|
type IdGenerator interface {
|
|
Id() string
|
|
}
|
|
|
|
// ObjectId
|
|
type objectId struct{}
|
|
|
|
func (id *objectId) Id() string {
|
|
return bson.NewObjectId().Hex()
|
|
}
|
|
|
|
func NewObjectId() IdGenerator {
|
|
return &objectId{}
|
|
}
|
|
|
|
// 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)}
|
|
}
|