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


Golang strings.ToLower函数代码示例

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


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

示例1: isWatching

func isWatching(channel string, name string) bool {
	chanName := strings.Replace(channel, "#", "", 1)
	url := "http://tmi.twitch.tv/group/user/" + chanName + "/chatters"
	response, err := http.Get(url)
	if err != nil {
		log.Fatalf("Cannot get URL response: %s\n", err.Error())
	}
	defer response.Body.Close()
	data, err := ioutil.ReadAll(response.Body)
	if err != nil {
		log.Fatalf("Cannot read URL response: %s\n", err.Error())
	}
	var parsed map[string]interface{}
	p := json.Unmarshal(data, &parsed)
	if p != nil {
		log.Fatalf("Parse error: %s\n", err.Error())
	}
	chats := parsed["chatters"].(map[string]interface{})
	views := chats["viewers"].([]interface{})
	mods := chats["moderators"].([]interface{})
	for _, b := range views {
		if b == strings.ToLower(name) {
			return true
		}
	}
	for _, b := range mods {
		if b == strings.ToLower(name) {
			return true
		}
	}
	return false
}
开发者ID:carriercomm,项目名称:mariomaker-twitch,代码行数:32,代码来源:db.go

示例2: RealType

// RealType takes 'XmlName' and finds its real concrete type in our Protocol.
// It is an error if we can't find such a type.
func (t *Translation) RealType(p *Protocol) Type {
	// Check to see if there is a namespace. If so, strip it and use it to
	// make sure we only look for a type in that protocol.
	namespace, typeName := "", t.XmlName()
	if ni := strings.Index(t.XmlName(), ":"); ni > -1 {
		namespace, typeName = strings.ToLower(typeName[:ni]), typeName[ni+1:]
	}

	if len(namespace) == 0 || namespace == strings.ToLower(p.Name) {
		for _, typ := range p.Types {
			if typeName == typ.XmlName() {
				return typ
			}
		}
	}
	for _, imp := range p.Imports {
		if len(namespace) == 0 || namespace == strings.ToLower(imp.Name) {
			for _, typ := range imp.Types {
				if typeName == typ.XmlName() {
					return typ
				}
			}
		}
	}
	panic("Could not find real type for translation type: " + t.XmlName())
}
开发者ID:rjmcguire,项目名称:xgb,代码行数:28,代码来源:type.go

示例3: KindToResource

// KindToResource converts Kind to a resource name.
func KindToResource(kind unversioned.GroupVersionKind, mixedCase bool) (plural, singular unversioned.GroupVersionResource) {
	kindName := kind.Kind
	if len(kindName) == 0 {
		return
	}
	if mixedCase {
		// Legacy support for mixed case names
		singular = kind.GroupVersion().WithResource(strings.ToLower(kindName[:1]) + kindName[1:])
	} else {
		singular = kind.GroupVersion().WithResource(strings.ToLower(kindName))
	}

	singularName := singular.Resource
	if strings.HasSuffix(singularName, "endpoints") || strings.HasSuffix(singularName, "securitycontextconstraints") {
		plural = singular
	} else {
		switch string(singularName[len(singularName)-1]) {
		case "s":
			plural = kind.GroupVersion().WithResource(singularName + "es")
		case "y":
			plural = kind.GroupVersion().WithResource(strings.TrimSuffix(singularName, "y") + "ies")
		default:
			plural = kind.GroupVersion().WithResource(singularName + "s")
		}
	}
	return
}
开发者ID:jfcoz,项目名称:origin,代码行数:28,代码来源:restmapper.go

示例4: isTreamCreationAllowed

