当前位置: 首页>>代码示例>>Golang>>正文


Golang sort.StringSlice类代码示例

本文整理汇总了Golang中sort.StringSlice的典型用法代码示例。如果您正苦于以下问题:Golang StringSlice类的具体用法?Golang StringSlice怎么用?Golang StringSlice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StringSlice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: setUpdate

func setUpdate(prev []string, v interface{}) []string {
	m := map[string]bool{}
	for _, v := range prev {
		m[v] = true
	}

	switch i := v.(type) {
	case nil:
	case string:
		m[i] = true
	case []interface{}:
		for _, v := range i {
			val, ok := v.(string)
			if ok {
				m[val] = true
			}
		}
	}

	rv := sort.StringSlice{}
	for k := range m {
		rv = append(rv, k)
	}
	rv.Sort()
	return []string(rv)
}
开发者ID:couchbaselabs,项目名称:statstore,代码行数:26,代码来源:data.go

示例2: setUsage

func setUsage(commands map[string]Command) {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr,
			"Usage:\n  %s [http://cbfs:8484/] cmd [-opts] cmdargs\n",
			os.Args[0])

		fmt.Fprintf(os.Stderr, "\nCommands:\n")

		ss := sort.StringSlice{}
		for k := range commands {
			ss = append(ss, k)
		}
		ss.Sort()

		for _, k := range ss {
			fmt.Fprintf(os.Stderr, "  %s %s\n", k, commands[k].Argstr)
		}

		fmt.Fprintf(os.Stderr, "\n---- Subcommand Options ----\n")

		for _, k := range ss {
			if commands[k].Flags != nil {
				fmt.Fprintf(os.Stderr, "\n%s:\n", k)
				commands[k].Flags.PrintDefaults()
			}
		}

		os.Exit(1)
	}
}
开发者ID:piaohai,项目名称:cbfs,代码行数:30,代码来源:tool.go

示例3: AminoAcidCode

// Returns the code for an ambigious amino acid.
func AminoAcidCode(aa string) string {
	aa = strings.ToUpper(aa)
	if len(aa) == 1 {
		return aa
	}
	letters := sort.StringSlice{aa[:]}
	letters.Sort()
	sorted := strings.Join([]string(letters), "")
	switch sorted {
	case "AG":
		return "R"
	case "CT":
		return "Y"
	case "AC":
		return "M"
	case "GT":
		return "K"
	case "CG":
		return "S"
	case "AT":
		return "W"
	case "ACT":
		return "H"
	case "CGT":
		return "B"
	case "ACG":
		return "V"
	case "AGT":
		return "D"
	case "ACGT":
		return "N"
	}
	return aa
}
开发者ID:baruchlubinsky,项目名称:bioutil,代码行数:35,代码来源:amino_acids.go

示例4: ConfigList

func ConfigList(configStore *config.Store, app, env string) error {

	cfg, err := configStore.GetApp(app, env)
	if err != nil {
		return err
	}

	if cfg == nil {
		return fmt.Errorf("unable to list config for %s.", app)
	}

	keys := sort.StringSlice{"ENV"}
	for k, _ := range cfg.Env() {
		keys = append(keys, k)
	}

	keys.Sort()

	for _, k := range keys {
		if k == "ENV" {
			log.Printf("%s=%s\n", k, env)
			continue
		}
		fmt.Printf("%s=%s\n", k, cfg.Env()[k])
	}

	return nil
}
开发者ID:sguzwf,项目名称:galaxy,代码行数:28,代码来源:config.go

示例5: UploadDirTree

