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

在下文中一共展示了TrimRight函数的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: ParseKey

// ParseKey reads the given RSA private key and create a public one for it.
func ParseKey(pem string) (*Key, error) {
    p, err := ioutil.ReadFile(pem)
    if err != nil {
        return nil, err
    }
    key, err := ssh.ParseRawPrivateKey(p)
    if err != nil {
        return nil, err
    }
    rsaKey, ok := key.(*rsa.PrivateKey)
    if !ok {
        return nil, fmt.Errorf("%q is not a RSA key", pem)
    }
    pub, err := ssh.NewPublicKey(&rsaKey.PublicKey)
    if err != nil {
        return nil, err
    }
    // Compute key fingerprint.
    var buf bytes.Buffer
    for _, b := range md5.Sum(pub.Marshal()) {
        fmt.Fprintf(&buf, "%0.2x:", b)
    }
    return &Key{
        Label:       strings.TrimSuffix(filepath.Base(pem), ".pem"),               // trim .pem file extension
        Key:         string(bytes.TrimRight(ssh.MarshalAuthorizedKey(pub), "\n")), // trim newline
        Fingerprint: string(bytes.TrimRight(buf.Bytes(), ":")),                    // trim dangling colon
        Note:        "{}",
        Tags:        make(Tags),
    }, nil
}

开发者ID:koding,项目名称:koding,代码行数:31,代码来源:keys.go

示例3: DetectAtxHeader

func DetectAtxHeader(first, second Line, detectors Detectors) Handler {
    if !bytes.HasPrefix(first.Bytes, []byte("#")) {
        return nil
    }
    done := false
    return HandlerFunc(func(line Line, ctx Context) (bool, error) {
        if done {
            return false, nil
        }
        done = true
        block := md.AtxHeaderBlock{
            Raw: md.Raw{md.Run(line)},
        }
        text := bytes.TrimRight(line.Bytes, "\n")
        text = bytes.Trim(text, "#")
        if len(text) > 0 {
            block.Level, _ = mdutils.OffsetIn(line.Bytes, text)
        } else {
            block.Level = len(bytes.TrimRight(line.Bytes, "\n"))
        }
        if block.Level > 6 {
            block.Level = 6
        }

        spanRegion := md.Raw{md.Run{
            Line:  line.Line,
            Bytes: bytes.Trim(text, mdutils.Whites),
        }}
        ctx.Emit(block)
        parseSpans(spanRegion, ctx)
        ctx.Emit(md.End{})
        return true, nil
    })
}

开发者ID:akavel,项目名称:vfmd,代码行数:34,代码来源:atxheader.go

示例4: readLine

func (p *parser) readLine() []byte {
    if !p.linenoFixed {
        p.lineno = p.elineno + 1
    }
    var line []byte
    for !p.done {
        buf, err := p.rd.ReadBytes('\n')
        if !p.linenoFixed {
            p.elineno++
        }
        if err == io.EOF {
            p.done = true
        } else if err != nil {
            p.err = fmt.Errorf("readline %s: %v", p.srcpos(), err)
            p.done = true
        }
        line = append(line, buf...)
        buf = bytes.TrimRight(buf, "\r\n")
        backslash := false
        for len(buf) > 1 && buf[len(buf)-1] == '\\' {
            buf = buf[:len(buf)-1]
            backslash = !backslash
        }
        if !backslash {
            break
        }
    }
    line = bytes.TrimRight(line, "\r\n")
    return line
}

开发者ID:kleopatra999,项目名称:kati,代码行数:30,代码来源:parser.go

示例5: main

func main() {
    input_buffer := bufio.NewReader(os.Stdin)
    fmt.Println("Type your settings from https://themis.cossacklabs.com/interactive-simulator/setup/")

    fmt.Println("JSON endpoint: ")
    endpoint, err := input_buffer.ReadString('\n')
    endpoint = strings.TrimRight(endpoint, "\n\r")

    fmt.Println("Your private key in base64 format:")
    client_private, err := input_buffer.ReadBytes('\n')
    client_private, err = base64.StdEncoding.DecodeString(string(client_private))
    if err != nil {
        fmt.Println("Incorrect base64 format for private key")
        return
    }

    fmt.Println("Server public key in base64 format:")
    server_public, err := input_buffer.ReadBytes('\n')
    server_public = bytes.TrimRight(server_public, "\r\n")
    server_public, err = base64.StdEncoding.DecodeString(string(server_public))
    secure_message := message.New(
        &keys.PrivateKey{bytes.TrimRight(client_private, "\r\n")},
        &keys.PublicKey{server_public})

    for {
        fmt.Println("Print message to send (or quit to stop):")
        line, _, err := input_buffer.ReadLine()
        if err != nil {
            fmt.Println(err)
            return
        }
        if bytes.Equal(line, []byte("quit")) {
            return
        }

        wrapped, err := secure_message.Wrap(line)
        if err != nil {
            fmt.Println("Error in wraping", err)
            return
        }
        data, err := send_message(wrapped, endpoint)
        if err != nil {
            fmt.Println("Error occured:", err)
            return
        }
        unwrapped, err := secure_message.Unwrap(data)
        fmt.Println(string(unwrapped))
    }
}

开发者ID:secumod,项目名称:themis,代码行数:49,代码来源:smessage_server.go

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