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