本文整理汇总了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
}
示例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())
}
示例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
}
示例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
}
示例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)
}
示例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()
}
示例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
}
}
示例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
}
示例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), "")
}
}
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
}