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


Golang strings.HasSuffix函数代码示例

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


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

示例1: removeTrailingSlash

func removeTrailingSlash(u *url.URL) {
	if l := len(u.Path); l > 0 && strings.HasSuffix(u.Path, "/") {
		u.Path = u.Path[:l-1]
	} else if l = len(u.Host); l > 0 && strings.HasSuffix(u.Host, "/") {
		u.Host = u.Host[:l-1]
	}
}
开发者ID:rogpeppe,项目名称:purell,代码行数:7,代码来源:purell.go

示例2: addTrailingSlash

func addTrailingSlash(u *url.URL) {
	if l := len(u.Path); l > 0 && !strings.HasSuffix(u.Path, "/") {
		u.Path += "/"
	} else if l = len(u.Host); l > 0 && !strings.HasSuffix(u.Host, "/") {
		u.Host += "/"
	}
}
开发者ID:rogpeppe,项目名称:purell,代码行数:7,代码来源:purell.go

示例3: TestSanitizeURL

func TestSanitizeURL(t *testing.T) {
	tests := []struct {
		input    string
		expected string
	}{
		{"http://foo.bar/", "http://foo.bar"},
		{"http://foo.bar", "http://foo.bar"},          // issue #1105
		{"http://foo.bar/zoo/", "http://foo.bar/zoo"}, // issue #931
	}

	for i, test := range tests {
		o1 := SanitizeURL(test.input)
		o2 := SanitizeURLKeepTrailingSlash(test.input)

		expected2 := test.expected

		if strings.HasSuffix(test.input, "/") && !strings.HasSuffix(expected2, "/") {
			expected2 += "/"
		}

		if o1 != test.expected {
			t.Errorf("[%d] 1: Expected %#v, got %#v\n", i, test.expected, o1)
		}
		if o2 != expected2 {
			t.Errorf("[%d] 2: Expected %#v, got %#v\n", i, expected2, o2)
		}
	}
}
开发者ID:CODECOMMUNITY,项目名称:hugo,代码行数:28,代码来源:url_test.go

示例4: ConfigKeyChecker

// ConfigKeyChecker returns a function that will check whether or not
// a provide value is valid for the associate config key.  Returns an
// error if the key is not known.  The checker function only performs
// syntactic checking of the value, semantic and usage checking must
// be done by the caller.  User defined keys are always considered to
// be valid, e.g. user.* and environment.* keys.
func ConfigKeyChecker(key string) (func(value string) error, error) {
	if f, ok := KnownContainerConfigKeys[key]; ok {
		return f, nil
	}

	if strings.HasPrefix(key, "volatile.") {
		if strings.HasSuffix(key, ".hwaddr") {
			return IsAny, nil
		}

		if strings.HasSuffix(key, ".name") {
			return IsAny, nil
		}
	}

	if strings.HasPrefix(key, "environment.") {
		return IsAny, nil
	}

	if strings.HasPrefix(key, "user.") {
		return IsAny, nil
	}

	if strings.HasPrefix(key, "image.") {
		return IsAny, nil
	}

	return nil, fmt.Errorf("Bad key: %s", key)
}
开发者ID:akshaykarle,项目名称:lxd,代码行数:35,代码来源:container.go

示例5: init

func init() {
	dir, err := ioutil.TempDir("", "index_pack")
	if err != nil {
		panic(fmt.Sprintf("unable to create temp directory: %v", err))
	}
	tempDir = dir

	// Populate required inputs and source files for the test compilations.
	for _, unit := range testUnits {
		for path, data := range testFiles {
			unit.RequiredInput = append(unit.RequiredInput, &cpb.CompilationUnit_FileInput{
				Info: &cpb.FileInfo{
					Path:   path,
					Digest: hexDigest([]byte(data)),
				},
			})
			switch unit.VName.Language {
			case "go":
				if strings.HasSuffix(path, ".go") {
					unit.SourceFile = append(unit.SourceFile, path)
				}
			case "java":
				if strings.HasSuffix(path, ".java") {
					unit.SourceFile = append(unit.SourceFile, path)
				}
			}
		}
	}
}
开发者ID:herberteuler,项目名称:kythe,代码行数:29,代码来源:indexpack_test.go

