当前位置: 首页>>代码示例>>Golang>>正文


Golang PipeWriter.Write方法代码示例

本文整理汇总了Golang中io.PipeWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:Golang PipeWriter.Write方法的具体用法?Golang PipeWriter.Write怎么用?Golang PipeWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.PipeWriter的用法示例。


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

示例1: PipeWriter

func PipeWriter(data map[string]interface{}) {
	w := io.PipeWriter{}
	defer w.Close()
	w.Write([]byte("pipeWriter"))
	// err := tpl.Execute(w, data)
	// if err != nil {
	// 	fmt.Println(err)
	// }

}
开发者ID:shaalx,项目名称:leetcode,代码行数:10,代码来源:ext.go

示例2: streamInput

func (s *GardenServer) streamInput(decoder *json.Decoder, in *io.PipeWriter, process garden.Process, connCloseCh chan struct{}) {
	for {
		var payload transport.ProcessPayload
		err := decoder.Decode(&payload)
		if err != nil {
			close(connCloseCh)
			in.CloseWithError(errors.New("Connection closed"))
			return
		}

		switch {
		case payload.TTY != nil:
			process.SetTTY(*payload.TTY)

		case payload.Source != nil:
			if payload.Data == nil {
				in.Close()
				return
			} else {
				_, err := in.Write([]byte(*payload.Data))
				if err != nil {
					return
				}
			}

		case payload.Signal != nil:
			s.logger.Info("stream-input-process-signal", lager.Data{"payload": payload})

			switch *payload.Signal {
			case garden.SignalKill:
				err = process.Signal(garden.SignalKill)
				if err != nil {
					s.logger.Error("stream-input-process-signal-kill-failed", err, lager.Data{"payload": payload})
				}
			case garden.SignalTerminate:
				err = process.Signal(garden.SignalTerminate)
				if err != nil {
					s.logger.Error("stream-input-process-signal-terminate-failed", err, lager.Data{"payload": payload})
				}
			default:
				s.logger.Error("stream-input-unknown-process-payload-signal", nil, lager.Data{"payload": payload})
				in.Close()
				return
			}

		default:
			s.logger.Error("stream-input-unknown-process-payload", nil, lager.Data{"payload": payload})
			in.Close()
			return
		}
	}
}
开发者ID:nagyistoce,项目名称:garden,代码行数:52,代码来源:request_handling.go

示例3: PipeWrite

func PipeWrite(pipeWriter *io.PipeWriter) {
	var (
		i   = 0
		err error
		n   int
	)
	data := []byte("Go语言学习园地")
	for _, err = pipeWriter.Write(data); err == nil; n, err = pipeWriter.Write(data) {
		i++
		if i == 3 {
			pipeWriter.CloseWithError(errors.New("输出3次后结束"))
		}
	}
	fmt.Println("close 后输出的字节数:", n, " error:", err)
}
开发者ID:cwen-coder,项目名称:study-gopkg,代码行数:15,代码来源:PipRW.go

示例4: readDat

func readDat(filename string, c chan io.Reader) {
	f, err := os.Open("testdata/webkit/" + filename)
	if err != nil {
		c <- pipeErr(err)
		return
	}
	defer f.Close()

	// Loop through the lines of the file. Each line beginning with "#" denotes
	// a new section, which is returned as a separate io.Reader.
	r := bufio.NewReader(f)
	var pw *io.PipeWriter
	for {
		line, err := r.ReadSlice('\n')
		if err != nil {
			if pw != nil {
				pw.CloseWithError(err)
				pw = nil
			} else {
				c <- pipeErr(err)
			}
			return
		}
		if len(line) == 0 {
			continue
		}
		if line[0] == '#' {
			if pw != nil {
				pw.Close()
			}
			var pr *io.PipeReader
			pr, pw = io.Pipe()
			c <- pr
			continue
		}
		if line[0] != '|' {
			// Strip the trailing '\n'.
			line = line[:len(line)-1]
		}
		if pw != nil {
			if _, err := pw.Write(line); err != nil {
				pw.CloseWithError(err)
				pw = nil
			}
		}
	}
}
开发者ID:WXB506,项目名称:golang,代码行数:47,代码来源:parse_test.go

