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

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

示例1: addEmails

func addEmails(reason string, emailsReader io.Reader) {
    scanner := bufio.NewScanner(emailsReader)
    emailsFile, emailsFileErr := os.OpenFile("./emails.txt", os.O_APPEND|os.O_WRONLY, 0600)
    if emailsFileErr != nil {
        fmt.Println(emailsFileErr.Error())
    }
    defer emailsFile.Close()
    emailsListFile, emailsListFileErr := os.OpenFile("./emailsList.txt", os.O_APPEND|os.O_WRONLY, 0600)
    if emailsListFileErr != nil {
        fmt.Println(emailsListFileErr.Error())
    }
    defer emailsListFile.Close()
    emailsWritter := bufio.NewWriter(emailsFile)
    emailsListWritter := bufio.NewWriter(emailsListFile)
    for scanner.Scan() {
        // TODO refactor r:reason,e:email
        email := scanner.Text()
        emailLine := "reason:" + reason + ",email:" + email + "\n"
        _, writeEmailsErr := emailsWritter.WriteString(emailLine)
        if writeEmailsErr != nil {
            fmt.Println(writeEmailsErr.Error())
        }
        _, writeEmailsListErr := emailsListWritter.WriteString(email + "\n")
        if writeEmailsListErr != nil {
            fmt.Println(writeEmailsListErr.Error())
        }
    }
    emailsWritter.Flush()
    emailsListWritter.Flush()
}

开发者ID:LicaSterian,项目名称:unsub,代码行数:30,代码来源:Index.go

示例2: Trim

func Trim() {
    var inputFile, outputFile string
    var mean, window, minLength int
    flags := flag.NewFlagSet("trim", flag.ExitOnError)
    flags.StringVar(&inputFile, "input", "", "Name of the fastq input file. Otherwise STDIN.")
    flags.StringVar(&outputFile, "output", "", "Name of the output file. Otherwise STDOUT.")
    flags.IntVar(&mean, "mean", 20, "Mean quality of output sequences.")
    flags.IntVar(&window, "window", 50, "Size of trailing window.")
    flags.IntVar(&minLength, "length", 50, "Minimum sequence length.")
    flags.Parse(os.Args[2:])
    input := bufio.NewReader(os.Stdin)
    output := bufio.NewWriter(os.Stdout)
    if inputFile != "" {
        file, err := os.Open(inputFile)
        if err != nil {
            panic("Cannot open specified input file: " + inputFile)
        }
        input = bufio.NewReader(file)
    }
    if outputFile != "" {
        file, err := os.Create(outputFile)
        if err != nil {
            panic("Cannot create specified output file: " + outputFile)
        }
        output = bufio.NewWriter(file)
    }
    qtrim.TrimIO(input, output, mean, window, minLength)
}

开发者ID:hyraxbio,项目名称:qtrim,代码行数:28,代码来源:qtrim.go

示例3: sendCommand

func sendCommand(command, args string, connector models.Connector) string {
    port := 5985
    if connector.Port != "" {
        port, _ = strconv.Atoi(connector.Port)
    }

    endpoint := winrm.NewEndpoint(connector.Server, port, false, false, nil, nil, nil, 0)
    rmclient, err := winrm.NewClient(endpoint, connector.Login, connector.Pass)
    if err != nil {
        log.Println("Error connecting to endpoint:", err)
        return "Error connecting to endpoint: " + err.Error()
    }

    var in bytes.Buffer
    var out bytes.Buffer
    var e bytes.Buffer

    stdin := bufio.NewReader(&in)
    stdout := bufio.NewWriter(&out)
    stderr := bufio.NewWriter(&e)

    _, err = rmclient.RunWithInput(command, stdout, stderr, stdin)
    if err != nil {
        return "Error running command: " + err.Error()
    }

    if e.String() != "" {
        return e.String()
    }

    return out.String()
}

开发者ID:projectjane,项目名称:jane,代码行数:32,代码来源:winrm.go

示例4: RenderDetail

