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