// UploadDirTree uploads a local directory and all of its subfolders
// localDir 		-> path to the local folder to upload along with all of its subfolders.
// remoteRootDir 	-> the root folder on the FTP server where to store the localDir tree.
// excludedDirs		-> a slice of folder names to exclude from the uploaded directory tree.
// callback			-> a callback function, which is called synchronously. Do remember to collect data in a go routine for instance if you do not want the upload to block.
// Returns the number of files uploaded and an error if any.
//
// The current workding directory is set back to the initial value at the end.
func (ftp *FTP) UploadDirTree(localDir string, remoteRootDir string, maxSimultaneousConns int, excludedDirs []string, callback Callback) (n int, err error) {

	if len(remoteRootDir) == 0 {
		return n, errors.New("A valid remote root folder with write permission needs specifying.")
	}

	var pwd string
	if pwd, err = ftp.Pwd(); err != nil {
		return
	}

	if _, err = ftp.Cwd(remoteRootDir); err != nil {
		return n, nil
	}
	//go back to original wd
	defer ftp.Cwd(pwd)

	//all lower case
	var exDirs sort.StringSlice
	if len(excludedDirs) > 0 {
		exDirs = sort.StringSlice(excludedDirs)
		for _, v := range exDirs {
			v = strings.ToLower(v)
		}
		exDirs.Sort()
	}

	err = ftp.uploadDirTree(localDir, exDirs, callback, &n)
	if err != nil {
		ftp.writeInfo(fmt.Sprintf("An error while uploading the folder %s occurred.", localDir))
	}

	return n, err
}
开发者ID:ghp268,项目名称:ftp4go-1,代码行数:42,代码来源:clientutil.go

示例6: sortFlags

// sortFlags returns the flags as a slice in lexicographical sorted order.
func sortFlags(flags map[string]*Flag) []*Flag {
	var list sort.StringSlice
	for _, f := range flags {
		if len(f.Names) == 1 {
			list = append(list, f.Names[0])
			continue
		}

		found := false
		fName := strings.TrimPrefix(strings.TrimPrefix(f.Names[0], "#"), "-")
		for _, name := range list {
			if name == fName {
				found = true
				break
			}
		}
		if !found {
			list = append(list, fName)
		}
	}
	list.Sort()
	result := make([]*Flag, len(list))
	for i, name := range list {
		result[i] = flags[name]
	}
	return result
}
开发者ID:rjjb3427,项目名称:docker,代码行数:28,代码来源:flag.go

示例7: _CheckSignature

// 校验消息是否是从微信服务器发送过来的.
// 使用 buf 能提高一点性能 和 减少一些对 GC 的压力, buf 的长度最好 >=128
func _CheckSignature(signature, timestamp, nonce, token string, buf []byte) bool {
	const hashsumLen = 40 // sha1

	if len(signature) != hashsumLen {
		return false
	}

	bufLen := hashsumLen + len(timestamp) + len(nonce) + len(token)
	if len(buf) < bufLen {
		buf = make([]byte, hashsumLen, bufLen)
	} else {
		buf = buf[:hashsumLen]
	}

	strArray := sort.StringSlice{token, timestamp, nonce}
	strArray.Sort()

	buf = append(buf, strArray[0]...)
	buf = append(buf, strArray[1]...)
	buf = append(buf, strArray[2]...)

	hashsumArray := sha1.Sum(buf[hashsumLen:]) // require go1.2+

	hashsumHexBytes := buf[:hashsumLen]
	hex.Encode(hashsumHexBytes, hashsumArray[:])

	// 采用 subtle.ConstantTimeCompare 是防止 计时攻击!
	if rslt := subtle.ConstantTimeCompare(hashsumHexBytes, []byte(signature)); rslt == 1 {
		return true
	}
	return false
}
开发者ID:GOCMS,项目名称:wechat,代码行数:34,代码来源:signature.go

示例8: display

func display(w io.Writer, format string, title string, supportedSites map[string]string) {

	var urls sort.StringSlice
	for url := range supportedSites {
		urls = append(urls, url)
	}
	urls.Sort()

	switch format {
	case "html":
		fmt.Fprint(w, "\t\tSupported "+title+":")
		fmt.Fprint(w, "<br />\n")
		for _, url := range urls {
			var s string

			if strings.Contains(url, "http") {
				s = "\t\t<a href=\"" + url + "\">" + supportedSites[url] + "</a><br />\n"
			} else {
				s = "\t\t<a href=\"http://www." + url + "\">" + supportedSites[url] + "</a><br />\n"
			}

			fmt.Fprint(w, s)
		}
	default:
		fmt.Fprint(w, "Supported journals:\n\n")
		for _, url := range urls {
			fmt.Fprint(w, supportedSites[url]+"\t\t"+url+"\n")
		}
	}
}
开发者ID:frankMilde,项目名称:rol,代码行数:30,代码来源:store.go

