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

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

示例1: parseIndex

func parseIndex(sql []byte) (indexName string, indexId interface{}, userId uint64) {
    var err error
    keyspaceIndex := bytes.Index(sql, KEYSPACE_ID_COMMENT)
    if keyspaceIndex == -1 {
        panic(NewBinlogParseError(fmt.Sprintf("Error parsing index comment, doesn't contain keyspace id %v", string(sql))))
    }
    keyspaceIdComment := sql[keyspaceIndex+len(KEYSPACE_ID_COMMENT):]
    indexCommentStart := bytes.Index(keyspaceIdComment, INDEX_COMMENT)
    if indexCommentStart != -1 {
        indexCommentParts := bytes.SplitN(keyspaceIdComment[indexCommentStart:], COLON_BYTE, 2)
        userId, err = strconv.ParseUint(string(bytes.SplitN(indexCommentParts[1], mysqlctl.SPACE, 2)[0]), 10, 64)
        if err != nil {
            panic(NewBinlogParseError(fmt.Sprintf("Error converting user_id %v", string(sql))))
        }
        indexNameId := bytes.Split(indexCommentParts[0], DOT_BYTE)
        indexName = string(indexNameId[1])
        if indexName == "username" {
            indexId = string(bytes.TrimRight(indexNameId[2], COLON))
        } else {
            indexId, err = strconv.ParseUint(string(bytes.TrimRight(indexNameId[2], COLON)), 10, 64)
            if err != nil {
                panic(NewBinlogParseError(fmt.Sprintf("Error converting index id %v %v", string(bytes.TrimRight(indexNameId[2], COLON)), string(sql))))
            }
        }
    }
    return
}

开发者ID:shrutip,项目名称:vitess,代码行数:27,代码来源:vt_binlog_server.go

示例2: TestNew

func TestNew(t *testing.T) {

    err := New("foo")

    if err.Error() != "foo" {
        t.Errorf("Wrong message")
    }

    err = New(fmt.Errorf("foo"))

    if err.Error() != "foo" {
        t.Errorf("Wrong message")
    }

    bs := [][]byte{New("foo").Stack(), debug.Stack()}

    // Ignore the first line (as it contains the PC of the .Stack() call)
    bs[0] = bytes.SplitN(bs[0], []byte("\n"), 2)[1]
    bs[1] = bytes.SplitN(bs[1], []byte("\n"), 2)[1]

    if bytes.Compare(bs[0], bs[1]) != 0 {
        t.Errorf("Stack didn't match")
        t.Errorf("%s", bs[0])
        t.Errorf("%s", bs[1])
    }

    if err.ErrorStack() != err.TypeName()+" "+err.Error()+"\n"+string(err.Stack()) {
        t.Errorf("ErrorStack is in the wrong format")
    }
}

开发者ID:hdczsf,项目名称:errors,代码行数:30,代码来源:error_test.go

示例3: statCpu

func statCpu(oC *tCommand) {
    var aPass [2][7]int
    var aTotl = [2]int{0, 0}
    for a := 0; a < len(aPass); a++ {
        aBuf, _ := ioutil.ReadFile("/proc/stat")
        aLine := bytes.SplitN(aBuf, []byte{'\n'}, 3)
        aLine = bytes.SplitN(aLine[1], []byte{' '}, 9)
        for aN := 0; aN < len(aPass[0]); aN++ {
            aPass[a][aN], _ = strconv.Atoi(string(aLine[aN+1]))
            aTotl[a] += aPass[a][aN]
        }
        if a == 0 {
            time.Sleep(time.Duration(150) * time.Millisecond)
        }
    }
    var aArg string
    for aN := 0; aN < len(aPass[0]); aN++ {
        aPass[0][aN] = (aPass[1][aN] - aPass[0][aN]) * 1000 / (aTotl[1] - aTotl[0])
        aArg += fmt.Sprintf("%4d.%d  ", aPass[0][aN]/10, aPass[0][aN]%10)
    }
    oC.buf = []byte(fmt.Sprintf("%-6s  %-6s  %-6s  %-6s  %-6s  %-6s  %-6s\n%s\n",
        "User %", "Niced", "System", "Idle", "IOWait", "IRQ", "SoftIRQ", aArg))
    if sDebug {
        fmt.Println(oC.name)
    }
}

开发者ID:networkimprov,项目名称:info-anvl,代码行数:26,代码来源:info.go

示例4: ParseMessage

func ParseMessage(line []byte) *Message {
    line = bytes.TrimSpace(line)
    if len(line) <= 0 {
        return nil
    }
    m := new(Message)
    if line[0] == ':' {
        split := bytes.SplitN(line, []byte{' '}, 2)
        if len(split) <= 1 {
            return nil
        }
        m.Prefix = string(split[0][1:])
        line = split[1]
    }
    split := bytes.SplitN(line, []byte{':'}, 2)
    args := bytes.Split(bytes.TrimSpace(split[0]), []byte{' '})
    m.Command = string(bytes.ToUpper(args[0]))
    m.Args = make([]string, 0, len(args))
    for _, arg := range args[1:] {
        m.Args = append(m.Args, string(arg))
    }
    if len(split) > 1 {
        m.Args = append(m.Args, string(split[1]))
    }
    return m
}

开发者ID:kylelemons,项目名称:ircd-blight,代码行数:26,代码来源:parser.go

示例5: decodeJob

// Decode job from byte slice
func decodeJob(data []byte) (job *Job, err error) {
    if len(data) < 12 {
        return nil, common.Errorf("Invalid data: %V", data)
    }
    datatype := common.BytesToUint32([4]byte{data[4], data[5], data[6], data[7]})
    l := common.BytesToUint32([4]byte{data[8], data[9], data[10], data[11]})
    if len(data[12:]) != int(l) {
        return nil, common.Errorf("Invalid data: %V", data)
    }
    data = data[12:]
    job = &Job{magicCode: common.RES, DataType: datatype, c: make(chan bool)}
    switch datatype {
    case common.JOB_ASSIGN:
        s := bytes.SplitN(data, []byte{'\x00'}, 3)
        if len(s) == 3 {
            job.Handle = string(s[0])
            job.Fn = string(s[1])
            data = s[2]
        }
    case common.JOB_ASSIGN_UNIQ:
        s := bytes.SplitN(data, []byte{'\x00'}, 4)
        if len(s) == 4 {
            job.Handle = string(s[0])
            job.Fn = string(s[1])
            job.UniqueId = string(s[2])
            data = s[3]
        }
    }
    job.Data = data
    return
}

开发者ID:jasonmoo,项目名称:gearman-go,代码行数:32,代码来源:job.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng