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


Golang strings.TrimPrefix函数代码示例

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


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

示例1: Run

func (cmd *cmdBreakfast) Run(title, from, text string) error {
	var err error

	if strings.HasPrefix(text, "!b-") {
		bfText := strings.TrimSpace(strings.TrimPrefix(text, "!b-"))
		if bfText == "" {
			// !b-: Reset list
			err = cmd.listReset(title)
		} else {
			// !b- n: Remove item n
			err = cmd.removeItem(title, bfText)
		}
	} else {
		bfText := strings.TrimSpace(strings.TrimPrefix(text, "!b"))
		if bfText == "" {
			// !b: List
			err = cmd.listItems(title)
		} else {
			// !b item: Add item to the list
			err = cmd.addItem(title, from, bfText)
		}
	}
	if err != nil {
		fmt.Fprintf(cmd.w, "msg %v error: cannot get or add items\n", title)
		return err
	}
	return nil
}
开发者ID:sergiodmn,项目名称:tgbot,代码行数:28,代码来源:breakfast.go

示例2: iomPreprocessor

// walk every arg looking for "file:" and calling iomHelper on the suffix.
// Replace the arg with the local file if found.
func iomPreprocessor(c *minicli.Command) (*minicli.Command, error) {
	for k, v := range c.StringArgs {
		if strings.HasPrefix(v, IOM_HELPER_MATCH) {
			file := strings.TrimPrefix(v, IOM_HELPER_MATCH)
			local, err := iomHelper(file)
			if err != nil {
				return nil, err
			}
			log.Debug("iomPreProcessor: %v -> %v", v, local)
			c.StringArgs[k] = local
		}
	}
	for k, v := range c.ListArgs {
		for x, y := range v {
			if strings.HasPrefix(y, IOM_HELPER_MATCH) {
				file := strings.TrimPrefix(y, IOM_HELPER_MATCH)
				local, err := iomHelper(file)
				if err != nil {
					return nil, err
				}
				log.Debug("iomPreProcessor: %v -> %v", y, local)
				c.ListArgs[k][x] = local
			}
		}
	}
	return c, nil
}
开发者ID:jenareljam,项目名称:minimega,代码行数:29,代码来源:iomeshage.go

示例3: aliasExpand

// aliasExpand expands aliased (name:/path) to full URL, used by url-parser
func aliasExpand(aliasedURL string, aliases map[string]string) (newURL string, err error) {
	u, err := client.Parse(aliasedURL)
	if err != nil {
		return aliasedURL, iodine.New(errInvalidURL{URL: aliasedURL}, nil)
	}
	// proper URL
	if u.Host != "" {
		return aliasedURL, nil
	}
	for aliasName, expandedURL := range aliases {
		if strings.HasPrefix(aliasedURL, aliasName+":") {
			// Match found. Expand it.
			splits := strings.Split(aliasedURL, ":")
			// if expandedURL is missing, return aliasedURL treat it like fs
			if expandedURL == "" {
				return aliasedURL, nil
			}
			// if more splits found return
			if len(splits) == 2 {
				// remove any prefixed slashes
				trimmedURL := expandedURL + "/" + strings.TrimPrefix(strings.TrimPrefix(splits[1], "/"), "\\")
				u, err := client.Parse(trimmedURL)
				if err != nil {
					return aliasedURL, iodine.New(errInvalidURL{URL: aliasedURL}, nil)
				}
				return u.String(), nil
			}
			return aliasedURL, nil
		}
	}
	return aliasedURL, nil
}
开发者ID:Pragatheesh,项目名称:mc,代码行数:33,代码来源:aliases.go

示例4: pathToKey

