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

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

示例1: startAgent

// startAgent executes ssh-agent, and returns a Agent interface to it.
func startAgent(t *testing.T) (client Agent, socket string, cleanup func()) {
    if testing.Short() {
        // ssh-agent is not always available, and the key
        // types supported vary by platform.
        t.Skip("skipping test due to -short")
    }

    bin, err := exec.LookPath("ssh-agent")
    if err != nil {
        t.Skip("could not find ssh-agent")
    }

    cmd := exec.Command(bin, "-s")
    out, err := cmd.Output()
    if err != nil {
        t.Fatalf("cmd.Output: %v", err)
    }

    /* Output looks like:

           SSH_AUTH_SOCK=/tmp/ssh-P65gpcqArqvH/agent.15541; export SSH_AUTH_SOCK;
               SSH_AGENT_PID=15542; export SSH_AGENT_PID;
               echo Agent pid 15542;
    */
    fields := bytes.Split(out, []byte(";"))
    line := bytes.SplitN(fields[0], []byte("="), 2)
    line[0] = bytes.TrimLeft(line[0], "\n")
    if string(line[0]) != "SSH_AUTH_SOCK" {
        t.Fatalf("could not find key SSH_AUTH_SOCK in %q", fields[0])
    }
    socket = string(line[1])

    line = bytes.SplitN(fields[2], []byte("="), 2)
    line[0] = bytes.TrimLeft(line[0], "\n")
    if string(line[0]) != "SSH_AGENT_PID" {
        t.Fatalf("could not find key SSH_AGENT_PID in %q", fields[2])
    }
    pidStr := line[1]
    pid, err := strconv.Atoi(string(pidStr))
    if err != nil {
        t.Fatalf("Atoi(%q): %v", pidStr, err)
    }

    conn, err := net.Dial("unix", string(socket))
    if err != nil {
        t.Fatalf("net.Dial: %v", err)
    }

    ac := NewClient(conn)
    return ac, socket, func() {
        proc, _ := os.FindProcess(pid)
        if proc != nil {
            proc.Kill()
        }
        conn.Close()
        os.RemoveAll(filepath.Dir(socket))
    }
}

开发者ID:ericcapricorn,项目名称:deis,代码行数:59,代码来源:client_test.go

示例2: trimCut

// trimCut cuts the given label at min(maxlen, len(label)) and ensures the left
// and right cutsets are trimmed from their respective ends.
func trimCut(label []byte, maxlen int, left, right string) []byte {
    trim := bytes.TrimLeft(label, left)
    size := min(len(trim), maxlen)
    head := bytes.TrimRight(trim[:size], right)
    if len(head) == size {
        return head
    }
    tail := bytes.TrimLeft(trim[size:], right)
    if len(tail) > 0 {
        return append(head, tail[:size-len(head)]...)
    }
    return head
}

开发者ID:GaizkaRubio,项目名称:mesos-dns,代码行数:15,代码来源:labels.go

示例3: testWalkOutputs

func testWalkOutputs(t *testing.T, root node.Node, opts Options, expect []byte) {
    expect = bytes.TrimLeft(expect, "\n")

    buf := new(bytes.Buffer)
    walk := func(current State) error {
        s := fmt.Sprintf("%d %s\n", current.Depth, current.Node.(*mdag.ProtoNode).Data())
        t.Logf("walk: %s", s)
        buf.Write([]byte(s))
        return nil
    }

    opts.Func = walk
    if err := Traverse(root, opts); err != nil {
        t.Error(err)
        return
    }

    actual := buf.Bytes()
    if !bytes.Equal(actual, expect) {
        t.Error("error: outputs differ")
        t.Logf("expect:\n%s", expect)
        t.Logf("actual:\n%s", actual)
    } else {
        t.Logf("expect matches actual:\n%s", expect)
    }
}

开发者ID:qnib,项目名称:go-ipfs,代码行数:26,代码来源:traverse_test.go

示例4: ListenAndServe

func (s *Server) ListenAndServe() error {
    uaddr, err := net.ResolveUDPAddr("udp", s.Addr)
    if err != nil {
        return err
    }
    conn, err := net.ListenUDP("udp", uaddr)
    if err != nil {
        return err
    }
    defer conn.Close()
    log.Println("listening on", uaddr)
    newmsg := make(chan Message)
    go messageReceiver(s, newmsg)
    for {
        b := make([]byte, 1024)
        n, addr, err := conn.ReadFrom(b)
        if err != nil {
            log.Println("error %v", err)
            continue
        }
        heartbeat := Message{From: addr.String()}
        b = bytes.TrimLeft(b[:n], "\n")
        heartbeat.extract(b) // remove newline
        newmsg <- heartbeat
    }

}

开发者ID:hagna,项目名称:watchdog,代码行数:27,代码来源:watchdog.go

示例5: Detect

func (p ParagraphDetector) Detect(first, second Line, detectors Detectors) Handler {
    block := md.ParagraphBlock{}
    return HandlerFunc(func(next Line, ctx Context) (bool, error) {
        if next.EOF() {
            return p.close(block, ctx)
        }
        if len(block.Raw) == 0 {
            block.Raw = append(block.Raw, md.Run(next))
            return true, nil
        }
        prev := Line(block.Raw[len(block.Raw)-1])
        // TODO(akavel): support HTML parser & related interactions [#paragraph-line-sequence]
        if prev.isBlank() {
            return p.close(block, ctx)
        }
        nextBytes := bytes.TrimRight(next.Bytes, "\n")
        if !next.hasFourSpacePrefix() {
            if reHorizontalRule.Match(nextBytes) ||
                (p.InQuote && bytes.HasPrefix(bytes.TrimLeft(next.Bytes, " "), []byte(">"))) ||
                (p.InList && reOrderedList.Match(nextBytes)) ||
                (p.InList && reUnorderedList.Match(nextBytes)) {
                return p.close(block, ctx)
            }
        }
        block.Raw = append(block.Raw, md.Run(next))
        return true, nil
    })
}

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

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