示例6: handlePTRQuery

func (r *resolver) handlePTRQuery(ptr string, query *dns.Msg) (*dns.Msg, error) {
	parts := []string{}

	if strings.HasSuffix(ptr, ptrIPv4domain) {
		parts = strings.Split(ptr, ptrIPv4domain)
	} else if strings.HasSuffix(ptr, ptrIPv6domain) {
		parts = strings.Split(ptr, ptrIPv6domain)
	} else {
		return nil, fmt.Errorf("invalid PTR query, %v", ptr)
	}

	host := r.backend.ResolveIP(parts[0])

	if len(host) == 0 {
		return nil, nil
	}

	logrus.Debugf("Lookup for IP %s: name %s", parts[0], host)
	fqdn := dns.Fqdn(host)

	resp := new(dns.Msg)
	resp.SetReply(query)
	setCommonFlags(resp)

	rr := new(dns.PTR)
	rr.Hdr = dns.RR_Header{Name: ptr, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: respTTL}
	rr.Ptr = fqdn
	resp.Answer = append(resp.Answer, rr)
	return resp, nil
}
开发者ID:jwhonce,项目名称:docker,代码行数:30,代码来源:resolver.go

示例7: ResourceAliases

// ResourceAliases returns the resource shortcuts and plural forms for the given resources.
func ResourceAliases(rs []string) []string {
	as := make([]string, 0, len(rs))
	plurals := make(map[string]struct{}, len(rs))
	for _, r := range rs {
		var plural string
		switch {
		case r == "endpoints":
			plural = r // exception. "endpoint" does not exist. Why?
		case strings.HasSuffix(r, "y"):
			plural = r[0:len(r)-1] + "ies"
		case strings.HasSuffix(r, "s"):
			plural = r + "es"
		default:
			plural = r + "s"
		}
		as = append(as, plural)

		plurals[plural] = struct{}{}
	}

	for sf, r := range shortForms {
		if _, found := plurals[r]; found {
			as = append(as, sf)
		}
	}
	return as
}
开发者ID:digitalfishpond,项目名称:dashboard,代码行数:28,代码来源:kubectl.go

示例8: makeGoMethod

func makeGoMethod(fun *CFunc, class *Class, name string) *BridgeFunc {
	gofunc := new(BridgeFunc)
	gofunc.CFunc = fun
	gofunc.Receiver = "*" + class.Name
	gofunc.Name = name
	gofunc.CgoArguments = append(gofunc.CgoArguments, "self.obj")
	if len(fun.ParamNames) > 1 {
		for i, paramName := range fun.ParamNames[1:] {
			paramType := fun.ParamTypes[i+1]
			if strings.HasSuffix(paramType, "_Cb") || paramName == "cb" { // does not support callback type
				return nil
			}
			if NOT_SUPPORTED_TYPES.Has(paramType) {
				return nil
			}
			if _, has := RETURN_PARAM_MAPPINGS[paramType]; (strings.HasSuffix(fun.Name, "_get") || FUNCS_WITH_RETURN_PARAM.Has(fun.Name)) && has { // return params
				gofunc.ConvertReturnParam(paramName, paramType)
			} else {
				gofunc.ConvertParam(paramName, paramType)
			}
		}
	}
	if NOT_SUPPORTED_TYPES.Has(fun.ReturnType) {
		return nil
	}
	if fun.ReturnType != "void" {
		gofunc.ConvertReturnType(fun.ReturnType)
	}
	gofunc.CgoFunc = fun.Name
	return gofunc
}
开发者ID:reusee,项目名称:elementary-go,代码行数:31,代码来源:methods.go

