本文整理汇总了Golang中github.com/wallyworld/core/utils/set.Strings.SortedValues方法的典型用法代码示例。如果您正苦于以下问题:Golang Strings.SortedValues方法的具体用法?Golang Strings.SortedValues怎么用?Golang Strings.SortedValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/utils/set.Strings
的用法示例。
在下文中一共展示了Strings.SortedValues方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: collect
// collect calls f on all values in src and returns an alphabetically
// ordered list of the returned results without duplicates.
func (src List) collect(f func(*Tools) string) []string {
var seen set.Strings
for _, tools := range src {
seen.Add(f(tools))
}
return seen.SortedValues()
}
示例2: processRelations
func (*statusContext) processRelations(service *state.Service) (related map[string][]string, subord []string, err error) {
// TODO(mue) This way the same relation is read twice (for each service).
// Maybe add Relations() to state, read them only once and pass them to each
// call of this function.
relations, err := service.Relations()
if err != nil {
return nil, nil, err
}
var subordSet set.Strings
related = make(map[string][]string)
for _, relation := range relations {
ep, err := relation.Endpoint(service.Name())
if err != nil {
return nil, nil, err
}
relationName := ep.Relation.Name
eps, err := relation.RelatedEndpoints(service.Name())
if err != nil {
return nil, nil, err
}
for _, ep := range eps {
if ep.Scope == charm.ScopeContainer && !service.IsPrincipal() {
subordSet.Add(ep.ServiceName)
}
related[relationName] = append(related[relationName], ep.ServiceName)
}
}
for relationName, serviceNames := range related {
sn := set.NewStrings(serviceNames...)
related[relationName] = sn.SortedValues()
}
return related, subordSet.SortedValues(), nil
}
示例3: storeManifest
// storeManifest stores, into dataPath, the supplied manifest for the supplied charm.
func (d *manifestDeployer) storeManifest(url *charm.URL, manifest set.Strings) error {
if err := os.MkdirAll(d.DataPath(manifestsDataPath), 0755); err != nil {
return err
}
name := charm.Quote(url.String())
path := filepath.Join(d.DataPath(manifestsDataPath), name)
return utils.WriteYaml(path, manifest.SortedValues())
}
示例4: ParseMetadataFromStorage
// ParseMetadataFromStorage loads ImageMetadata from the specified storage reader.
func ParseMetadataFromStorage(c *gc.C, stor storage.StorageReader) []*imagemetadata.ImageMetadata {
source := storage.NewStorageSimpleStreamsDataSource("test storage reader", stor, "images")
// Find the simplestreams index file.
params := simplestreams.ValueParams{
DataType: "image-ids",
ValueTemplate: imagemetadata.ImageMetadata{},
}
const requireSigned = false
indexPath := simplestreams.UnsignedIndex
indexRef, err := simplestreams.GetIndexWithFormat(
source, indexPath, "index:1.0", requireSigned, simplestreams.CloudSpec{}, params)
c.Assert(err, gc.IsNil)
c.Assert(indexRef.Indexes, gc.HasLen, 1)
imageIndexMetadata := indexRef.Indexes["com.ubuntu.cloud:custom"]
c.Assert(imageIndexMetadata, gc.NotNil)
// Read the products file contents.
r, err := stor.Get(path.Join("images", imageIndexMetadata.ProductsFilePath))
defer r.Close()
c.Assert(err, gc.IsNil)
data, err := ioutil.ReadAll(r)
c.Assert(err, gc.IsNil)
// Parse the products file metadata.
url, err := source.URL(imageIndexMetadata.ProductsFilePath)
c.Assert(err, gc.IsNil)
cloudMetadata, err := simplestreams.ParseCloudMetadata(data, "products:1.0", url, imagemetadata.ImageMetadata{})
c.Assert(err, gc.IsNil)
// Collate the metadata.
imageMetadataMap := make(map[string]*imagemetadata.ImageMetadata)
var expectedProductIds set.Strings
var imageVersions set.Strings
for _, mc := range cloudMetadata.Products {
for _, items := range mc.Items {
for key, item := range items.Items {
imageMetadata := item.(*imagemetadata.ImageMetadata)
imageMetadataMap[key] = imageMetadata
imageVersions.Add(key)
productId := fmt.Sprintf("com.ubuntu.cloud:server:%s:%s", mc.Version, imageMetadata.Arch)
expectedProductIds.Add(productId)
}
}
}
// Make sure index's product IDs are all represented in the products metadata.
sort.Strings(imageIndexMetadata.ProductIds)
c.Assert(imageIndexMetadata.ProductIds, gc.DeepEquals, expectedProductIds.SortedValues())
imageMetadata := make([]*imagemetadata.ImageMetadata, len(imageMetadataMap))
for i, key := range imageVersions.SortedValues() {
imageMetadata[i] = imageMetadataMap[key]
}
return imageMetadata
}
示例5: AssertValues
// Helper methods for the tests.
func AssertValues(c *gc.C, s set.Strings, expected ...string) {
values := s.Values()
// Expect an empty slice, not a nil slice for values.
if expected == nil {
expected = []string{}
}
sort.Strings(expected)
sort.Strings(values)
c.Assert(values, gc.DeepEquals, expected)
c.Assert(s.Size(), gc.Equals, len(expected))
// Check the sorted values too.
sorted := s.SortedValues()
c.Assert(sorted, gc.DeepEquals, expected)
}
示例6: commonServiceInstances
// commonServiceInstances returns instances with
// services in common with the specified machine.
func commonServiceInstances(st *state.State, m *state.Machine) ([]instance.Id, error) {
units, err := m.Units()
if err != nil {
return nil, err
}
var instanceIdSet set.Strings
for _, unit := range units {
if !unit.IsPrincipal() {
continue
}
service, err := unit.Service()
if err != nil {
return nil, err
}
allUnits, err := service.AllUnits()
if err != nil {
return nil, err
}
for _, unit := range allUnits {
machineId, err := unit.AssignedMachineId()
if state.IsNotAssigned(err) {
continue
} else if err != nil {
return nil, err
}
machine, err := st.Machine(machineId)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instanceIdSet.Add(string(instanceId))
} else if state.IsNotProvisionedError(err) {
continue
} else {
return nil, err
}
}
}
instanceIds := make([]instance.Id, instanceIdSet.Size())
// Sort values to simplify testing.
for i, instanceId := range instanceIdSet.SortedValues() {
instanceIds[i] = instance.Id(instanceId)
}
return instanceIds, nil
}
示例7: ParseMetadataFromStorage
// ParseMetadataFromStorage loads ToolsMetadata from the specified storage reader.
func ParseMetadataFromStorage(c *gc.C, stor storage.StorageReader, expectMirrors bool) []*tools.ToolsMetadata {
source := storage.NewStorageSimpleStreamsDataSource("test storage reader", stor, "tools")
params := simplestreams.ValueParams{
DataType: tools.ContentDownload,
ValueTemplate: tools.ToolsMetadata{},
}
const requireSigned = false
indexPath := simplestreams.UnsignedIndex
indexRef, err := simplestreams.GetIndexWithFormat(
source, indexPath, "index:1.0", requireSigned, simplestreams.CloudSpec{}, params)
c.Assert(err, gc.IsNil)
c.Assert(indexRef.Indexes, gc.HasLen, 1)
toolsIndexMetadata := indexRef.Indexes["com.ubuntu.juju:released:tools"]
c.Assert(toolsIndexMetadata, gc.NotNil)
// Read the products file contents.
r, err := stor.Get(path.Join("tools", toolsIndexMetadata.ProductsFilePath))
defer r.Close()
c.Assert(err, gc.IsNil)
data, err := ioutil.ReadAll(r)
c.Assert(err, gc.IsNil)
url, err := source.URL(toolsIndexMetadata.ProductsFilePath)
c.Assert(err, gc.IsNil)
cloudMetadata, err := simplestreams.ParseCloudMetadata(data, "products:1.0", url, tools.ToolsMetadata{})
c.Assert(err, gc.IsNil)
toolsMetadataMap := make(map[string]*tools.ToolsMetadata)
var expectedProductIds set.Strings
var toolsVersions set.Strings
for _, mc := range cloudMetadata.Products {
for _, items := range mc.Items {
for key, item := range items.Items {
toolsMetadata := item.(*tools.ToolsMetadata)
toolsMetadataMap[key] = toolsMetadata
toolsVersions.Add(key)
seriesVersion, err := ubuntu.SeriesVersion(toolsMetadata.Release)
c.Assert(err, gc.IsNil)
productId := fmt.Sprintf("com.ubuntu.juju:%s:%s", seriesVersion, toolsMetadata.Arch)
expectedProductIds.Add(productId)
}
}
}
// Make sure index's product IDs are all represented in the products metadata.
sort.Strings(toolsIndexMetadata.ProductIds)
c.Assert(toolsIndexMetadata.ProductIds, gc.DeepEquals, expectedProductIds.SortedValues())
toolsMetadata := make([]*tools.ToolsMetadata, len(toolsMetadataMap))
for i, key := range toolsVersions.SortedValues() {
toolsMetadata[i] = toolsMetadataMap[key]
}
if expectMirrors {
r, err = stor.Get(path.Join("tools", simplestreams.UnsignedMirror))
defer r.Close()
c.Assert(err, gc.IsNil)
data, err = ioutil.ReadAll(r)
c.Assert(err, gc.IsNil)
c.Assert(string(data), jc.Contains, `"mirrors":`)
c.Assert(err, gc.IsNil)
}
return toolsMetadata
}