Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

36 lignes
545 B

  1. package client
  2. import (
  3. "strconv"
  4. "labix.org/v2/mgo/bson"
  5. "github.com/mikespook/golib/autoinc"
  6. )
  7. type IdGenerator interface {
  8. Id() string
  9. }
  10. // ObjectId
  11. type objectId struct {}
  12. func (id *objectId) Id() string {
  13. return bson.NewObjectId().Hex()
  14. }
  15. func NewObjectId() IdGenerator {
  16. return &objectId{}
  17. }
  18. // AutoIncId
  19. type autoincId struct {
  20. *autoinc.AutoInc
  21. }
  22. func (id *autoincId) Id() string {
  23. return strconv.Itoa(id.AutoInc.Id())
  24. }
  25. func NewAutoIncId() IdGenerator {
  26. return &autoincId{autoinc.New(1, 1)}
  27. }