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

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

示例1: postContainerExecCreate

func postContainerExecCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    if err := parseForm(r); err != nil {
        return nil
    }
    var (
        name         = vars["name"]
        job          = eng.Job("execCreate", name)
        stdoutBuffer = bytes.NewBuffer(nil)
        outWarnings  []string
        warnings     = bytes.NewBuffer(nil)
    )

    if err := job.DecodeEnv(r.Body); err != nil {
        return err
    }

    job.Stdout.Add(stdoutBuffer)
    // Read warnings from stderr
    job.Stderr.Add(warnings)
    // Register an instance of Exec in container.
    if err := job.Run(); err != nil {
        fmt.Fprintf(os.Stderr, "Error setting up exec command in container %s: %s\n", name, err)
        return err
    }
    // Parse warnings from stderr
    scanner := bufio.NewScanner(warnings)
    for scanner.Scan() {
        outWarnings = append(outWarnings, scanner.Text())
    }

    return writeJSON(w, http.StatusCreated, &types.ContainerExecCreateResponse{
        ID:       engine.Tail(stdoutBuffer, 1),
        Warnings: outWarnings,
    })
}

开发者ID:jaegerpicker,项目名称:docker,代码行数:35,代码来源:server.go

示例2: waterMark

//水印
func waterMark(picBytes []byte) []byte {
    // 打开水印图并解码
    img, fileType, _ := image.Decode(bytes.NewBuffer(picBytes))

    //读取水印图片
    watermark, _ := png.Decode(bytes.NewBuffer(wm))

    //原始图界限
    origin_size := img.Bounds()

    //创建新图层
    canvas := image.NewNRGBA(origin_size)

    //贴原始图
    draw.Draw(canvas, origin_size, img, image.ZP, draw.Src)
    //贴水印图
    draw.Draw(canvas, watermark.Bounds().Add(image.Pt(origin_size.Dx()-watermark.Bounds().Dx(), origin_size.Dy()-watermark.Bounds().Dy()-4)), watermark, image.ZP, draw.Over)

    //生成新图片
    buff := bytes.NewBuffer([]byte{})

    switch fileType {
    case "jpeg":
        jpeg.Encode(buff, canvas, &jpeg.Options{95})
    default:
        png.Encode(buff, canvas)
    }

    return buff.Bytes()
}

开发者ID:elvizlai,项目名称:MGBlog,代码行数:31,代码来源:file.go

示例3: Render

func (self *Task) Render() {
    for _, config := range self.Config.Templates {
        log.Printf("Render: %s", config.Dst)
        f, err := ioutil.ReadFile(self.Controller.Atom.Config.TmplDir + "/" + config.Src)
        if err != nil {
            log.Printf("Error:: Read - %s", err)
            continue
        }
        var output *bytes.Buffer
        if self.Controller.Atom.Config.Verbose {
            output = bytes.NewBuffer(nil)
        }
        src := bytes.NewBuffer(f)
        tmpl, err := template.New("").Funcs(self.Config.Store.FuncMap).Parse(src.String())
        if err != nil {
            log.Printf("Error:: Render - %s", err)
            continue
        }
        vars := map[string]interface{}{"cli": self.Controller.Atom.CLI}
        if self.Controller.Atom.Config.Verbose {
            if err := tmpl.Execute(output, vars); err != nil {
                log.Printf("Error:: Write - %s", err)
            }
            fmt.Print(output.String())
        }
        dst, err := os.Create(config.Dst)
        if err != nil {
            log.Printf("Error:: Open - %s", err)
            continue
        }
        if err := tmpl.Execute(dst, vars); err != nil {
            log.Printf("Error:: Write - %s", err)
        }
    }
}

开发者ID:psev,项目名称:atom,代码行数:35,代码来源:task.go

示例4: TestDecrypterClose

func TestDecrypterClose(t *testing.T) {
    c, err := newCipher(NameEncryptionStandard, "", "")
    assert.NoError(t, err)

    cd := newCloseDetector(bytes.NewBuffer(file16))
    fh, err := c.newDecrypter(cd)
    assert.NoError(t, err)
    assert.Equal(t, 0, cd.closed)

    // close before reading
    assert.Equal(t, nil, fh.err)
    err = fh.Close()
    assert.Equal(t, ErrorFileClosed, fh.err)
    assert.Equal(t, 1, cd.closed)

    // double close
    err = fh.Close()
    assert.Error(t, err, ErrorFileClosed.Error())
    assert.Equal(t, 1, cd.closed)

    // try again reading the file this time
    cd = newCloseDetector(bytes.NewBuffer(file1))
    fh, err = c.newDecrypter(cd)
    assert.NoError(t, err)
    assert.Equal(t, 0, cd.closed)

    // close after reading
    out, err := ioutil.ReadAll(fh)
    assert.NoError(t, err)
    assert.Equal(t, []byte{1}, out)
    assert.Equal(t, io.EOF, fh.err)
    err = fh.Close()
    assert.Equal(t, ErrorFileClosed, fh.err)
    assert.Equal(t, 1, cd.closed)
}

开发者ID:ncw,项目名称:rclone,代码行数:35,代码来源:cipher_test.go

示例5: SetUpTest

func (s *archiveDataSuite) SetUpTest(c *gc.C) {
    s.IsolationSuite.SetUpTest(c)

    meta, err := backups.NewMetadataJSONReader(bytes.NewBufferString(`{` +
        `"ID":"20140909-115934.asdf-zxcv-qwe",` +
        `"Checksum":"123af2cef",` +
        `"ChecksumFormat":"SHA-1, base64 encoded",` +
        `"Size":10,` +
        `"Stored":"0001-01-01T00:00:00Z",` +
        `"Started":"2014-09-09T11:59:34Z",` +
        `"Finished":"2014-09-09T12:00:34Z",` +
        `"Notes":"",` +
        `"Environment":"asdf-zxcv-qwe",` +
        `"Machine":"0",` +
        `"Hostname":"myhost",` +
        `"Version":"1.21-alpha3"` +
        `}` + "\n"))
    c.Assert(err, jc.ErrorIsNil)

    archiveFile := s.newArchiveFile(c, meta)
    compressed, err := ioutil.ReadAll(archiveFile)
    c.Assert(err, jc.ErrorIsNil)
    gzr, err := gzip.NewReader(bytes.NewBuffer(compressed))
    c.Assert(err, jc.ErrorIsNil)
    data, err := ioutil.ReadAll(gzr)
    c.Assert(err, jc.ErrorIsNil)

    s.archiveFile = bytes.NewBuffer(compressed)
    s.data = data
    s.meta = meta
}

开发者ID:howbazaar,项目名称:juju,代码行数:31,代码来源:archive_data_test.go

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