github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/state/leadership/token.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package leadership 5 6 import ( 7 "github.com/juju/errors" 8 "gopkg.in/mgo.v2/txn" 9 ) 10 11 // token implements leadership.Token. 12 type token struct { 13 serviceName string 14 unitName string 15 checks chan<- check 16 abort <-chan struct{} 17 } 18 19 // Check is part of the leadership.Token interface. 20 func (t token) Check(out interface{}) error { 21 22 // Check validity and get the assert op in case it's needed. 23 op, err := check{ 24 serviceName: t.serviceName, 25 unitName: t.unitName, 26 response: make(chan txn.Op), 27 abort: t.abort, 28 }.invoke(t.checks) 29 if err != nil { 30 return errors.Trace(err) 31 } 32 33 // Report transaction ops if the client wants them. 34 if out != nil { 35 outPtr, ok := out.(*[]txn.Op) 36 if !ok { 37 return errors.New("expected pointer to []txn.Op") 38 } 39 *outPtr = []txn.Op{op} 40 } 41 return nil 42 }