示例5: importFile

func importFile(filename string) {
	file, err := os.Open(filename)

	if err != nil {
		log.Printf("Error: %v\n", err)
		return
	}
	defer file.Close()

	stats, _ := file.Stat()
	fileSize := stats.Size()

	log.Printf("Importing %v", filename)

	reader := bufio.NewReaderSize(file, 1024*1024)

	var resps = make(chan Response, 100)
	go handleResponses(filename, fileSize, resps)

	var pReader *io.PipeReader
	var pWriter *io.PipeWriter
	var i int
	for i = 0; err == nil; i++ {
		if i%250 == 0 {
			if pWriter != nil {
				pWriter.Close()
			}
			pReader, pWriter = io.Pipe()
			reqs <- Request{pReader, resps}
		}

		var line []byte
		line, err = reader.ReadBytes('\n')
		pWriter.Write(line)
	}

	if pWriter != nil {
		pWriter.Close()
	}

	if err != nil && err != io.EOF {
		log.Panicf("Scanner error: %v\n", err)
	}

	resps <- Response{nil, nil, true, i - 1}
}
开发者ID:chrislittle,项目名称:orchestrate-bulk-import,代码行数:46,代码来源:orcbulkimport.go

示例6: readTo

func (c *combinedReader) readTo(r io.Reader, w *io.PipeWriter) {
	p := make([]byte, 1e5)
	for {
		n, err := r.Read(p)
		if n > 0 {
			c.wlk.Lock()
			w.Write(p[:n])
			c.wlk.Unlock()
		}
		if err != nil {
			c.wlk.Lock()
			defer c.wlk.Unlock()
			c.closed++
			if c.closed == 2 {
				w.Close()
			}
			return
		}
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:20,代码来源:combine.go

示例7:

				config.Save()

				test_helpers.ExecuteCommandWithArgs(targetBlobCommand, []string{})

				Expect(outputBuffer).To(test_helpers.SayLine("Blob target not set"))
			})
		})

		Context("setting the blob target", func() {
			It("sets the blob target and credentials", func() {
				fakeTargetVerifier.VerifyBlobTargetReturns(true, nil)

				commandFinishChan := test_helpers.AsyncExecuteCommandWithArgs(targetBlobCommand, []string{"192.168.11.11:8980"})

				Eventually(outputBuffer).Should(test_helpers.Say("Access Key: "))
				stdinWriter.Write([]byte("yaykey\n"))
				Eventually(outputBuffer).Should(test_helpers.Say("Secret Key: "))
				stdinWriter.Write([]byte("superserial\n"))
				Eventually(outputBuffer).Should(test_helpers.Say("Bucket Name [condenser-bucket]: "))
				stdinWriter.Write([]byte("bhuket\n"))

				Eventually(commandFinishChan).Should(BeClosed())

				Expect(fakeTargetVerifier.VerifyBlobTargetCallCount()).To(Equal(1))
				host, port, accessKey, secretKey, bucketName := fakeTargetVerifier.VerifyBlobTargetArgsForCall(0)
				Expect(host).To(Equal("192.168.11.11"))
				Expect(port).To(Equal(uint16(8980)))
				Expect(accessKey).To(Equal("yaykey"))
				Expect(secretKey).To(Equal("superserial"))
				Expect(bucketName).To(Equal("bhuket"))
开发者ID:se77en,项目名称:lattice,代码行数:30,代码来源:blob_config_command_factory_test.go

示例8:

					Source:   "chug-test",
					Message:  "first-session.nested-session-2.modernify",
					Session:  "1.2",
					Data:     lager.Data{},
				}))
			})
		})
	})

	Context("handling lager JSON that is surrounded by non-JSON", func() {
		var input []byte
		var entry Entry

		BeforeEach(func() {
			input = []byte(`[some-component][e]{"timestamp":"1407102779.028711081","source":"chug-test","message":"chug-test.chug","log_level":0,"data":{"some-float":3,"some-string":"foo"}}...some trailing stuff`)
			pipeWriter.Write(input)
			pipeWriter.Write([]byte("\n"))

			Eventually(stream).Should(Receive(&entry))
		})

		It("should be a lager message", func() {
			Ω(entry.IsLager).Should(BeTrue())
		})

		It("should contain all the data in Raw", func() {
			Ω(entry.Raw).Should(Equal(input))
		})

		It("should succesfully parse the lager message", func() {
			Ω(entry.Log.Source).Should(Equal("chug-test"))
开发者ID:Doebe,项目名称:workplace,代码行数:31,代码来源:chug_test.go

示例9:

			})
		})

		Context("when the receptor requires authentication", func() {
			BeforeEach(func() {
				fakeTargetVerifier.VerifyTargetReturns(true, false, nil)
				fakeBlobStoreVerifier.VerifyReturns(true, nil)
				fakePasswordReader.PromptForPasswordReturns("testpassword")
			})

			It("prompts for credentials and stores them in the config", func() {
				doneChan := test_helpers.AsyncExecuteCommandWithArgs(targetCommand, []string{"myapi.com"})

				Eventually(outputBuffer).Should(test_helpers.Say("Username: "))
				fakeTargetVerifier.VerifyTargetReturns(true, true, nil)
				stdinWriter.Write([]byte("testusername\n"))

				Eventually(doneChan, 3).Should(BeClosed())

				Expect(config.Target()).To(Equal("myapi.com"))
				Expect(config.Receptor()).To(Equal("http://testusername:[email protected]"))
				Expect(outputBuffer).To(test_helpers.SayLine("API location set."))

				Expect(fakePasswordReader.PromptForPasswordCallCount()).To(Equal(1))
				Expect(fakePasswordReader.PromptForPasswordArgsForCall(0)).To(Equal("Password"))

				Expect(fakeTargetVerifier.VerifyTargetCallCount()).To(Equal(2))
				Expect(fakeTargetVerifier.VerifyTargetArgsForCall(0)).To(Equal("http://receptor.myapi.com"))
				Expect(fakeTargetVerifier.VerifyTargetArgsForCall(1)).To(Equal("http://testusername:[email protected]"))
			})
开发者ID:SrinivasChilveri,项目名称:lattice,代码行数:30,代码来源:config_command_factory_test.go

示例10:

		})
	})

	Describe("Input Methods", func() {
		Describe("Prompt", func() {
			It("Prompts the user for input", func() {
				answerChan := make(chan string)
				go func() {
					defer GinkgoRecover()

					answerChan <- terminalUI.Prompt("Nickname")
					close(answerChan)
				}()

				Eventually(outputBuffer).Should(test_helpers.Say("Nickname: "))
				stdinWriter.Write([]byte("RockStar\n"))

				Eventually(answerChan).Should(Receive(Equal("RockStar")))
				Eventually(answerChan).Should(BeClosed())
			})
		})

		Describe("PromptWithDefault", func() {
			It("Prompts the user for input", func() {
				answerChan := make(chan string)
				go func() {
					defer GinkgoRecover()

					answerChan <- terminalUI.PromptWithDefault("Nickname", "x")
					close(answerChan)
				}()
开发者ID:cloudfoundry-incubator,项目名称:ltc,代码行数:31,代码来源:ui_test.go

示例11:

				})
			})
		})

		Context("setting target that requires auth", func() {
			BeforeEach(func() {
				fakeTargetVerifier.VerifyTargetReturns(true, false, nil)
				fakePasswordReader.PromptForPasswordReturns("testpassword")
			})

			It("sets the api, username, password from the target specified", func() {
				commandFinishChan := test_helpers.AsyncExecuteCommandWithArgs(targetCommand, []string{"myapi.com"})

				Eventually(outputBuffer).Should(test_helpers.Say("Username: "))
				fakeTargetVerifier.VerifyTargetReturns(true, true, nil)
				stdinWriter.Write([]byte("testusername\n"))

				Eventually(commandFinishChan).Should(BeClosed())

				Expect(config.Target()).To(Equal("myapi.com"))
				Expect(config.Receptor()).To(Equal("http://testusername:[email protected]"))
				Expect(outputBuffer).To(test_helpers.Say("Api Location Set"))

				Expect(fakePasswordReader.PromptForPasswordCallCount()).To(Equal(1))
				Expect(fakePasswordReader.PromptForPasswordArgsForCall(0)).To(Equal("Password"))

				Expect(fakeTargetVerifier.VerifyTargetCallCount()).To(Equal(2))
				Expect(fakeTargetVerifier.VerifyTargetArgsForCall(0)).To(Equal("http://receptor.myapi.com"))
				Expect(fakeTargetVerifier.VerifyTargetArgsForCall(1)).To(Equal("http://testusername:[email protected]"))
			})
开发者ID:se77en,项目名称:lattice,代码行数:30,代码来源:config_command_factory_test.go

示例12:

			})
		})

		Context("when the receptor requires authentication", func() {
			BeforeEach(func() {
				fakeTargetVerifier.VerifyTargetReturns(true, false, nil)
				fakeBlobStoreVerifier.VerifyReturns(true, nil)
				fakePasswordReader.PromptForPasswordReturns("testpassword")
			})

			It("prompts for credentials and stores them in the config", func() {
				doneChan := test_helpers.AsyncExecuteCommandWithArgs(targetCommand, []string{"myapi.com"})

				Eventually(outputBuffer).Should(test_helpers.Say("Username: "))
				fakeTargetVerifier.VerifyTargetReturns(true, true, nil)
				stdinWriter.Write([]byte("testusername\n"))

				Eventually(doneChan).Should(BeClosed())

				Expect(config.Target()).To(Equal("myapi.com"))
				Expect(config.Receptor()).To(Equal("http://testusername:[email protected]"))
				Expect(outputBuffer).To(test_helpers.Say("API location set."))

				Expect(fakePasswordReader.PromptForPasswordCallCount()).To(Equal(1))
				Expect(fakePasswordReader.PromptForPasswordArgsForCall(0)).To(Equal("Password"))

				Expect(fakeTargetVerifier.VerifyTargetCallCount()).To(Equal(2))
				Expect(fakeTargetVerifier.VerifyTargetArgsForCall(0)).To(Equal("http://receptor.myapi.com"))
				Expect(fakeTargetVerifier.VerifyTargetArgsForCall(1)).To(Equal("http://testusername:[email protected]"))
			})
开发者ID:edwardt,项目名称:lattice,代码行数:30,代码来源:config_command_factory_test.go

示例13:

		It("returns empty slice and true", func() {
			out, finished := br.Next()
			Expect(out).To(BeEmpty())
			Expect(finished).To(BeTrue())
		})
	})

	Context("when there is a small amount of output and the writer is done", func() {
		var testFinished chan bool

		BeforeEach(func() {
			testFinished = make(chan bool)

			go func() {
				defer GinkgoRecover()
				_, err := writer.Write([]byte("Hello world!"))
				Expect(err).NotTo(HaveOccurred())
				Expect(writer.Close()).To(Succeed())
				testFinished <- true
			}()
			done = true
		})

		It("returns the output and true", func() {
			out, finished := br.Next()
			Expect(string(out)).To(Equal("Hello world!"))
			Expect(finished).To(BeTrue())
			<-testFinished
		})
	})
开发者ID:craigfurman,项目名称:Woodhouse-CI,代码行数:30,代码来源:chunked_reader_test.go


注:本文中的io.PipeWriter.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。