func isTreamCreationAllowed(c *Context, email string) bool {

	email = strings.ToLower(email)

	if utils.Cfg.TeamSettings.DisableTeamCreation {
		c.Err = model.NewAppError("isTreamCreationAllowed", "Team creation has been disabled. Please ask your systems administrator for details.", "")
		return false
	}

	// commas and @ signs are optional
	// can be in the form of "@corp.mattermost.com, mattermost.com mattermost.org" -> corp.mattermost.com mattermost.com mattermost.org
	domains := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(utils.Cfg.TeamSettings.RestrictCreationToDomains, "@", " ", -1), ",", " ", -1))))

	matched := false
	for _, d := range domains {
		if strings.HasSuffix(email, "@"+d) {
			matched = true
			break
		}
	}

	if len(utils.Cfg.TeamSettings.RestrictCreationToDomains) > 0 && !matched {
		c.Err = model.NewAppError("isTreamCreationAllowed", "Email must be from a specific domain (e.g. @example.com). Please ask your systems administrator for details.", "")
		return false
	}

	return true
}
开发者ID:narita-takeru,项目名称:platform,代码行数:28,代码来源:team.go

示例5: NewConnection

// NewConnection validates the upgrade response, creating and returning a new
// httpstream.Connection if there were no errors.
func (s *SpdyRoundTripper) NewConnection(resp *http.Response) (httpstream.Connection, error) {
	connectionHeader := strings.ToLower(resp.Header.Get(httpstream.HeaderConnection))
	upgradeHeader := strings.ToLower(resp.Header.Get(httpstream.HeaderUpgrade))
	if (resp.StatusCode != http.StatusSwitchingProtocols) || !strings.Contains(connectionHeader, strings.ToLower(httpstream.HeaderUpgrade)) || !strings.Contains(upgradeHeader, strings.ToLower(HeaderSpdy31)) {
		defer resp.Body.Close()
		responseError := ""
		responseErrorBytes, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			responseError = "unable to read error from server response"
		} else {
			// TODO: I don't belong here, I should be abstracted from this class
			if obj, _, err := api.Codecs.UniversalDecoder().Decode(responseErrorBytes, nil, &unversioned.Status{}); err == nil {
				if status, ok := obj.(*unversioned.Status); ok {
					return nil, &apierrors.StatusError{ErrStatus: *status}
				}
			}
			responseError = string(responseErrorBytes)
			responseError = strings.TrimSpace(responseError)
		}

		return nil, fmt.Errorf("unable to upgrade connection: %s", responseError)
	}

	return NewClientConnection(s.conn)
}
开发者ID:arvindkandhare,项目名称:kubernetes,代码行数:27,代码来源:roundtripper.go

示例6: Prepare

func (c *baseController) Prepare() {
	controllerName, actionName := c.GetControllerAndAction()
	c.controllerName = strings.ToLower(controllerName[0 : len(controllerName)-10])
	c.actionName = strings.ToLower(actionName)
	c.auth()
	// c.checkPermission()
}
开发者ID:Genffy,项目名称:api.genffy.com,代码行数:7,代码来源:base.go

示例7: searchMap

func (v *Viper) searchMap(source map[string]interface{}, path []string) interface{} {

	if len(path) == 0 {
		return source
	}

	var ok bool
	var next interface{}
	for k, v := range source {
		if strings.ToLower(k) == strings.ToLower(path[0]) {
			ok = true
			next = v
			break
		}
	}

	if ok {
		switch next.(type) {
		case map[interface{}]interface{}:
			return v.searchMap(cast.ToStringMap(next), path[1:])
		case map[string]interface{}:
			// Type assertion is safe here since it is only reached
			// if the type of `next` is the same as the type being asserted
			return v.searchMap(next.(map[string]interface{}), path[1:])
		default:
			return next
		}
	} else {
		return nil
	}
}
开发者ID:flowg,项目名称:SmallWorld,代码行数:31,代码来源:viper.go

示例8: groupByDateField

func (p Pages) groupByDateField(sorter func(p Pages) Pages, formatter func(p *Page) string, order ...string) (PagesGroup, error) {
	if len(p) < 1 {
		return nil, nil
	}

	sp := sorter(p)

	if !(len(order) > 0 && (strings.ToLower(order[0]) == "asc" || strings.ToLower(order[0]) == "rev" || strings.ToLower(order[0]) == "reverse")) {
		sp = sp.Reverse()
	}

	date := formatter(sp[0])
	var r []PageGroup
	r = append(r, PageGroup{Key: date, Pages: make(Pages, 0)})
	r[0].Pages = append(r[0].Pages, sp[0])

	i := 0
	for _, e := range sp[1:] {
		date = formatter(e)
		if r[i].Key.(string) != date {
			r = append(r, PageGroup{Key: date})
			i++
		}
		r[i].Pages = append(r[i].Pages, e)
	}
	return r, nil
}
开发者ID:XCMer,项目名称:hugo,代码行数:27,代码来源:pageGroup.go

示例9: processIdParam

func (statement *Statement) processIdParam() {

	if statement.IdParam != nil {
		i := 0
		colCnt := len(statement.RefTable.ColumnsSeq)
		for _, elem := range *(statement.IdParam) {
			for ; i < colCnt; i++ {
				colName := statement.RefTable.ColumnsSeq[i]
				col := statement.RefTable.Columns[strings.ToLower(colName)]
				if col.IsPrimaryKey {
					statement.And(fmt.Sprintf("%v=?", col.Name), elem)
					i++
					break
				}
			}
		}

		// !nashtsai! REVIEW what if statement.IdParam has insufficient pk item? handle it
		// as empty string for now, so this will result sql exec failed instead of unexpected
		// false update/delete
		for ; i < colCnt; i++ {
			colName := statement.RefTable.ColumnsSeq[i]
			col := statement.RefTable.Columns[strings.ToLower(colName)]
			if col.IsPrimaryKey {
				statement.And(fmt.Sprintf("%v=?", col.Name), "")
			}
		}
	}
}
开发者ID:matm,项目名称:gobuild,代码行数:29,代码来源:statement.go

示例10: Push

func (p *Filter) Push(k string) {
	partResult := make(ResultItemSlice, 0)
	s := "/"
	if runtime.GOOS == "windows" {
		s = "\\"
	}
	for _, v := range p.Results {
		if v.Index >= len(v.Line.Cs) {
			continue
		}
		l := v.Line.GetString()
		if config.GetConfig().FuzzyFindMode == config.NameMode && v.Index == 0 {
			li := strings.LastIndex(l, s)
			if li != -1 && li <= len(l)-1 {
				if li == len(l)-1 {
					v.Index = li
				} else {
					v.Index = li + 1
				}
			}
		}
		k = strings.ToLower(k)
		l = strings.ToLower(l[v.Index:])
		if strings.Contains(l, k) {
			v.Index += strings.Index(l, k) + len(k)
			partResult = append(partResult, v)
		}
	}
	if config.GetConfig().DirectoryMode == config.AllMode {
		sort.Sort(partResult)
	}
	p.Results = partResult
}
开发者ID:arkorsky,项目名称:dcd,代码行数:33,代码来源:filter.go

示例11: Delete

func (orm *Model) Delete(output interface{}) (int64, error) {
	defer orm.InitModel()
	orm.ScanPK(output)
	results, err := scanStructIntoMap(output)
	if err != nil {
		return 0, err
	}

	if orm.TableName == "" {
		orm.TableName = getTableName(StructName(output))
	}
	id := results[strings.ToLower(orm.PrimaryKey)]
	condition := fmt.Sprintf("%v%v%v='%v'", orm.QuoteIdentifier, strings.ToLower(orm.PrimaryKey), orm.QuoteIdentifier, id)
	statement := fmt.Sprintf("DELETE FROM %v%v%v WHERE %v",
		orm.QuoteIdentifier,
		orm.TableName,
		orm.QuoteIdentifier,
		condition)
	if OnDebug {
		fmt.Println(statement)
		fmt.Println(orm)
	}
	res, err := orm.Exec(statement)
	if err != nil {
		return -1, err
	}
	Affectid, err := res.RowsAffected()

	if err != nil {
		return -1, err
	}
	return Affectid, nil
}
开发者ID:scottcagno,项目名称:beedb,代码行数:33,代码来源:beedb.go

示例12: getParam

