本文整理汇总了Golang中github.com/juju/core/state.Service.SetCharm方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.SetCharm方法的具体用法?Golang Service.SetCharm怎么用?Golang Service.SetCharm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/core/state.Service
的用法示例。
在下文中一共展示了Service.SetCharm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serviceSetCharm1dot16
// serviceSetCharm1dot16 sets the charm for the given service in 1.16
// compatibility mode. Remove this when support for 1.16 is dropped.
func (c *Client) serviceSetCharm1dot16(service *state.Service, curl *charm.URL, force bool) error {
if curl.Schema != "cs" {
return fmt.Errorf(`charm url has unsupported schema %q`, curl.Schema)
}
if curl.Revision < 0 {
return fmt.Errorf("charm url must include revision")
}
err := c.AddCharm(params.CharmURL{curl.String()})
if err != nil {
return err
}
ch, err := c.api.state.Charm(curl)
if err != nil {
return err
}
return service.SetCharm(ch, force)
}
示例2: serviceSetCharm
// serviceSetCharm sets the charm for the given service.
func (c *Client) serviceSetCharm(service *state.Service, url string, force bool) error {
curl, err := charm.ParseURL(url)
if err != nil {
return err
}
sch, err := c.api.state.Charm(curl)
if errors.IsNotFound(err) {
// Charms should be added before trying to use them, with
// AddCharm or AddLocalCharm API calls. When they're not,
// we're reverting to 1.16 compatibility mode.
return c.serviceSetCharm1dot16(service, curl, force)
}
if err != nil {
return err
}
return service.SetCharm(sch, force)
}