func RenderDetail(shdarray []*DP, t *template.Template, sh string) error {
    var hisName = time.Now().Format("2006-01-02")
    dshfilename := homeDir + "/changshi/today/detail_" + sh + ".html"
    if _, err := os.Stat(dshfilename); os.IsExist(err) {
        os.Remove(dshfilename)
    }
    dshf, _ := os.Create(dshfilename)
    dshfbw := bufio.NewWriter(dshf)
    err := t.ExecuteTemplate(dshfbw, "detail.tmpl", shdarray)
    if err != nil {
        return err
    }
    dshfbw.Flush()
    dshf.Close()

    dshhfilename := homeDir + "/changshi/his/d_" + sh + "_" + hisName + ".html"
    if _, err := os.Stat(dshhfilename); os.IsExist(err) {
        os.Remove(dshhfilename)
    }
    dshhf, _ := os.Create(dshhfilename)
    dshhfbw := bufio.NewWriter(dshhf)
    err1 := t.ExecuteTemplate(dshhfbw, "detail.tmpl", shdarray)
    if err1 != nil {
        return err
    }
    dshhfbw.Flush()
    dshhf.Close()
    return nil
}

开发者ID:wenxiaoyu,项目名称:traffic,代码行数:29,代码来源:main.go

示例5: writeOutput