示例9: Usage

func (cmdr *Commander) Usage() {
	fmt.Printf("usage: %s cmd [cmd-flags] [cmd-args]\n", os.Args[0])

	var groupNames sort.StringSlice
	cmdNamesByGroup := map[string]sort.StringSlice{}
	for _, cmd := range cmdr.Commands {
		if _, ok := cmdNamesByGroup[cmd.Group]; !ok {
			groupNames = append(groupNames, cmd.Group)
		}

		cmdNamesByGroup[cmd.Group] = append(cmdNamesByGroup[cmd.Group], cmd.Name)
	}

	groupNames.Sort()

	for _, gn := range groupNames {
		fmt.Printf("\n%s:\n", gn)

		cmdNamesByGroup[gn].Sort()

		for _, cn := range cmdNamesByGroup[gn] {
			cmd := cmdr.Commands[cn]
			fmt.Printf("    %-18s %s\n", cmd.Name, cmd.Description)
		}
	}

	fmt.Println()
}
开发者ID:xsleonard,项目名称:cmd,代码行数:28,代码来源:cmd.go

示例10: ComputeChecksum

// computeChecksum computes checksum of all servers in the ring
func (r *hashRing) ComputeChecksum() {
	var addresses sort.StringSlice
	var buffer bytes.Buffer

	r.servers.Lock()
	for address := range r.servers.byAddress {
		addresses = append(addresses, address)
	}

	addresses.Sort()

	for _, address := range addresses {
		buffer.WriteString(address)
		buffer.WriteString(";")
	}

	old := r.servers.checksum
	r.servers.checksum = farm.Fingerprint32(buffer.Bytes())
	r.ringpop.ringEvent(RingChecksumEvent{
		OldChecksum: old,
		NewChecksum: r.servers.checksum,
	})

	r.servers.Unlock()
}
开发者ID:coderQQ,项目名称:ringpop-go,代码行数:26,代码来源:hashring.go

示例11: String

func (ee EtcdEnvironment) String() (out string) {
	norm := normalizeSvcEnv(ee)

	if val, ok := norm["DISCOVERY_URL"]; ok {
		delete(norm, "DISCOVERY_URL")
		if _, ok := norm["DISCOVERY"]; !ok {
			norm["DISCOVERY"] = val
		}
	}

	var sorted sort.StringSlice
	for k, _ := range norm {
		sorted = append(sorted, k)
	}
	sorted.Sort()

	out += "[Service]\n"

	for _, key := range sorted {
		val := norm[key]
		out += fmt.Sprintf("Environment=\"ETCD_%s=%s\"\n", key, val)
	}

	return
}
开发者ID:rcleere,项目名称:coreos-cloudinit,代码行数:25,代码来源:etcd.go

示例12: findFile

// findFile finds a file that ends with name.md, ignoring leading digits and dashes (to support blogging and
// sorting of .md files a-là jekyll) and returns it's name. It returns an error if no path is found.
// Names ending with / are automatically added index to them. If there are multiple paths ending with name.md,
// they are sorted lexicographically and the biggest path is returned, so e.g. 2014-01-01-results.md
// will have preference over 2013-01-01-results.md
func findFile(root, name string) (string, error) {
	if strings.HasSuffix(name, "/") || name == "" {
		name += "index"
	}
	name += ".md"
	basename := filepath.Base(name)
	dirname := filepath.Dir(name)
	matches, err := filepath.Glob(filepath.Join(root, dirname, "*"+basename))
	if err != nil {
		return "", err
	}
	if len(matches) == 0 {
		return "", fmt.Errorf("no matches for pattern %s", name)
	}
	var prefixes sort.StringSlice
	for _, m := range matches {
		m = filepath.Base(m)
		if p := m[:len(m)-len(basename)]; isDigital(p) {
			prefixes = append(prefixes, p)
		}
	}
	if len(prefixes) == 0 {
		return "", fmt.Errorf("no matches for pattern %s", name)
	}
	prefixes.Sort()
	return filepath.Join(root, dirname, prefixes[len(prefixes)-1]+basename), nil
}
开发者ID:grafikdb,项目名称:grafik-public,代码行数:32,代码来源:handlers.go