示例9: fileExtImpliesText

func fileExtImpliesText(ext string) (yes, unknown bool) {
	defer func() {
		glog.V(2).Infof("'%s' -> yes=%v   unknown=%v", ext, yes, unknown)
	}()

	if ext == "" {
		unknown = true
		return
	}
	mt := mime.TypeByExtension(ext)
	if strings.HasPrefix(mt, "text/") ||
		strings.HasSuffix(mt, "+xml") ||
		strings.HasSuffix(mt, ".json") ||
		strings.HasSuffix(mt, "+json") {
		// Most likely text.
		yes = true
		glog.V(1).Infof("Most likely a text extension: %s", ext)
		return
	}
	if strings.HasPrefix(mt, "audio/") ||
		strings.HasPrefix(mt, "image/") ||
		strings.HasPrefix(mt, "video/") {
		// Almost certainly not text.
		glog.V(1).Infof("Most likely a binary extension: %s", ext)
		return
	}
	unknown = true
	return
}
开发者ID:zlongshen,项目名称:diffmerge,代码行数:29,代码来源:measure_indent.go

示例10: assertGetImageMetadataSources

func (s *localServerSuite) assertGetImageMetadataSources(c *gc.C, stream, officialSourcePath string) {
	// Create a config that matches s.TestConfig but with the specified stream.
	envAttrs := s.TestConfig
	if stream != "" {
		envAttrs = envAttrs.Merge(coretesting.Attrs{"image-stream": stream})
	}
	cfg, err := config.New(config.NoDefaults, envAttrs)
	c.Assert(err, gc.IsNil)
	env, err := environs.New(cfg)
	c.Assert(err, gc.IsNil)
	sources, err := imagemetadata.GetMetadataSources(env)
	c.Assert(err, gc.IsNil)
	c.Assert(sources, gc.HasLen, 4)
	var urls = make([]string, len(sources))
	for i, source := range sources {
		url, err := source.URL("")
		c.Assert(err, gc.IsNil)
		urls[i] = url
	}
	// The image-metadata-url ends with "/juju-dist-test/".
	c.Check(strings.HasSuffix(urls[0], "/juju-dist-test/"), jc.IsTrue)
	// The control bucket URL contains the bucket name.
	c.Check(strings.Contains(urls[1], openstack.ControlBucketName(env)+"/images"), jc.IsTrue)
	// The product-streams URL ends with "/imagemetadata".
	c.Check(strings.HasSuffix(urls[2], "/imagemetadata/"), jc.IsTrue)
	c.Assert(urls[3], gc.Equals, fmt.Sprintf("http://cloud-images.ubuntu.com/%s/", officialSourcePath))
}
开发者ID:klyachin,项目名称:juju,代码行数:27,代码来源:local_test.go

示例11: scanFolder

func scanFolder(url string) {
	doc, err := goquery.NewDocument(url)
	if err != nil {
		log.Fatal(err)
	}

	doc.Find("a").Each(func(i int, s *goquery.Selection) {
		href, _ := s.Attr("href")

		if strings.HasSuffix(href, ".zip") {
			c := pool.Borrow()
			go func() {
				defer pool.Return(c)
				filename := download(url, href)
				if filename != "" {
					process(filename)
				}
			}()
		}

		if !strings.HasPrefix(href, "/") && strings.HasSuffix(href, "/") {
			log.Printf("%+v", href)
			scanFolder(url + href)
		}
	})
}
开发者ID:marucreative,项目名称:untracked-mapgen-old,代码行数:26,代码来源:download.go

示例12: TestDirectToUnknownStateMember