func writeOutput(data []byte) {
    var output *bufio.Writer

    // prepare "output"
    if *out != "" {
        file, err := os.Open(*out, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
        checkOutputFailure(err)
        defer file.Close()

        output = bufio.NewWriter(file)
    } else {
        output = bufio.NewWriter(os.Stdout)
    }

    // write package clause if any
    if *pkg != "" {
        _, err := fmt.Fprintf(output, "package %s\n\n", *pkg)
        checkOutputFailure(err)
    }

    // write data
    writeData(data, output)

    // flush
    err := output.Flush()
    checkOutputFailure(err)
}

开发者ID:nsf,项目名称:goal,代码行数:27,代码来源:bin2go.go

示例6: TestQueue_sendMessageAfterUnsubscribe_messageReceivedSuccessfully

// A unsubscribing client should not be considered for message delivery
func TestQueue_sendMessageAfterUnsubscribe_messageReceivedSuccessfully(t *testing.T) {
    // Need gomega for async testing
    gomega.RegisterTestingT(t)

    testMessagePayload := []byte("Testing!")
    expectedMessagePayload := []byte("Testing!\r\n.\r\n")
    testMessage := message.NewHeaderlessMessage(&testMessagePayload)

    dummyMetricsPipe := make(chan<- *Metric, 10)
    dummyClosingPipe := make(chan<- *string)

    underTest := newMessageQueue(TEST_QUEUE_NAME, dummyMetricsPipe, dummyClosingPipe)

    writerBuffer1 := new(bytes.Buffer)
    dummyWriter1 := bufio.NewWriter(writerBuffer1)
    closedChannel1 := make(chan bool)
    dummyClient1 := Client{Name: "Test1", Writer: dummyWriter1, Closed: &closedChannel1}

    writerBuffer2 := new(bytes.Buffer)
    dummyWriter2 := bufio.NewWriter(writerBuffer2)
    closedChannel2 := make(chan bool)
    dummyClient2 := Client{Name: "Test2", Writer: dummyWriter2, Closed: &closedChannel2}

    // Add the subscription
    underTest.AddSubscriber(&dummyClient1)
    underTest.AddSubscriber(&dummyClient2)

    // Queue the message
    underTest.Publish(testMessage)

    // Bit of a hack - only one of the subscribers will get the message,
    // and we don't know which one
    gomega.Eventually(func() []byte {
        if writerBuffer1.String() == "" {
            return writerBuffer2.Bytes()
        } else {
            return writerBuffer1.Bytes()
        }
    }).Should(gomega.Equal(expectedMessagePayload))

    // We'll be reusing these buffers
    writerBuffer1.Reset()
    writerBuffer2.Reset()

    // Close one client
    *dummyClient1.Closed <- true

    // Should remove the client from the map
    gomega.Eventually(func() bool {
        return underTest.subscribers[dummyClient1.Name] == nil
    }).Should(gomega.BeTrue())

    // Now send a message - the remaining client should receive it without issue
    underTest.Publish(testMessage)

    gomega.Eventually(func() []byte {
        return writerBuffer2.Bytes()
    }).Should(gomega.Equal(expectedMessagePayload))

}

开发者ID:FireEater64,项目名称:gamq,代码行数:61,代码来源:messagequeue_test.go

示例7: main

func main() {
    // parse command line arguments and populate op, res, params, and flags
    initializeArgs()

    // set up file handle for results
    if *output != "" {
        fo, err := os.Create(*output)
        if err != nil {
            log.Critical("%s", err)
        }
        defer func() {
            if err := fo.Close(); err != nil {
                log.Critical("%s", err)
            }
        }()
        outfile = bufio.NewWriter(fo)
    } else {
        outfile = bufio.NewWriter(os.Stdout)
    }
    defer outfile.Flush()

    // set up logging and initialize log
    initializeLogger()
    // parse config file and populate env data structure
    initializeConfig()

    // bundle up the request into a data structure that can be easily marshaled
    createJSONRequest()

    // POST the request to the api, receive the results, and process them
    postRequest()
}

开发者ID:chadh,项目名称:buzzapi,代码行数:32,代码来源:main.go

示例8: main

func main() {
    proxy := goproxy.NewProxyHttpServer()
    proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*baidu.com$"))).
        HandleConnect(goproxy.AlwaysReject)
    proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*$"))).
        HandleConnect(goproxy.AlwaysMitm)
    // enable curl -p for all hosts on port 80
    proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("^.*:80$"))).
        HijackConnect(func(req *http.Request, client net.Conn, ctx *goproxy.ProxyCtx) {
            defer func() {
                if e := recover(); e != nil {
                    ctx.Logf("error connecting to remote: %v", e)
                    client.Write([]byte("HTTP/1.1 500 Cannot reach destination\r\n\r\n"))
                }
                client.Close()
            }()
            clientBuf := bufio.NewReadWriter(bufio.NewReader(client), bufio.NewWriter(client))
            remote, err := net.Dial("tcp", req.URL.Host)
            orPanic(err)
            remoteBuf := bufio.NewReadWriter(bufio.NewReader(remote), bufio.NewWriter(remote))
            for {
                req, err := http.ReadRequest(clientBuf.Reader)
                orPanic(err)
                orPanic(req.Write(remoteBuf))
                orPanic(remoteBuf.Flush())
                resp, err := http.ReadResponse(remoteBuf.Reader, req)
                orPanic(err)
                orPanic(resp.Write(clientBuf.Writer))
                orPanic(clientBuf.Flush())
            }
        })
    proxy.Verbose = true
    log.Fatal(http.ListenAndServe(":8080", proxy))
}

开发者ID:LivingInPortal,项目名称:goproxy,代码行数:34,代码来源:main.go

示例9: TestNewWriter

func TestNewWriter(t *testing.T) {
    Convey("Testing newWriter()", t, func() {

        tests := []struct {
            name   string
            exp    io.Writer
            expStr string
        }{
            {
                name: "vanilla",
                exp: func() io.Writer {
                    var b bytes.Buffer
                    return bufio.NewWriter(&b)
                }(),
                expStr: "Es ist Krieg!",
            },
        }
        for _, tt := range tests {
            act := NewWriter()
            Convey("Testing "+tt.name, func() {
                So(act, ShouldResemble, tt.exp)
                logIt(act, tt.expStr)
                var b bytes.Buffer
                want := bufio.NewWriter(&b)
                io.Copy(want, strings.NewReader(tt.expStr))
                So(act, ShouldResemble, want)
            })
        }
    })
}

开发者ID:britannic,项目名称:blacklist,代码行数:30,代码来源:data_test.go

示例10: generateProject

