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

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

示例1: HandleLog

// HandleLog is the default http log handler
func HandleLog(h HTTP, entries <-chan *log.Entry) {
    var e *log.Entry
    var b []byte
    var reader *bytes.Reader

    formatter := h.FormatFunc()(h)
    remoteHost := h.RemoteHost()
    httpClient := stdhttp.Client{}

    req, _ := stdhttp.NewRequest(h.Method(), remoteHost, nil)
    req.Header = h.Headers()

    for e = range entries {

        b = formatter(e)

        reader = bytes.NewReader(b)
        req.Body = ioutil.NopCloser(reader)
        req.ContentLength = int64(reader.Len())

        resp, err := httpClient.Do(req)
        if err != nil {
            log.Error("Could not post data to %s: %v\n", remoteHost, err)
            goto END
        }

        if resp.StatusCode < 200 || resp.StatusCode >= 299 {
            bt, _ := ioutil.ReadAll(resp.Body)
            log.Error("Received HTTP %d during POST request to %s body: %s\n", resp.StatusCode, remoteHost, string(bt))
        }

    END:
        e.Consumed()
    }
}

开发者ID:go-playground,项目名称:log,代码行数:36,代码来源:http.go

示例2: _readLong3

func _readLong3(file *bytes.Reader, offset int64) int64 {
    buf := make([]byte, 4)
    file.ReadAt(buf, offset)
    buf[3] = 0x00

    return int64(binary.LittleEndian.Uint32(buf))
}

开发者ID:rchunping,项目名称:ip2location-qqwry,代码行数:7,代码来源:main.go

示例3: AuthedRequest

func (k *KeenIoMetrics) AuthedRequest(method, path string, body *bytes.Reader) (resp *http.Response, err error) {
    path = fmt.Sprintf("https://api.keen.io/3.0/projects/%s%s", k.ProjectToken, path)
    req, err := http.NewRequest(method, path, body)
    if err != nil {
        return
    }

    req.Header.Add("Authorization", k.ApiKey)

    if body != nil {
        req.Header.Add("Content-Type", "application/json")
        req.ContentLength = int64(body.Len())
    }

    resp, err = k.HttpClient.Do(req)

    if err != nil {
        k.Error("Failed to send metric event to keen.io %v", err)
    } else {
        defer resp.Body.Close()
        if resp.StatusCode != 201 {
            bytes, _ := ioutil.ReadAll(resp.Body)
            k.Error("Got %v response from keen.io: %s", resp.StatusCode, bytes)
        }
    }

    return
}

开发者ID:rif,项目名称:golang-stuff,代码行数:28,代码来源:metrics.go

示例4: readEntryValueAsLong

func (this *HSPerfData) readEntryValueAsLong(reader *bytes.Reader, StartOfs int64, entry *PerfDataEntry) error {
    reader.Seek(StartOfs+int64(entry.DataOffset), os.SEEK_SET)
    reader.Read(this.globalbuf[:8])
    entry.LongValue = int64(this.byteOrder.Uint64(this.globalbuf[:8]))

    return nil
}

开发者ID:YaSuenag,项目名称:hsbeat,代码行数:7,代码来源:parser.go

示例5: Skip

//Skip skip
func (t *TTFParser) Skip(fd *bytes.Reader, length int) error {
    _, err := fd.Seek(int64(length), 1)
    if err != nil {
        return err
    }
    return nil
}

开发者ID:signintech,项目名称:gopdf,代码行数:8,代码来源:ttfparser.go

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