github.com/scottcagno/storage@v1.8.0/pkg/_junk/_ui/auto/autoid.go (about)

     1  package auto
     2  
     3  import "sync"
     4  
     5  // ai (auto increment)
     6  var ai Incr // global instance
     7  
     8  type Incr struct {
     9  	sync.Mutex // ensures Incr is goroutine-safe
    10  	id         int64
    11  }
    12  
    13  func (a *Incr) ID() (id int64) {
    14  	a.Lock()
    15  	defer a.Unlock()
    16  	id = a.id
    17  	a.id++
    18  	return
    19  }
    20  
    21  func (a *Incr) Next() int64 {
    22  	return a.ID()
    23  }