func generateProject(htmlSettings HtmlTemplateSettings, packageSettings PackageTemplateSettings) {
    htmlTemplate, _ := Asset("client/index.html")
    packageTemplate, _ := Asset("package.json")

    htmlTempl := template.Must(template.New("").Parse(string(htmlTemplate)))
    packageTempl := template.Must(template.New("").Parse(string(packageTemplate)))

    appFolder := packageSettings.AppName

    RestoreAssets(appFolder, "")

    htmlFile, _ := os.Create(path.Join(appFolder, "client", "index.html"))
    htmlFileWriter := bufio.NewWriter(htmlFile)
    defer func() {
        htmlFileWriter.Flush()
        htmlFile.Close()
    }()

    packageFile, _ := os.Create(path.Join(appFolder, "package.json"))
    packageFileWriter := bufio.NewWriter(packageFile)
    defer func() {
        packageFileWriter.Flush()
        packageFile.Close()
    }()

    htmlTempl.Execute(htmlFileWriter, htmlSettings)
    packageTempl.Execute(packageFileWriter, packageSettings)
}

开发者ID:hheld,项目名称:AltReactScaffolding,代码行数:28,代码来源:main.go

示例11: NewFile

func NewFile(fileName, fileType string, compress bool) (*File, error) {
    fullName := fileName + fileType

    if _, err := os.Stat(fullName); err == nil {
        os.Rename(fullName, fileName+".01"+fileType)
        fullName = fileName + ".02" + fileType
    } else if _, err := os.Stat(fileName + ".01" + fileType); err == nil {
        for fileId := 1; true; fileId++ {
            fullName = fileName + fmt.Sprintf(".%02d", fileId) + fileType
            if _, err := os.Stat(fullName); err != nil {
                break
            }
        }
    }

    f, err := os.OpenFile(fullName, os.O_WRONLY|os.O_CREATE, 0755)
    if err != nil {
        return nil, err
    }

    log := &File{f: f}
    if compress {
        log.bufio = bufio.NewWriter(log.f)
        log.gzip = gzip.NewWriter(log.bufio)
        log.json = json.NewEncoder(log.gzip)
    } else {
        log.bufio = bufio.NewWriter(log.f)
        log.json = json.NewEncoder(log.bufio)
    }

    return log, nil
}

开发者ID:sdgdsffdsfff,项目名称:jsonlog,代码行数:32,代码来源:file.go

示例12: initLogs

func (DS *MainSearch) initLogs(logdir string) {

    // open logs
    DS.logDir = logdir
    os.Mkdir(DS.logDir, os.ModePerm)
    tmpF0, err5 := os.Create(DS.logDir + "main:err.log")
    if err5 != nil {
        log.Fatal("couldn't create errs log", err5)
    }
    DS.errLogBuf = bufio.NewWriter(tmpF0)
    DS.errLogBuf.Flush()
    DS.errLog = log.New(DS.errLogBuf, "", log.LstdFlags)

    tmpF1, err1 := os.Create(DS.logDir + "main:main.log")
    if err1 != nil {
        log.Fatal("couldn't create main log", err1)
    }
    DS.mainLogBuf = bufio.NewWriter(tmpF1)
    DS.mainLogBuf.Flush()
    DS.mainLog = log.New(DS.mainLogBuf, "", log.LstdFlags)

    tmpF2, err2 := os.Create(DS.logDir + "main:eqns.log")
    if err2 != nil {
        log.Fatal("couldn't create eqns log", err2)
    }
    DS.eqnsLogBuf = bufio.NewWriter(tmpF2)
    DS.eqnsLogBuf.Flush()
    DS.eqnsLog = log.New(DS.eqnsLogBuf, "", log.LstdFlags)

}

开发者ID:verdverm,项目名称:go-pge,代码行数:30,代码来源:main_search.go

示例13: Dial

