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

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

示例1: snmpTranslate

// snmpTranslate resolves the given OID.
// The contents of the oid parameter will be replaced with the numeric oid value.
// If name is empty, the textual OID value is stored in it. If the textual OID cannot be translated, the numeric OID is stored instead.
// If mibPrefix is non-nil, the MIB in which the OID was found is stored, with a suffix of "::".
func snmpTranslate(mibPrefix *string, oid *string, name *string) error {
    if strings.ContainsAny(*oid, ":abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
        out, err := execCmd("snmptranslate", "-m", "all", "-On", *oid)
        if err != nil {
            return Errorf(err, "translating %s", *oid)
        }
        *oid = string(bytes.TrimSuffix(out, []byte{'\n'}))
    }

    if *name == "" {
        out, err := execCmd("snmptranslate", "-m", "all", *oid)
        if err != nil {
            //TODO debug message
            *name = *oid
        } else {
            if i := bytes.Index(out, []byte("::")); i != -1 {
                if mibPrefix != nil {
                    *mibPrefix = string(out[:i+2])
                }
                out = out[i+2:]
            }
            *name = string(bytes.TrimSuffix(out, []byte{'\n'}))
        }
    }

    return nil
}

开发者ID:li-ang,项目名称:telegraf,代码行数:31,代码来源:snmp.go

示例2: statsPerNUMA

// statsPerNUMA gathers hugepages statistics from each NUMA node
func statsPerNUMA(path string) (map[string]HugepagesNUMAStats, error) {
    var hugepagesStats = make(map[string]HugepagesNUMAStats)
    dirs, err := ioutil.ReadDir(path)
    if err != nil {
        return hugepagesStats, err
    }

    for _, d := range dirs {
        if !(d.IsDir() && strings.HasPrefix(d.Name(), "node")) {
            continue
        }

        hugepagesFree := fmt.Sprintf("%s/%s/hugepages/hugepages-2048kB/free_hugepages", path, d.Name())
        hugepagesNR := fmt.Sprintf("%s/%s/hugepages/hugepages-2048kB/nr_hugepages", path, d.Name())

        free, err := ioutil.ReadFile(hugepagesFree)
        if err != nil {
            return hugepagesStats, err
        }

        nr, err := ioutil.ReadFile(hugepagesNR)
        if err != nil {
            return hugepagesStats, err
        }

        f, _ := strconv.Atoi(string(bytes.TrimSuffix(free, newlineByte)))
        n, _ := strconv.Atoi(string(bytes.TrimSuffix(nr, newlineByte)))

        hugepagesStats[d.Name()] = HugepagesNUMAStats{Free: f, NR: n}

    }
    return hugepagesStats, nil
}

开发者ID:Maksadbek,项目名称:telegraf,代码行数:34,代码来源:hugepages.go

示例3: execAndParseCols

func (r *Repository) execAndParseCols(subcmd string) ([][2]string, error) {
    cmd := exec.Command("hg", "-v", "--debug", subcmd)
    cmd.Dir = r.Dir
    out, err := cmd.CombinedOutput()
    if err != nil {
        return nil, fmt.Errorf("exec `hg -v --debug %s` failed: %s. Output was:\n\n%s", subcmd, err, out)
    }

    out = bytes.TrimSuffix(out, []byte("\n")) // remove trailing newline
    lines := bytes.Split(out, []byte("\n"))
    sort.Sort(byteSlices(lines)) // sort for consistency
    refs := make([][2]string, len(lines))
    for i, line := range lines {
        line = bytes.TrimSuffix(line, []byte(" (inactive)"))

        // format: "NAME      SEQUENCE:ID" (arbitrary amount of whitespace between NAME and SEQUENCE)
        if len(line) <= 41 {
            return nil, fmt.Errorf("unexpectedly short (<=41 bytes) line in `hg -v --debug %s` output", subcmd)
        }
        id := line[len(line)-40:]

        // find where the SEQUENCE begins
        seqIdx := bytes.LastIndex(line, []byte(" "))
        if seqIdx == -1 {
            return nil, fmt.Errorf("unexpectedly no whitespace in line in `hg -v --debug %s` output", subcmd)
        }
        name := bytes.TrimRight(line[:seqIdx], " ")
        refs[i] = [2]string{string(id), string(name)}
    }
    return refs, nil
}

开发者ID:alexsaveliev,项目名称:go-vcs,代码行数:31,代码来源:repo.go

示例4: adjustedOutputPosition

func (p *docPrinter) adjustedOutputPosition() int64 {
    b := p.buf.Bytes()
    b = bytes.TrimSuffix(b, []byte{'*'})
    b = bytes.TrimSuffix(b, []byte{'[', ']'})
    b = bytes.TrimSuffix(b, []byte{'*'})
    b = bytes.TrimSuffix(b, []byte{'&'})
    return p.outputPosition() - int64(p.buf.Len()-len(b))
}

开发者ID:gosuri,项目名称:dotfiles,代码行数:8,代码来源:doc.go

示例5: ExampleTrimSuffix

func ExampleTrimSuffix() {
    var b = []byte("Hello, goodbye, etc!")
    b = bytes.TrimSuffix(b, []byte("goodbye, etc!"))
    b = bytes.TrimSuffix(b, []byte("gopher"))
    b = append(b, bytes.TrimSuffix([]byte("world!"), []byte("x!"))...)
    os.Stdout.Write(b)
    // Output: Hello, world!
}

开发者ID:achanda,项目名称:go,代码行数:8,代码来源:example_test.go

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