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

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

示例1: ReverseScan

// Scan the datafile in reverse order using a custom separator and function.
// The provided function has two params, data and whether we at the end or not .
// This function will lock the whole file till it ends .
func (this *AOF) ReverseScan(sep []byte, fn func(data []byte, atEOF bool) bool) {
    this.Lock()
    defer this.Unlock()
    pos := int64(0)
    done := int64(0)
    data := []byte{}
    for {
        this.file.Seek(pos, 2)
        tmp := make([]byte, len(sep))
        n, _ := this.file.Read(tmp)
        pos -= int64(len(sep))
        if n > 0 {
            done += int64(n)
            data = append(tmp, data...)
        }
        if bytes.Equal(sep, tmp) {
            if !fn(bytes.Trim(data, string(sep)), false) {
                break
            }
            data = []byte{}
        }
        if done >= this.size {
            fn(bytes.Trim(data, string(sep)), true)
            break
        }
    }
    data = []byte{}
}

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

示例2: Scan

// Scan the datafile using a custom separator and function.
// The provided function has two params, data and whether we at the end or not .
// This function will lock the whole file till it ends .
func (this *AOF) Scan(sep []byte, fn func(data []byte, atEOF bool) bool) {
    this.Lock()
    defer this.Unlock()
    this.file.Seek(0, 0)
    data := []byte{}
    for {
        tmp := make([]byte, len(sep))
        n, e := this.file.Read(tmp)
        if n > 0 {
            data = append(data, tmp[0:n]...)
        }
        if e != nil || n == 0 {
            if len(data) > 0 {
                fn(bytes.Trim(data, string(sep)), true)
            }
            break
        }
        if bytes.Equal(sep, tmp) {
            if !fn(bytes.Trim(data, string(sep)), false) {
                break
            }
            data = []byte{}
        }
    }
    data = []byte{}
}

开发者ID:alash3al,项目名称:aof,代码行数:29,代码来源:aof.go

示例3: WiteToTSDB

func WiteToTSDB(channel chan []byte, cfg *Config) {
START:
    tcpAddr, err := net.ResolveTCPAddr("tcp4", cfg.OPENTSDB_ADDR)
    if err != nil {
        panic(fmt.Sprintf("error opentsdb address(%s)", cfg.OPENTSDB_ADDR))
    }
    conn, err := net.DialTCP("tcp4", nil, tcpAddr)
    if err != nil {
        slog.Error("connect tsdb server(%s) error(%s)", tcpAddr, err)
        time.Sleep(time.Second * 30)
        goto START
    }
    slog.Info("connected to opentsdb server %s", cfg.OPENTSDB_ADDR)
    conn.SetKeepAlive(true)
    defer conn.Close()
    for {
        select {
        case data, ok := <-channel:
            if ok {
                data = append(data, '\n')
                length, err := conn.Write(data)
                if err != nil {
                    slog.Error("write opentsdb error %s", err)
                    channel <- bytes.Trim(data, "\n")
                    time.Sleep(time.Second * 30)
                    goto START
                }
                dlog.Info("write opentsdb %d bytes, data:(%s)", length, string(bytes.Trim(data, "\n")))
            }
        }
    }
}

开发者ID:y8y,项目名称:OWL-v3,代码行数:32,代码来源:opentsdb.go

示例4: parseMeta

func parseMeta(buf *bytes.Buffer, repo string) {
    var name string
    pack := map[string]string{}
    pack["REPO"] = repo
    _, _ = buf.ReadByte()
    for {
        key, err := buf.ReadBytes('%')
        if err == io.EOF {
            break
        }
        key = bytes.Trim(key, "%")
        values, _ := buf.ReadBytes('%')
        values = bytes.Trim(values, "%")
        values = bytes.Replace(values, []byte("\n"), []byte(" "), -1)
        values = bytes.Trim(values, " ")
        if string(key) == "NAME" {
            name = string(values)
        }
        pack[string(key)] = string(values)
    }
    v, _ := packages[name]
    if v != nil {
        printf("%s exists\n", name)
    }
    packages[name] = pack
}

开发者ID:sbinet,项目名称:gur,代码行数:26,代码来源:pacman.go

示例5: ProtrackerParse

func ProtrackerParse(rawData *bytes.Buffer) (samples []Sample) {
    modTitle := string(bytes.Trim(rawData.Next(20), zerostring))
    for i := 0; i < 31; i++ {
        sampleTitle := modTitle + " - " + string(bytes.Trim(rawData.Next(22), zerostring))
        sampleLength := BigEndianBytesToInt(rawData.Next(2)) * 2
        if sampleLength >= uint16(2) &&
            len(sampleTitle) > 0 {
            samples = append(samples, Sample{
                Title:  sampleTitle,
                Length: int(sampleLength),
            })
        }
        //discard finetune (1 byte), volume (1 byte), repeat info (4 bytes)
        _ = rawData.Next(6)
    }

    songLength := rawData.Next(2)[0] //discard unused 127 byte.
    patternOrder := rawData.Next(133)[:songLength]
    // discard pattern data
    for i := 0; i < int(biggest(patternOrder))+1; i++ { // patterns start at 00, so add 1
        _ = rawData.Next(1024)
    }

    for i, s := range samples {
        samples[i].Data = rawData.Next(s.Length)
    }

    fmt.Println("Title:", modTitle, "Samples:", len(samples))
    return
}

开发者ID:minikomi,项目名称:ModRipper.go,代码行数:30,代码来源:ModRipper.go

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