// Dial connects to server at address
func (handler *ConnHandler) Dial(addr string) ([]Peer, error) {
    var peers []Peer
    conn, err := net.Dial("tcp", addr)
    if err != nil {
        log.Println(err)
        return nil, err
    }
    writer := bufio.NewWriter(conn)
    reader := bufio.NewReader(conn)
    line, _ := reader.ReadString('\n')
    line = strings.Trim(line, "\n")
    addrs := strings.Split(line, ";")
    info := strings.Split(addrs[0], ",")
    writer.WriteString(handler.String() + "\n")
    writer.Flush()
    peers = append(peers, NewPeer(conn, conn, info[0], info[1]))
    for _, a := range addrs[1:] {
        info := strings.Split(a, ",")
        c, _ := net.Dial("tcp", info[0])
        writer = bufio.NewWriter(c)
        writer.WriteString(handler.String() + "\n")
        writer.Flush()
        reader = bufio.NewReader(c)
        line, _ = reader.ReadString('\n')
        peers = append(peers, NewPeer(c, c, info[0], info[1]))
    }
    return peers, nil
}

开发者ID:jpanda109,项目名称:gocc,代码行数:29,代码来源:connhandler.go

示例14: runShell

func runShell(command *Command, args []string) bool {
    r := bufio.NewReader(os.Stdin)
    o := bufio.NewWriter(os.Stdout)
    e := bufio.NewWriter(os.Stderr)
    prompt := func() {
        o.WriteString("> ")
        o.Flush()
    }
    readLine := func() string {
        ret, err := r.ReadString('\n')
        if err != nil {
            fmt.Fprint(e, err)
            os.Exit(1)
        }
        return ret
    }
    execCmd := func(cmd string) int {
        if cmd != "" {
            o.WriteString(cmd)
        }
        return 0
    }

    cmd := ""
    for {
        prompt()
        cmd = readLine()
        execCmd(cmd)
    }
    return true
}

开发者ID:abasse,项目名称:weed-fs,代码行数:31,代码来源:shell.go

示例15: main

func main() {
    addr, _ := net.ResolveTCPAddr("0.0.0.0:9009")
    go func() {
        l, _ := net.ListenTCP("tcp", addr)
        conn, _ := l.AcceptTCP()
        println("accepted")
        go func(c io.ReadWriter) {
            buf := make([]byte, N)
            b := bufio.NewReadWriter(bufio.NewReader(c), bufio.NewWriter(c))
            if n, e := b.Read(buf); e != nil || n < N {
                println("read", n, e.String())
                return
            }
            if n, e := b.Write(buf); n < N || e != nil {
                println("write", n, e.String())
            }
            b.Flush()
            time.Sleep(1)
        }(conn)
    }()
    time.Sleep(1e9)
    c, _ := net.DialTCP("tcp", nil, addr)
    println("connected")
    f := bufio.NewReadWriter(bufio.NewReader(c), bufio.NewWriter(c))
    b := make([]byte, N)
    if n, e := f.Write(b); n < N || e != nil {
        panic("write failed")
    }
    f.Flush()
    if n, e := f.Read(b); e != nil || n < N {
        println("read 2", n, e.String())
    }
}

开发者ID:haiger,项目名称:beansdb,代码行数:33,代码来源:main.go

示例16: saveKeydir

func saveKeydir(root string, kd *keydir, fileId int32) error {
    filename := fmt.Sprintf("%s_%d", keydirFilename, fileId)
    f, err := os.Create(filepath.Join(root, filename))
    if err != nil {
        return err
    }
    defer f.Close()

    bw := bufio.NewWriter(f)
    defer bw.Flush()

    sha1Bytes, err := writeKeydir(bw, kd)
    if err != nil {
        return err
    }

    filename = fmt.Sprintf("%s_%d", keydirSha1Filename, fileId)
    fsha, err := os.Create(filepath.Join(root, filename))
    if err != nil {
        return err
    }
    defer fsha.Close()

    bwsha := bufio.NewWriter(fsha)
    defer bwsha.Flush()

    _, err = bwsha.Write(sha1Bytes)
    return err
}

开发者ID:sbinet,项目名称:romba,代码行数:29,代码来源:keydirio.go