func (s *S) TestDirectToUnknownStateMember(c *C) {
	session, err := mgo.Dial("localhost:40041?connect=direct")
	c.Assert(err, IsNil)
	defer session.Close()

	session.SetMode(mgo.Monotonic, true)

	result := &struct{ Host string }{}
	err = session.Run("serverStatus", result)
	c.Assert(err, IsNil)
	c.Assert(strings.HasSuffix(result.Host, ":40041"), Equals, true)

	// We've got no master, so it'll timeout.
	session.SetSyncTimeout(5e8 * time.Nanosecond)

	coll := session.DB("mydb").C("mycoll")
	err = coll.Insert(M{"test": 1})
	c.Assert(err, ErrorMatches, "no reachable servers")

	// Slave is still reachable.
	result.Host = ""
	err = session.Run("serverStatus", result)
	c.Assert(err, IsNil)
	c.Assert(strings.HasSuffix(result.Host, ":40041"), Equals, true)
}
开发者ID:Yogesh9692,项目名称:mgo,代码行数:25,代码来源:cluster_test.go

示例13: convertGlobs

func convertGlobs(patterns []string) (*regexp.Regexp, error) {
	if len(patterns) == 0 {
		return nil, nil
	}

	exprs := make([]string, len(patterns))
	for i, pattern := range patterns {
		var prefix, suffix string

		if strings.HasPrefix(pattern, "**/") {
			prefix = "(.+/)?"
			pattern = pattern[len("**/"):]
		}

		if strings.HasSuffix(pattern, "/") {
			suffix = "(/.+)?"
			pattern = pattern[:len(pattern)-len("/")]
		} else if strings.HasSuffix(pattern, "/**") {
			suffix = "(/.+)?"
			pattern = pattern[:len(pattern)-len("/**")]
		}

		exprs[i] = prefix + replacer.Replace(pattern) + suffix
	}
	return regexp.Compile(`\A(` + strings.Join(exprs, "|") + `)\z`)
}
开发者ID:hnakamur,项目名称:paths,代码行数:26,代码来源:matcher.go

示例14: parse_split

/**
 * parse split chars and return value
 */
func parse_split(split string) (id byte, value int, err error) {
	split = strings.ToLower(split)
	switch split {
	case "day":
		id, value = SPLIT_DAY, 1
	default:
		if strings.HasSuffix(split, "hour") {
			id = SPLIT_HOUR
			value, err = strconv.Atoi(strings.TrimSuffix(split, "hour"))
			//fix illegal hour
			if err == nil && (value < 1 || value > 23) {
				value = 1
			}
		} else if strings.HasSuffix(split, "min") {
			id = SPLIT_MIN
			value, err = strconv.Atoi(strings.TrimSuffix(split, "min"))
			//fix illegal minute
			if err == nil && (value > 60 || value < 5) {
				value = 5
			}
		} else if strings.HasSuffix(split, "m") {
			id = SPLIT_SIZE
			value, err = strconv.Atoi(strings.TrimSuffix(split, "m"))
			//fix illegal size
			if err == nil && value < 1 {
				value = 1
			}
		} else {
			err = errors.New("unknow split")
		}
	}
	return
}
开发者ID:miffa,项目名称:glog-1,代码行数:36,代码来源:glog.go

示例15: parseSpeed

func parseSpeed(s string) (float32, bool) {
	var times float64 = 1
	s = strings.ToLower(s)
	if strings.HasSuffix(s, "/s") {
		s = s[:len(s)-2]
	}

	if strings.HasSuffix(s, "b") {
		s = s[:len(s)-1]
	}

	if strings.HasSuffix(s, "g") {
		s = s[:len(s)-1]
		times = 1024 * 1024 * 1024
	} else if strings.HasSuffix(s, "m") {
		s = s[:len(s)-1]
		times = 1024 * 1024
	} else if strings.HasSuffix(s, "k") {
		s = s[:len(s)-1]
		times = 1024
	}

	f, err := strconv.ParseFloat(s, 32)
	if err != nil {
		return -1, false
	} else {
		return float32(f * times), true
	}
}
开发者ID:clarelin,项目名称:asuran,代码行数:29,代码来源:cmd.go


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