github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/worker/util/api.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package util 5 6 import ( 7 "github.com/juju/juju/api/base" 8 "github.com/juju/juju/worker" 9 "github.com/juju/juju/worker/dependency" 10 ) 11 12 // Some (hopefully growing number of) manifolds completely depend on an API 13 // connection; this type configures them. 14 type ApiManifoldConfig struct { 15 APICallerName string 16 } 17 18 // ApiStartFunc encapsulates the behaviour that varies among ApiManifolds. 19 type ApiStartFunc func(base.APICaller) (worker.Worker, error) 20 21 // ApiManifold returns a dependency.Manifold that calls the supplied start 22 // func with the API resource defined in the config (once it's present). 23 func ApiManifold(config ApiManifoldConfig, start ApiStartFunc) dependency.Manifold { 24 return dependency.Manifold{ 25 Inputs: []string{ 26 config.APICallerName, 27 }, 28 Start: func(getResource dependency.GetResourceFunc) (worker.Worker, error) { 29 var apiCaller base.APICaller 30 if err := getResource(config.APICallerName, &apiCaller); err != nil { 31 return nil, err 32 } 33 return start(apiCaller) 34 }, 35 } 36 }