本文整理汇总了Golang中github.com/juju/charm.Repository类的典型用法代码示例。如果您正苦于以下问题:Golang Repository类的具体用法?Golang Repository怎么用?Golang Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Repository类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addCharmViaAPI
// addCharmViaAPI calls the appropriate client API calls to add the
// given charm URL to state. Also displays the charm URL of the added
// charm on stdout.
func addCharmViaAPI(client *api.Client, ctx *cmd.Context, curl *charm.URL, repo charm.Repository) (*charm.URL, error) {
if curl.Revision < 0 {
latest, err := charm.Latest(repo, curl)
if err != nil {
return nil, err
}
curl = curl.WithRevision(latest)
}
switch curl.Schema {
case "local":
ch, err := repo.Get(curl)
if err != nil {
return nil, err
}
stateCurl, err := client.AddLocalCharm(curl, ch)
if err != nil {
return nil, err
}
curl = stateCurl
case "cs":
err := client.AddCharm(curl)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unsupported charm URL schema: %q", curl.Schema)
}
ctx.Infof("Added charm %q to the environment.", curl)
return curl, nil
}
示例2: PutCharm
// PutCharm uploads the given charm to provider storage, and adds a
// state.Charm to the state. The charm is not uploaded if a charm with
// the same URL already exists in the state.
// If bumpRevision is true, the charm must be a local directory,
// and the revision number will be incremented before pushing.
func (conn *Conn) PutCharm(curl *charm.URL, repo charm.Repository, bumpRevision bool) (*state.Charm, error) {
if curl.Revision == -1 {
rev, err := charm.Latest(repo, curl)
if err != nil {
return nil, fmt.Errorf("cannot get latest charm revision: %v", err)
}
curl = curl.WithRevision(rev)
}
ch, err := repo.Get(curl)
if err != nil {
return nil, fmt.Errorf("cannot get charm: %v", err)
}
if bumpRevision {
chd, ok := ch.(*charm.Dir)
if !ok {
return nil, fmt.Errorf("cannot increment revision of charm %q: not a directory", curl)
}
if err = chd.SetDiskRevision(chd.Revision() + 1); err != nil {
return nil, fmt.Errorf("cannot increment revision of charm %q: %v", curl, err)
}
curl = curl.WithRevision(chd.Revision())
}
if sch, err := conn.State.Charm(curl); err == nil {
return sch, nil
}
return conn.addCharm(curl, ch)
}
示例3: resolveCharm
func (c *Client) resolveCharm(ref charm.Reference, repo charm.Repository) (*charm.URL, error) {
if ref.Schema != "cs" {
return nil, fmt.Errorf("only charm store charm references are supported, with cs: schema")
}
// Resolve the charm location with the repository.
return repo.Resolve(ref)
}