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


Golang strings.EqualFold函数代码示例

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


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

示例1: lookdot0

// lookdot0 returns the number of fields or methods named s associated
// with Type t. If exactly one exists, it will be returned in *save
// (if save is not nil).
func lookdot0(s *Sym, t *Type, save **Field, ignorecase bool) int {
	u := t
	if u.IsPtr() {
		u = u.Elem()
	}

	c := 0
	if u.IsStruct() || u.IsInterface() {
		for _, f := range u.Fields().Slice() {
			if f.Sym == s || (ignorecase && f.Type.Etype == TFUNC && f.Type.Recv() != nil && strings.EqualFold(f.Sym.Name, s.Name)) {
				if save != nil {
					*save = f
				}
				c++
			}
		}
	}

	u = methtype(t, 0)
	if u != nil {
		for _, f := range u.Methods().Slice() {
			if f.Embedded == 0 && (f.Sym == s || (ignorecase && strings.EqualFold(f.Sym.Name, s.Name))) {
				if save != nil {
					*save = f
				}
				c++
			}
		}
	}

	return c
}
开发者ID:2thetop,项目名称:go,代码行数:35,代码来源:subr.go

示例2: TestParseServerInfo

func TestParseServerInfo(t *testing.T) {
	data := []byte{
		0xFF, 0xFF, 0xFF, 0xFF, 0x49, 0x11, 0x71, 0x6C, 0x2E, 0x73, 0x79, 0x6E,
		0x63, 0x6F, 0x72, 0x65, 0x2E, 0x6F, 0x72, 0x67, 0x20, 0x2D, 0x20, 0x55,
		0x53, 0x20, 0x43, 0x45, 0x4E, 0x54, 0x52, 0x41, 0x4C, 0x20, 0x23, 0x31,
		0x00, 0x74, 0x68, 0x75, 0x6E, 0x64, 0x65, 0x72, 0x73, 0x74, 0x72, 0x75,
		0x63, 0x6B, 0x00, 0x62, 0x61, 0x73, 0x65, 0x71, 0x33, 0x00, 0x43, 0x6C,
		0x61, 0x6E, 0x20, 0x41, 0x72, 0x65, 0x6E, 0x61, 0x00, 0x00, 0x00, 0x02,
		0x10, 0x00, 0x64, 0x6C, 0x00, 0x01, 0x31, 0x30, 0x36, 0x33, 0x00, 0xB1,
		0x38, 0x6D, 0x02, 0xF8, 0xC1, 0x4D, 0x7B, 0x17, 0x40, 0x01, 0x63, 0x6C,
		0x61, 0x6E, 0x61, 0x72, 0x65, 0x6E, 0x61, 0x2C, 0x73, 0x79, 0x6E, 0x63,
		0x6F, 0x72, 0x65, 0x2C, 0x74, 0x65, 0x78, 0x61, 0x73, 0x00, 0x48, 0x4F,
		0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
	sinfo, err := parseServerInfo(data)
	if err != nil {
		t.Fatalf("Unexpected error when parsing server info")
	}
	if !strings.EqualFold(sinfo.Name, "ql.syncore.org - US CENTRAL #1") {
		t.Fatalf("Expected server name: ql.syncore.org - US CENTRAL #1 got: %s",
			sinfo.Name)
	}
	if !strings.EqualFold(sinfo.Environment, "Linux") {
		t.Fatalf("Expected server environment: Linux got: %s",
			sinfo.Environment)
	}
	if sinfo.Players != 2 {
		t.Fatalf("Expected server to contain 2 players, got: %d", sinfo.Players)
	}
	if !strings.EqualFold(sinfo.Folder, "baseq3") {
		t.Fatalf("Expected server's game folder to be baseq3, got: %s", sinfo.Folder)
	}
}
开发者ID:syncore,项目名称:a2sapi,代码行数:34,代码来源:steaminfo_test.go

示例3: parseMetaGoImports

// parseMetaGoImports returns meta imports from the HTML in r.
// Parsing ends at the end of the <head> section or the beginning of the <body>.
func parseMetaGoImports(r io.Reader) (imports []metaImport) {
	d := xml.NewDecoder(r)
	d.Strict = false
	for {
		t, err := d.Token()
		if err != nil {
			return
		}
		if e, ok := t.(xml.StartElement); ok && strings.EqualFold(e.Name.Local, "body") {
			return
		}
		if e, ok := t.(xml.EndElement); ok && strings.EqualFold(e.Name.Local, "head") {
			return
		}
		e, ok := t.(xml.StartElement)
		if !ok || !strings.EqualFold(e.Name.Local, "meta") {
			continue
		}
		if attrValue(e.Attr, "name") != "go-import" {
			continue
		}
		if f := strings.Fields(attrValue(e.Attr, "content")); len(f) == 3 {
			imports = append(imports, metaImport{
				Prefix:   f[0],
				VCS:      f[1],
				RepoRoot: f[2],
			})
		}
	}
	return
}
开发者ID:blaggacao,项目名称:godoo,代码行数:33,代码来源:discovery.go

示例4: LoadEnv

func (c *Context) LoadEnv() (*rancherClient.Environment, error) {
	if c.Environment != nil {
		return c.Environment, nil
	}

	projectName := c.sanitizedProjectName()
	if _, err := c.loadClient(); err != nil {
		return nil, err
	}

	logrus.Debugf("Looking for stack %s", projectName)
	// First try by name
	envs, err := c.Client.Environment.List(&rancherClient.ListOpts{
		Filters: map[string]interface{}{
			"name":         projectName,
			"removed_null": nil,
		},
	})
	if err != nil {
		return nil, err
	}

	for _, env := range envs.Data {
		if strings.EqualFold(projectName, env.Name) {
			logrus.Debugf("Found stack: %s(%s)", env.Name, env.Id)
			c.Environment = &env
			return c.Environment, nil
		}
	}

	// Now try not by name for case sensitive databases
	envs, err = c.Client.Environment.List(&rancherClient.ListOpts{
		Filters: map[string]interface{}{
			"removed_null": nil,
		},
	})
	if err != nil {
		return nil, err
	}

	for _, env := range envs.Data {
		if strings.EqualFold(projectName, env.Name) {
			logrus.Debugf("Found stack: %s(%s)", env.Name, env.Id)
			c.Environment = &env
			return c.Environment, nil
		}
	}

	logrus.Infof("Creating stack %s", projectName)
	env, err := c.Client.Environment.Create(&rancherClient.Environment{
		Name: projectName,
	})
	if err != nil {
		return nil, err
	}

	c.Environment = env

	return c.Environment, nil
}
开发者ID:cloudnautique,项目名称:rancher-compose,代码行数:60,代码来源:context.go

示例5: Insert

func (c *CommandLine) Insert(stmt string) error {
	i, point := parseNextIdentifier(stmt)
	if !strings.EqualFold(i, "insert") {
		fmt.Printf("ERR: found %s, expected INSERT\n", i)
		return nil
	}
	if i, r := parseNextIdentifier(point); strings.EqualFold(i, "into") {
		point = c.parseInto(r)
	}
	_, err := c.Client.Write(client.BatchPoints{
		Points: []client.Point{
			client.Point{Raw: point},
		},
		Database:         c.Database,
		RetentionPolicy:  c.RetentionPolicy,
		Precision:        "n",
		WriteConsistency: c.WriteConsistency,
	})
	if err != nil {
		fmt.Printf("ERR: %s\n", err)
		if c.Database == "" {
			fmt.Println("Note: error may be due to not setting a database or retention policy.")
			fmt.Println(`Please set a database with the command "use <database>" or`)
			fmt.Println("INSERT INTO <database>.<retention-policy> <point>")
		}
		return err
	}
	return nil
}
开发者ID:ashanbrown,项目名称:influxdb,代码行数:29,代码来源:main.go

示例6: DecodeStrict

// DecodeStrict returns an error if env contains prefixed variables that do not
// correspond to either field names in v, or keys in ignoreEnv.
func (env Environment) DecodeStrict(prefix, sep string, v interface{},
	ignoreEnv map[string]interface{}) error {

	var fields []string
	if err := env.decode(prefix, sep, v, &fields); err != nil {
		return err
	}
getEnv:
	for key := range env {
		if !hasPrefixFold(key, prefix) {
			continue
		}
		if _, ok := ignoreEnv[key]; ok {
			continue
		}
		for _, field := range fields {
			if strings.EqualFold(key, field) {
				continue getEnv
			}
		}
		for field := range ignoreEnv {
			if strings.EqualFold(key, field) {
				continue getEnv
			}
		}
		return fmt.Errorf("Unrecognized environment variable '%s'", key)
	}
	return nil
}
开发者ID:kitcambridge,项目名称:envconf,代码行数:31,代码来源:envconf.go

示例7: phrasesMatch

// checks if partial is any of the words or phrases within whole
func phrasesMatch(partial, whole string) bool {
	// create words of whole
	words := strings.Fields(whole)
	// tag partial apart and put it back together with standard space
	partials := strings.Fields(partial)
	partialWords := len(partials)
	partial = strings.Join(partials, " ")
	// check if partial matches any of whole's phrases
	for i := 0; (i + partialWords) <= len(words); i++ {

		slidingBit := strings.Join(words[i:(i+partialWords)], " ")

		if strings.EqualFold(slidingBit, partial) {
			return true
		}

		if strings.HasSuffix(slidingBit, "'s") {
			if strings.EqualFold(strings.TrimSuffix(slidingBit, "'s"), partial) {
				return true
			}
		}
	}

	return false
}
开发者ID:strogo,项目名称:newshound,代码行数:26,代码来源:event.go

示例8: Read

func Read(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	requestType := r.FormValue("request_type")
	channelIdStr := r.FormValue("channel_id")
	userId := context.Get(r, "user_id").(int)

	var channelDetails []channeldetail.ChannelDetail

	if strings.EqualFold(requestType, "id") {
		channelDetails = channeldetail.Read(userId)
	} else if strings.EqualFold(requestType, "channel") {
		if helper.IsValidRequest(channelIdStr) {
			channelId, _ := strconv.Atoi(channelIdStr)
			channelDetails = channeldetail.ReadByChannel(channelId)
		}
	} else {
		channelDetails = nil
	}
	if channelDetails != nil {
		responseJson, responseCode := helper.GetResponseJson(channelDetails)
		middleware.Output.Response = responseJson
		middleware.Output.ResponseCode = responseCode
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}
开发者ID:MiteshSharma,项目名称:go-socialengine,代码行数:25,代码来源:channeldetail.go

示例9: syslogStreamer

func syslogStreamer(target Target, types []string, logstream chan *Log) {
	typestr := "," + strings.Join(types, ",") + ","
	for logline := range logstream {
		if typestr != ",," && !strings.Contains(typestr, logline.Type) {
			continue
		}
		tag, pid := getLogName(logline.Name)
		var conn net.Conn
		if strings.EqualFold(target.Protocol, "tcp") {
			addr, err := net.ResolveTCPAddr("tcp", target.Addr)
			assert(err, "syslog")
			tcpconn, err := net.DialTCP("tcp", nil, addr)
			assert(err, "syslog")
			assert(tcpconn.SetWriteBuffer(1048576), "syslog")
			conn = tcpconn
		} else if strings.EqualFold(target.Protocol, "udp") {
			addr, err := net.ResolveUDPAddr("udp", target.Addr)
			assert(err, "syslog")
			udpconn, err := net.DialUDP("udp", nil, addr)
			assert(err, "syslog")
			assert(udpconn.SetWriteBuffer(1048576), "syslog")
			conn = udpconn
		} else {
			assert(fmt.Errorf("%s is not a supported protocol, use either udp or tcp", target.Protocol), "syslog")
		}
		// HACK: Go's syslog package hardcodes the log format, so let's send our own message
		_, err := fmt.Fprintf(conn,
			"%s %s[%s]: %s",
			time.Now().Format(getopt("DATETIME_FORMAT", dtime.DeisDatetimeFormat)),
			tag,
			pid,
			logline.Data)
		assert(err, "syslog")
	}
}
开发者ID:robeferre,项目名称:deis,代码行数:35,代码来源:logspout.go

示例10: chackDqsjAccount

func chackDqsjAccount(ctx *context.Context) (bool, string) {
	ck, err := ctx.Request.Cookie(DQSJ_USERNAME)
	if err != nil {
		return false, ""
	}

	username := ck.Value

	ck, err = ctx.Request.Cookie(DQSJ_PASSWORD)
	if err != nil {
		return false, ""
	}

	password := ck.Value

	admin, err := models.GetOneDqsjAdmin(username)
	beego.Debug("GetOneDqsjAdmin admin:", admin)
	if err != nil {
		return false, ""
	}
	if admin != nil && strings.EqualFold(username, admin.Username) && strings.EqualFold(password, admin.Password) {
		beego.Debug(" cookie username ", username)
		return true, username
	} else {
		return false, username
	}

}
开发者ID:424626154,项目名称:Qax580_GoServer,代码行数:28,代码来源:dqsj.go

示例11: testCgroupspath

func testCgroupspath(linuxSpec *specs.LinuxSpec, linuxRuntimeSpec *specs.LinuxRuntimeSpec) (string, error) {
	configFile := "./config.json"
	runtimeFile := "./runtime.json"
	// check whether the container mounts Cgroup filesystem and get the mount point
	hasCgFs := false
	var cgmnt string
	for k, v := range linuxRuntimeSpec.RuntimeSpec.Mounts {
		if strings.EqualFold(v.Type, "cgroup") {
			hasCgFs = true
			for _, u := range linuxSpec.Spec.Mounts {
				if strings.EqualFold(u.Name, k) {
					cgmnt = u.Path
				}
			}
		}
	}
	if hasCgFs == false {
		return manager.UNSPPORTED, errors.New("Container doesn't support cgroup")
	}
	linuxSpec.Spec.Process.Args = []string{"/bin/bash", "-c", "find " + cgmnt + "/ -name " + linuxRuntimeSpec.Linux.CgroupsPath}
	err := configconvert.LinuxSpecToConfig(configFile, linuxSpec)
	err = configconvert.LinuxRuntimeToConfig(runtimeFile, linuxRuntimeSpec)
	out, err := adaptor.StartRunc(configFile, runtimeFile)
	if err != nil {
		return manager.UNKNOWNERR, errors.New("StartRunc error :" + out + "," + err.Error())
	} else if strings.Contains(out, linuxRuntimeSpec.Linux.CgroupsPath) {
		return manager.PASSED, nil
	} else {
		return manager.FAILED, errors.New("may be NOT SUPPORT setting cgrouppath")
	}
}
开发者ID:WeiZhang555,项目名称:oct,代码行数:31,代码来源:linuxcgroupspath_v0.1.1.go

示例12: getConnectionToken

func getConnectionToken(try int, tokenReq *rclient.HostApiProxyToken, rancherClient *rclient.RancherClient) (*rclient.HostApiProxyToken, error) {
	if try >= maxWaitOnHostTries {
		return nil, fmt.Errorf("Reached max retry attempts for getting token.")
	}

	tokenResponse, err := rancherClient.HostApiProxyToken.Create(tokenReq)
	if err != nil {
		if apiError, ok := err.(*rclient.ApiError); ok {
			if apiError.StatusCode == 422 {
				parsed := &ParsedError{}
				if uErr := json.Unmarshal([]byte(apiError.Body), &parsed); uErr == nil {
					if strings.EqualFold(parsed.Code, "InvalidReference") && strings.EqualFold(parsed.FieldName, "reportedUuid") {
						logrus.WithField("reportedUuid", config.Config.HostUuid).WithField("Attempt", try).Infof("Host not registered yet. Sleeping 1 second and trying again.")
						time.Sleep(time.Second)
						try += 1
						return getConnectionToken(try, tokenReq, rancherClient) // Recursion!
					}
				} else {
					return nil, uErr
				}
			} else if apiError.StatusCode == 501 {
				logrus.Infof("Host-api proxy disabled. Will not connect.")
				return nil, nil
			}
			return nil, err
		}
	}
	return tokenResponse, nil
}
开发者ID:yasker,项目名称:host-api,代码行数:29,代码来源:main.go

示例13: GenerateKey

func GenerateKey(passpharse []byte, config ConfigType) (err error) {
	pubBlock, priBlock, err := _generateKey(passpharse, config)
	if err != nil {
		return
	}

	pubkeyOut, err := os.OpenFile(config.PublicKeyDir, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		if strings.EqualFold(config.PublicKeyDir, "") {
			pubkeyOut = os.Stdout
		} else {
			return
		}

	}
	prikeyOut, err := os.OpenFile(config.PrivateKeyDir, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		if strings.EqualFold(config.PrivateKeyDir, "") {
			prikeyOut = os.Stdout
		} else {
			return
		}
	}
	err = pem.Encode(pubkeyOut, pubBlock)

	if err != nil {
		return
	}
	err = pem.Encode(prikeyOut, priBlock)
	return
}
开发者ID:wulinxu,项目名称:KeyAdmin-go,代码行数:31,代码来源:passwordadmin.go

示例14: ParseContent

// ParseContent asserts that Transmission.Content is valid.
func ParseContent(content interface{}) (err error) {
	switch rVal := content.(type) {
	case map[string]interface{}:
		for k, v := range rVal {
			switch vVal := v.(type) {
			case string:
				if strings.EqualFold(k, "template_id") {
					return nil
				}
			default:
				return fmt.Errorf("Transmission.Content objects must contain string values, not [%s]", reflect.TypeOf(vVal))
			}
		}
		return fmt.Errorf("Transmission.Content objects must contain a key `template_id`")

	case map[string]string:
		for k, _ := range rVal {
			if strings.EqualFold(k, "template_id") {
				return nil
			}
		}
		return fmt.Errorf("Transmission.Content objects must contain a key `template_id`")

	case Content:
		te := &Template{Name: "tmp", Content: rVal}
		return te.Validate()

	default:
		return fmt.Errorf("Unsupported Transmission.Content type [%s]", reflect.TypeOf(rVal))
	}

	return
}
开发者ID:SparkPost,项目名称:gosparkpost,代码行数:34,代码来源:transmissions.go

示例15: TestEcKeyErrors

func TestEcKeyErrors(t *testing.T) {
	k := Key{
		module:     &mockCtx{},
		tokenLabel: "token label",
		pin:        "unused",
	}

	// Trying to load private EC key with no public key
	err := k.setup("no_public_key_ec")
	if err == nil {
		t.Errorf("Unexpected success")
	}
	if !strings.EqualFold(err.Error(), "public key not found") {
		t.Errorf("Unexpected error value: %v", err)
	}

	// Trying to load private EC key with invalid EC point
	err = k.setup("invalid_ec_point")
	if err == nil {
		t.Errorf("Unexpected success")
	}
	if !strings.EqualFold(err.Error(), "invalid EC Point") {
		t.Errorf("Unexpected error value: %v", err)
	}
}
开发者ID:jamesbjackson,项目名称:cfssl,代码行数:25,代码来源:key_test.go


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