示例13: Less

func (d destinations) Less(i, j int) bool {
	switch d[i].routeFamily {
	case bgp.RF_FS_IPv4_UC, bgp.RF_FS_IPv6_UC, bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN, bgp.RF_FS_L2_VPN:
		var s, t *bgp.FlowSpecNLRI
		switch d[i].routeFamily {
		case bgp.RF_FS_IPv4_UC:
			s = &d[i].nlri.(*bgp.FlowSpecIPv4Unicast).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecIPv4Unicast).FlowSpecNLRI
		case bgp.RF_FS_IPv6_UC:
			s = &d[i].nlri.(*bgp.FlowSpecIPv6Unicast).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecIPv6Unicast).FlowSpecNLRI
		case bgp.RF_FS_IPv4_VPN:
			s = &d[i].nlri.(*bgp.FlowSpecIPv4VPN).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecIPv4VPN).FlowSpecNLRI
		case bgp.RF_FS_IPv6_VPN:
			s = &d[i].nlri.(*bgp.FlowSpecIPv6VPN).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecIPv6VPN).FlowSpecNLRI
		case bgp.RF_FS_L2_VPN:
			s = &d[i].nlri.(*bgp.FlowSpecL2VPN).FlowSpecNLRI
			t = &d[j].nlri.(*bgp.FlowSpecL2VPN).FlowSpecNLRI
		}
		if r, _ := bgp.CompareFlowSpecNLRI(s, t); r >= 0 {
			return true
		} else {
			return false
		}
	default:
		strings := sort.StringSlice{d[i].nlri.String(), d[j].nlri.String()}
		return strings.Less(0, 1)
	}
}
开发者ID:osrg,项目名称:gobgp,代码行数:31,代码来源:destination.go

示例14: SortedStringHas

func SortedStringHas(s sort.StringSlice, x string) bool {
	index := s.Search(x)
	if index == len(s) {
		return false
	}
	return s[s.Search(x)] == x
}
开发者ID:gaurav36,项目名称:heketi,代码行数:7,代码来源:sortedstrings.go

示例15: generalHelp

func generalHelp() {
	out := tabwriter.NewWriter(os.Stderr, 0, 8, 1, '\t', 0)
	exe := filepath.Base(os.Args[0])
	fmt.Fprintf(out, "USAGE:\n\t%s [global options] <command> [command options] [arguments...]\n\n", exe)
	fmt.Fprintf(out, "VERSION:\n\t%s\n\n", Version)

	fmt.Fprintf(out, "COMMANDS:\n")
	names := sort.StringSlice{}
	for name, _ := range subcommands {
		names = append(names, name)
	}
	names.Sort()
	for _, name := range names {
		cmd := subcommands[name]
		fmt.Fprintf(out, "\t%s\t%s\n", name, cmd.desc())
	}
	fmt.Fprintln(out)

	fmt.Fprintf(out, "GLOBAL OPTIONS:\n")
	flag.VisitAll(func(f *flag.Flag) {
		prefix := "-"
		if len(f.Name) > 1 {
			prefix = "--"
		}
		fmt.Fprintf(out, "\t%s%s=%s\t%s\n", prefix, f.Name, f.DefValue, f.Usage)
	})

	fmt.Fprintln(out)
	fmt.Fprintf(out, "Run \"%s help <command>\" for more details about a command.\n", exe)
}
开发者ID:logan,项目名称:heim,代码行数:30,代码来源:subcommands.go


注:本文中的sort.StringSlice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。