// pathToKey translates etcd key paths into something more suitable for use
// in Golang templates. Turn /prefix/key/subkey into key_subkey.
func pathToKey(key, prefix string) string {
	prefix = strings.TrimPrefix(prefix, "/")
	key = strings.TrimPrefix(key, "/")
	key = strings.TrimPrefix(key, prefix)
	key = strings.TrimPrefix(key, "/")
	return replacer.Replace(key)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:9,代码来源:util.go

示例5: lookUpNamespace

func lookUpNamespace(type_, currentNs string) string {
	//Embeddeds or extends are often times empty
	if type_ == "" {
		return type_
	}

	var prefix string
	if type_[0:1] == "*" {
		prefix = "*"
		type_ = type_[1:]
	} else if type_[0:3] == "[]*" {
		prefix = "[]*"
		type_ = type_[3:]
	} else if type_[0:2] == "[]" {
		prefix = "[]"
		type_ = type_[2:]
	}

	//strips out package name if it has it
	type_ = strings.TrimPrefix(type_, "mo.")
	type_ = strings.TrimPrefix(type_, "do.")
	type_ = strings.TrimPrefix(type_, "fault.")
	type_ = strings.TrimPrefix(type_, "enum.")

	targetNs := objnsmap[type_]
	if targetNs == "" || targetNs != "enum" || targetNs == currentNs {
		return prefix + type_
	}

	return prefix + targetNs + "." + type_
}
开发者ID:hooklift,项目名称:govsphere,代码行数:31,代码来源:generator.go

示例6: NewRequest

// NewRequest creates a new raw request object to query the Vault server
// configured for this client. This is an advanced method and generally
// doesn't need to be called externally.
func (c *Client) NewRequest(method, path string) *Request {
	req := &Request{
		Method: method,
		URL: &url.URL{
			Scheme: c.addr.Scheme,
			Host:   c.addr.Host,
			Path:   path,
		},
		ClientToken: c.token,
		Params:      make(map[string][]string),
	}

	var lookupPath string
	switch {
	case strings.HasPrefix(path, "/v1/"):
		lookupPath = strings.TrimPrefix(path, "/v1/")
	case strings.HasPrefix(path, "v1/"):
		lookupPath = strings.TrimPrefix(path, "v1/")
	default:
		lookupPath = path
	}
	if c.wrappingLookupFunc != nil {
		req.WrapTTL = c.wrappingLookupFunc(method, lookupPath)
	} else {
		req.WrapTTL = DefaultWrappingLookupFunc(method, lookupPath)
	}

	return req
}
开发者ID:rnaveiras,项目名称:vault,代码行数:32,代码来源:client.go

示例7: parseHost

// based off of https://github.com/dotcloud/docker/blob/2a711d16e05b69328f2636f88f8eac035477f7e4/utils/utils.go
func parseHost(addr string) (string, string, error) {

	var (
		proto string
		host  string
		port  int
	)
	addr = strings.TrimSpace(addr)
	switch {
	case addr == "tcp://":
		return "", "", fmt.Errorf("Invalid bind address format: %s", addr)
	case strings.HasPrefix(addr, "unix://"):
		proto = "unix"
		addr = strings.TrimPrefix(addr, "unix://")
		if addr == "" {
			addr = "/var/run/docker.sock"
		}
	case strings.HasPrefix(addr, "tcp://"):
		proto = "tcp"
		addr = strings.TrimPrefix(addr, "tcp://")
	case strings.HasPrefix(addr, "fd://"):
		return "fd", addr, nil
	case addr == "":
		proto = "unix"
		addr = "/var/run/docker.sock"
	default:
		if strings.Contains(addr, "://") {
			return "", "", fmt.Errorf("Invalid bind address protocol: %s", addr)
		}
		proto = "tcp"
	}

	if proto != "unix" && strings.Contains(addr, ":") {
		hostParts := strings.Split(addr, ":")
		if len(hostParts) != 2 {
			return "", "", fmt.Errorf("Invalid bind address format: %s", addr)
		}
		if hostParts[0] != "" {
			host = hostParts[0]
		} else {
			host = "127.0.0.1"
		}

		if p, err := strconv.Atoi(hostParts[1]); err == nil && p != 0 {
			port = p
		} else {
			return "", "", fmt.Errorf("Invalid bind address format: %s", addr)
		}

	} else if proto == "tcp" && !strings.Contains(addr, ":") {
		return "", "", fmt.Errorf("Invalid bind address format: %s", addr)
	} else {
		host = addr
	}
	if proto == "unix" {
		return proto, host, nil

	}
	return proto, fmt.Sprintf("%s:%d", host, port), nil
}
开发者ID:cretzel,项目名称:docker-gen,代码行数:61,代码来源:docker_client.go

示例8: Add

// Add adds a pattern and associated value to the matcher.
func (m *Matcher) Add(pattern string, v interface{}) error {
	if strings.HasPrefix(pattern, ExactPrefix) {
		s := strings.TrimPrefix(pattern, ExactPrefix)
		m.exact[s] = v
		return nil
	}
	if strings.HasPrefix(pattern, RegexPrefix) {
		s := strings.TrimPrefix(pattern, RegexPrefix)
		re, err := regexp.Compile(s)
		if err != nil {
			return err
		}
		m.regex = append(m.regex, struct {
			re *regexp.Regexp
			v  interface{}
		}{
			re: re,
			v:  v,
		})
		return nil
	}
	if strings.HasPrefix(pattern, SkipPrefix) {
		s := strings.TrimPrefix(pattern, SkipPrefix)
		m.trie.Add(s, &skipMatcher{
			pattern: pattern,
			v:       v,
		})
		return nil
	}
	m.trie.Add(pattern, v)
	return nil
}
开发者ID:fanyang01,项目名称:crawler,代码行数:33,代码来源:mux.go

示例9: Strip

// Strip ...
func Strip(str string) string {
	dirty := true
	strippedStr := str
	for dirty {
		hasWhiteSpacePrefix := false
		if strings.HasPrefix(strippedStr, " ") {
			hasWhiteSpacePrefix = true
			strippedStr = strings.TrimPrefix(strippedStr, " ")
		}

		hasWhiteSpaceSuffix := false
		if strings.HasSuffix(strippedStr, " ") {
			hasWhiteSpaceSuffix = true
			strippedStr = strings.TrimSuffix(strippedStr, " ")
		}

		hasNewlinePrefix := false
		if strings.HasPrefix(strippedStr, "\n") {
			hasNewlinePrefix = true
			strippedStr = strings.TrimPrefix(strippedStr, "\n")
		}

		hasNewlineSuffix := false
		if strings.HasSuffix(strippedStr, "\n") {
			hasNewlinePrefix = true
			strippedStr = strings.TrimSuffix(strippedStr, "\n")
		}

		if !hasWhiteSpacePrefix && !hasWhiteSpaceSuffix && !hasNewlinePrefix && !hasNewlineSuffix {
			dirty = false
		}
	}
	return strippedStr
}
开发者ID:bitrise-tools,项目名称:releaseman,代码行数:35,代码来源:command.go

示例10: usrParse

func usrParse(usrStr string) (err error) {
	switch {
	default:
		err = client.Call("Receiver.SendMsg", Args{Token, usrStr}, nil)
	case strings.HasPrefix(usrStr, COMM_CREATEROOM):
		cName := strings.TrimSuffix(strings.TrimPrefix(usrStr, COMM_CREATEROOM+" "), "\n")
		err = client.Call("Receiver.CreateCRoom", Args{Token, cName}, nil)
	case strings.HasPrefix(usrStr, COMM_ENTERROOM):
		cName := strings.TrimSuffix(strings.TrimPrefix(usrStr, COMM_ENTERROOM+" "), "\n")
		err = client.Call("Receiver.JoinCRoom", Args{Token, cName}, nil)
	case strings.HasPrefix(usrStr, COMM_LEAVEROOM):
		err = client.Call("Receiver.LeaveCRoom", &Token, nil)
	case strings.HasPrefix(usrStr, COMM_LISTROOMS):
		err = client.Call("Receiver.ListCRooms", &Token, nil)
	case strings.HasPrefix(usrStr, COMM_HELPCHAT):
		fmt.Print(MESS_HELP)
	case strings.HasPrefix(usrStr, COMM_CHANGENAME):
		cName := strings.TrimSuffix(strings.TrimPrefix(usrStr, COMM_CHANGENAME+" "), "\n")
		err = client.Call("Receiver.ChangeName", Args{Token, cName}, nil)
	case strings.HasPrefix(usrStr, COMM_QUITCHAT):
		err = client.Call("Receiver.Quit", &Token, nil)
		waitG.Done()
	}
	//fmt.Print(err)
	return err
}
开发者ID:knames,项目名称:cmpt436chatCLIENT,代码行数:26,代码来源:main.go

示例11: TestCacheKeyFields

func TestCacheKeyFields(t *testing.T) {
	keyJSON, err := cacheKey(kapi.NewContext(), &authorizer.DefaultAuthorizationAttributes{})
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	keyMap := map[string]interface{}{}
	if err := json.Unmarshal([]byte(keyJSON), &keyMap); err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	keys := sets.NewString()
	for k := range keyMap {
		keys.Insert(strings.ToLower(k))
	}

	// These are results we don't expect to be in the cache key
	expectedMissingKeys := sets.NewString("requestattributes")

	attrType := reflect.TypeOf((*authorizer.AuthorizationAttributes)(nil)).Elem()
	for i := 0; i < attrType.NumMethod(); i++ {
		name := attrType.Method(i).Name
		name = strings.TrimPrefix(name, "Get")
		name = strings.TrimPrefix(name, "Is")
		name = strings.ToLower(name)
		if !keys.Has(name) && !expectedMissingKeys.Has(name) {
			t.Errorf("computed cache is missing an entry for %s", attrType.Method(i).Name)
		}
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:28,代码来源:authorizer_test.go

示例12: GetHostFromUrl

// GetHostFromUrl extracts the host from an URL.
// Local file urls starting with 'file://' are skipped.
func GetHostFromUrl(url string) string {
	url = strings.TrimSpace(url)

	// Skip if this is a local file url.
	if strings.HasPrefix(url, "file://") {
		return url
	}

	if strings.HasPrefix(url, "http://") {
		url = strings.TrimPrefix(url, "http://")
	} else if strings.HasPrefix(url, "https://") {
		url = strings.TrimPrefix(url, "https://")
	} else if strings.HasPrefix(url, "[email protected]") {
		url = strings.TrimPrefix(url, "[email protected]")
	}

	// Remove everything after the first slash.
	pos := strings.Index(url, "/")
	if pos >= 0 {
		url = url[:pos]
	}

	// Remove everything after the ':'.
	// This is important for git urls.
	pos = strings.Index(url, ":")
	if pos >= 0 {
		url = url[:pos]
	}

	return url
}
开发者ID:gitter-badger,项目名称:turtle,代码行数:33,代码来源:net.go

示例13: getFileSummary

func getFileSummary(filename, dir, cmd, out string) (FileSummary, error) {
	filename = strings.TrimPrefix(filename, "repos/src")
	githubLink := strings.TrimPrefix(dir, "repos/src")
	fileURL := "https://" + strings.TrimPrefix(dir, "repos/src/") + "/blob/master" + strings.TrimPrefix(filename, githubLink)
	fs := FileSummary{
		Filename: filename,
		FileURL:  fileURL,
	}
	split := strings.Split(string(out), "\n")
	for _, sp := range split[0 : len(split)-1] {
		parts := strings.Split(sp, ":")
		msg := sp
		if cmd != "gocyclo" {
			msg = parts[len(parts)-1]
		}
		e := Error{ErrorString: msg}
		switch cmd {
		case "golint", "gocyclo", "vet":
			ln, err := strconv.Atoi(strings.Split(sp, ":")[1])
			if err != nil {
				return fs, err
			}
			e.LineNumber = ln
		}

		fs.Errors = append(fs.Errors, e)
	}

	return fs, nil
}
开发者ID:prasus,项目名称:go_report,代码行数:30,代码来源:utils.go

示例14: uri

func uri(workdir, fn string) string {
	u := fn
	u = strings.TrimPrefix(u, path.Join(workdir, "markdowns"))
	u = strings.TrimPrefix(u, path.Join(workdir, "templates"))
	u = strings.TrimPrefix(u, path.Join(workdir, "statics"))
	return u
}
开发者ID:h2object,项目名称:h2object,代码行数:7,代码来源:deploy.go

示例15: simpleImporter

func simpleImporter(imports map[string]*ast.Object, path string) (*ast.Object, error) {
	pkg := imports[path]
	if pkg == nil {
		// Guess the package name without importing it. Start with the last
		// element of the path.
		name := path[strings.LastIndex(path, "/")+1:]

		// Trim commonly used prefixes and suffixes containing illegal name
		// runes.
		name = strings.TrimSuffix(name, ".go")
		name = strings.TrimSuffix(name, "-go")
		name = strings.TrimPrefix(name, "go.")
		name = strings.TrimPrefix(name, "go-")
		name = strings.TrimPrefix(name, "biogo.")

		// It's also common for the last element of the path to contain an
		// extra "go" prefix, but not always. TODO: examine unresolved ids to
		// detect when trimming the "go" prefix is appropriate.

		pkg = ast.NewObj(ast.Pkg, name)
		pkg.Data = ast.NewScope(nil)
		imports[path] = pkg
	}
	return pkg, nil
}
开发者ID:Linvas,项目名称:ant,代码行数:25,代码来源:autorouter.go


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