func (p *Page) getParam(key string, stringToLower bool) interface{} {
	v := p.Params[strings.ToLower(key)]

	if v == nil {
		return nil
	}

	switch v.(type) {
	case bool:
		return cast.ToBool(v)
	case string:
		if stringToLower {
			return strings.ToLower(cast.ToString(v))
		}
		return cast.ToString(v)
	case int64, int32, int16, int8, int:
		return cast.ToInt(v)
	case float64, float32:
		return cast.ToFloat64(v)
	case time.Time:
		return cast.ToTime(v)
	case []string:
		if stringToLower {
			return helpers.SliceToLower(v.([]string))
		}
		return v.([]string)
	case map[string]interface{}: // JSON and TOML
		return v
	case map[interface{}]interface{}: // YAML
		return v
	}

	jww.ERROR.Printf("GetParam(\"%s\"): Unknown type %s\n", key, reflect.TypeOf(v))
	return nil
}
开发者ID:JTrembl1,项目名称:hugo,代码行数:35,代码来源:page.go

示例13: newValidatorImpl

func newValidatorImpl(domains []string, usersFile string,
	done <-chan bool, onUpdate func()) func(string) bool {
	validUsers := NewUserMap(usersFile, done, onUpdate)

	var allowAll bool
	for i, domain := range domains {
		if domain == "*" {
			allowAll = true
			continue
		}
		domains[i] = fmt.Sprintf("@%s", strings.ToLower(domain))
	}

	validator := func(email string) bool {
		email = strings.ToLower(email)
		valid := false
		for _, domain := range domains {
			valid = valid || strings.HasSuffix(email, domain)
		}
		if !valid {
			valid = validUsers.IsValid(email)
		}
		if allowAll {
			valid = true
		}
		return valid
	}
	return validator
}
开发者ID:edhgoose,项目名称:oauth2_proxy,代码行数:29,代码来源:validator.go

示例14: showHelp

func (i *input) showHelp() {
	examples := make([]string, len(uiCommands))
	maxLen := 0

	for ix, cmd := range uiCommands {
		line := "/" + cmd.name
		prototype := reflect.TypeOf(cmd.prototype)
		for j := 0; j < prototype.NumField(); j++ {
			if strings.HasPrefix(string(prototype.Field(j).Tag), "flag:") {
				line += " [--" + strings.ToLower(string(prototype.Field(j).Tag[5:])) + "]"
			} else {
				line += " <" + strings.ToLower(prototype.Field(j).Name) + ">"
			}
		}
		if l := len(line); l > maxLen {
			maxLen = l
		}
		examples[ix] = line
	}

	for ix, cmd := range uiCommands {
		line := examples[ix]
		numSpaces := 1 + (maxLen - len(line))
		for j := 0; j < numSpaces; j++ {
			line += " "
		}
		line += cmd.desc
		info(i.term, i.tc, line)
	}
}
开发者ID:rosatolen,项目名称:coyim,代码行数:30,代码来源:input.go

示例15: newLogger

func newLogger(endpoint, strLevel, strFacility, tag string) EventLevelLogger {
	// figure priority
	level, err := stringToLevel(strLevel)

	if err != nil {
		panic("Initializing in ln logger: " + err.Error())
	}

	// figure out endpoint
	if strings.ToLower(endpoint) == "stderr" {
		// create a logger that writes to stderr, and we dont' care about the facility
		return newJSONLogger(newWriterLogger(os.Stderr, tag), level, -1)
	} else if strings.ToLower(endpoint) == "syslog" {
		facility, err := stringToFacility(strFacility)

		if err != nil {
			panic("Initializing in ln logger : " + err.Error())
		}

		syslogger := newBSyslogger(bsyslog.Priority(facility), tag)
		return newJSONLogger(syslogger, level, facility)
	} else {
		file, err := os.OpenFile(endpoint, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
		if err != nil {
			panic("Initializing ln logger: could not create endpoint " + endpoint + ", error: " + err.Error())
		}
		return newJSONLogger(newWriterLogger(file, tag), level, -1)
	}
}
开发者ID:john-cai,项目名称:tools,代码行数:29,代码来源:ln.go


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