示例17: jwtConfigFromP12KeyFile

func jwtConfigFromP12KeyFile(pth, email string) (*jwt.Config, error) {
    cmd := cmdex.NewCommand("openssl", "pkcs12", "-in", pth, "-passin", "pass:notasecret", "-nodes")

    var outBuffer bytes.Buffer
    outWriter := bufio.NewWriter(&outBuffer)
    cmd.SetStdout(outWriter)

    var errBuffer bytes.Buffer
    errWriter := bufio.NewWriter(&errBuffer)
    cmd.SetStderr(errWriter)

    if err := cmd.Run(); err != nil {
        if !errorutil.IsExitStatusError(err) {
            return nil, err
        }
        return nil, errors.New(string(errBuffer.Bytes()))
    }

    return &jwt.Config{
        Email:      email,
        PrivateKey: outBuffer.Bytes(),
        TokenURL:   google.JWTTokenURL,
        Scopes:     []string{androidpublisher.AndroidpublisherScope},
    }, nil
}

开发者ID:bitrise-steplib,项目名称:steps-google-play-deploy,代码行数:25,代码来源:main.go

示例18: ExecWithLog

func (c *EtcdAdapter) ExecWithLog(cmd *exec.Cmd, i int) {
    stdoutPipe, err := cmd.StdoutPipe()
    check(err)
    stderrPipe, err := cmd.StderrPipe()
    check(err)

    outFile, err := os.Create(fmt.Sprintf("/tmp/etcd_%d.out", i))
    check(err)
    errFile, err := os.Create(fmt.Sprintf("/tmp/etcd_%d.err", i))
    check(err)

    outWriter := bufio.NewWriter(outFile)
    errWriter := bufio.NewWriter(errFile)

    defer outWriter.Flush()
    defer errWriter.Flush()

    // Start the command
    err = cmd.Start()
    check(err)

    go io.Copy(outWriter, stdoutPipe)
    go io.Copy(errWriter, stderrPipe)

    c.launchProcess <- cmd.Process

    cmd.Wait()
}

开发者ID:rlayte,项目名称:teardown,代码行数:28,代码来源:etcd_cluster.go

示例19: outputWriter

func outputWriter(outdir string, name string, ext string) (*bufio.Writer, *os.File, string, error) {
    sname := "anonymous"
    if strings.HasSuffix(outdir, ext) {
        name = filepath.Base(outdir)
        sname = name[:len(name)-len(ext)]
        outdir = filepath.Dir(outdir)
    }
    if name != "" {
        sname = name
    }
    if outdir == "" {
        return bufio.NewWriter(os.Stdout), nil, sname, nil
    }
    outfile := sname
    if !strings.HasSuffix(outfile, ext) {
        outfile += ext
    }
    path := filepath.Join(outdir, outfile)
    f, err := os.Create(path)
    if err != nil {
        return nil, nil, "", err
    }
    writer := bufio.NewWriter(f)
    return writer, f, sname, nil
}

开发者ID:dmitris,项目名称:ardielle-go,代码行数:25,代码来源:util.go

示例20: Push

func Push(devices []Transporter, local io.Reader, mode os.FileMode, modtime uint32, remote string) error {
    d := make([]io.Writer, 0, len(devices))
    for _, t := range devices {
        conn, err := GetPushWriter(t, remote, uint32(mode))
        if err != nil {
            return err
        }
        d = append(d, io.Writer(conn))
        defer conn.VerifyOk()
    }

    reader := bufio.NewReader(local)
    sections := NewSectionedMultiWriter(d...)
    writer := bufio.NewWriter(sections)
    writer.ReadFrom(reader)
    writer.Flush()
    sections.Close()

    wr := bufio.NewWriter(io.MultiWriter(d...))
    wr.WriteString("DONE")
    binary.Write(wr, binary.LittleEndian, modtime)
    wr.Flush()

    return nil
}

开发者ID:mehulsbhatt,项目名称:android-3,代码行数:25,代码来源:sync.go

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