本文整理汇总了Golang中launchpad/net/gomaasapi.JSONObject类的典型用法代码示例。如果您正苦于以下问题:Golang JSONObject类的具体用法?Golang JSONObject怎么用?Golang JSONObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSONObject类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: extractFilenames
// extractFilenames returns the filenames from a "list" operation on the
// MAAS API, sorted by name.
func (stor *maasStorage) extractFilenames(listResult gomaasapi.JSONObject) ([]string, error) {
list, err := listResult.GetArray()
if err != nil {
return nil, err
}
result := make([]string, len(list))
for index, entry := range list {
file, err := entry.GetMap()
if err != nil {
return nil, err
}
filename, err := file["filename"].GetString()
if err != nil {
return nil, err
}
result[index] = filename
}
sort.Strings(result)
return result, nil
}
示例2: extractFilenames
// extractFilenames returns the filenames from a "list" operation on the
// MAAS API, sorted by name.
func (stor *maasStorage) extractFilenames(listResult gomaasapi.JSONObject) ([]string, error) {
privatePrefix := stor.prefixWithPrivateNamespace("")
list, err := listResult.GetArray()
if err != nil {
return nil, err
}
result := make([]string, len(list))
for index, entry := range list {
file, err := entry.GetMap()
if err != nil {
return nil, err
}
filename, err := file["filename"].GetString()
if err != nil {
return nil, err
}
// When listing files we need to return them without our special prefix.
result[index] = strings.TrimPrefix(filename, privatePrefix)
}
sort.Strings(result)
return result, nil
}
示例3: acquireNode
// acquireNode allocates a node from the MAAS.
func (environ *maasEnviron) acquireNode(cons constraints.Value, possibleTools tools.List) (gomaasapi.MAASObject, *state.Tools, error) {
constraintsParams := convertConstraints(cons)
var result gomaasapi.JSONObject
var err error
for a := shortAttempt.Start(); a.Next(); {
client := environ.getMAASClient().GetSubObject("nodes/")
result, err = client.CallPost("acquire", constraintsParams)
if err == nil {
break
}
}
if err != nil {
return gomaasapi.MAASObject{}, nil, err
}
node, err := result.GetMAASObject()
if err != nil {
msg := fmt.Errorf("unexpected result from 'acquire' on MAAS API: %v", err)
return gomaasapi.MAASObject{}, nil, msg
}
tools := possibleTools[0]
logger.Warningf("picked arbitrary tools %q", tools)
return node, tools, nil
}