github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/state/globalclock/config.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package globalclock 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/mongo" 10 ) 11 12 // UpdaterConfig contains the resources and information required to 13 // create an Updater. 14 type UpdaterConfig struct { 15 Config 16 } 17 18 // ReaderConfig contains the resources and information required to 19 // create a Reader. 20 type ReaderConfig struct { 21 Config 22 } 23 24 // Config contains the common resources and information required to 25 // create an Updater or Reader. 26 type Config struct { 27 // Collection names the MongoDB collection in which the clock 28 // documents are stored. 29 Collection string 30 31 // Mongo exposes the mgo capabilities required by a Client 32 // for updating and reading the clock. 33 Mongo Mongo 34 } 35 36 // Mongo exposes MongoDB operations for use by the globalclock package. 37 type Mongo interface { 38 // GetCollection should probably call the mongo.CollectionFromName func 39 GetCollection(name string) (collection mongo.Collection, closer func()) 40 } 41 42 // validate returns an error if the supplied config is not valid. 43 func (config Config) validate() error { 44 if config.Collection == "" { 45 return errors.New("missing collection") 46 } 47 if config.Mongo == nil { 48 return errors.New("missing mongo client") 49 } 50 return nil 51 }