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


Golang Writer.WriteString方法代码示例

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


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

示例1: writeData

// Write internal data structure to stream writer.
func (d *Data) writeData(wrt *bufio.Writer, level int) {

	// emit name (if defined)
	if len(d.Name) > 0 {
		wrt.WriteString(d.Name)
		wrt.WriteRune('=')
	}
	// handle value..
	if d.Len() == 0 {
		// .. as direct value
		wrt.WriteRune('"')
		wrt.WriteString(d.Value)
		wrt.WriteRune('"')
	} else {
		// .. as list of data
		if level > 0 {
			wrt.WriteRune('{')
		}
		// handle all list elements...
		count := d.Len()
		for n := 0; n < count; n++ {
			// emit delimiter
			if n > 0 {
				wrt.WriteRune(',')
			}
			// recursively write list element
			s := d.At(n).(*Data)
			s.writeData(wrt, level+1)
		}
		if level > 0 {
			wrt.WriteRune('}')
		}
	}
}
开发者ID:bfix,项目名称:gospel,代码行数:35,代码来源:data.go

示例2: new_line

func new_line(fw *bufio.Writer, email string, dest string) {
	pad := 40 - len(email)
	if pad <= 0 {
		pad = 1
	}
	fw.WriteString(email + strings.Repeat(" ", pad) + dest + "\n")
}
开发者ID:fazalmajid,项目名称:postmapweb,代码行数:7,代码来源:postmapweb.go

示例3: outputResults

func (r Resolver) outputResults(w *bufio.Writer, results gresults) {
	var zip, city, state, stateName, county, country, countryName string
	var latitude, longitude float32

	var comp addressComponent
	var err error
	for _, res := range results.Results {
		if comp, err = res.findAddressComponent(zipType); err == nil {
			zip = comp.LongName
		}
		if comp, err = res.findAddressComponent(cityType); err == nil {
			city = comp.LongName
		}
		if comp, err = res.findAddressComponent(countyType); err == nil {
			county = comp.LongName
		}
		if comp, err = res.findAddressComponent(stateType); err == nil {
			state = strings.ToUpper(comp.ShortName)
			stateName = comp.LongName
		}
		if comp, err = res.findAddressComponent(countryType); err == nil {
			country = strings.ToUpper(comp.ShortName)
			countryName = comp.LongName
		}
		latitude = res.Geometry.Location.Lat
		longitude = res.Geometry.Location.Lng
	}
	w.WriteString(fmt.Sprintf("%v,\"%v\",\"%v\",\"%v\",\"%v\",\"%v\",\"%v\",%v,%v\n", country, zip, city, state, stateName, county, countryName, latitude, longitude))
	w.Flush()
}
开发者ID:rchargel,项目名称:zilch,代码行数:30,代码来源:resolver.go

示例4: writeToServer

//take input from srvChan and send to server
func writeToServer(w *bufio.Writer, srvChan chan string, wg *sync.WaitGroup, quit chan bool, quitChans chan chan bool) {
	defer wg.Done()
	defer fmt.Println("WTS") //debug

	_, err := w.WriteString("PING" + config.Nick + "\r\n") //test message. primarily to get to select loop
	if err == nil {
		err = w.Flush()
	}
	//send all lines in srvChan to server
	for err == nil {
		select {
		case <-quit: //exit if indicated
			return
		case str := <-srvChan:
			_, err = w.WriteString(str + "\r\n")
			if err == nil {
				err = w.Flush()
			}
		}
	}

	//print error and exit
	if err != nil {
		errOut(err, quitChans)
	}
}
开发者ID:heydabop,项目名称:yaircb,代码行数:27,代码来源:irc.go

示例5: writeTo

// writeTo serializes the element to the writer w.
func (e *Element) writeTo(w *bufio.Writer) {
	w.WriteByte('<')
	if e.Space != "" {
		w.WriteString(e.Space)
		w.WriteByte(':')
	}
	w.WriteString(e.Tag)
	for _, a := range e.Attr {
		w.WriteByte(' ')
		a.writeTo(w)
	}
	if len(e.Child) > 0 {
		w.WriteString(">")
		for _, c := range e.Child {
			c.writeTo(w)
		}
		w.Write([]byte{'<', '/'})
		if e.Space != "" {
			w.WriteString(e.Space)
			w.WriteByte(':')
		}
		w.WriteString(e.Tag)
		w.WriteByte('>')
	} else {
		w.Write([]byte{'/', '>'})
	}
}
开发者ID:hzmnet,项目名称:etree,代码行数:28,代码来源:etree.go

示例6: createGroup

func createGroup(r *bufio.Reader, w *bufio.Writer, args []string, thisUser *utils.User) (err error) {

	if len(args) == 1 {
		fmt.Println("No arguments for call to create-group.")
		return nil
	}

	err = w.WriteByte(20)
	w.Flush()
	if err != nil {
		return err
	}

	// send the length of args
	err = w.WriteByte(uint8(len(args)))
	w.Flush()
	if err != nil {
		return err
	}

	for i := 1; i < len(args); i++ {

		// send group to create
		w.WriteString(args[i] + "\n")
		w.Flush()

		// get group id to display to user
		gid, _ := r.ReadString('\n')
		fmt.Println("Created group \"" + args[i] + "\" with id: " + strings.TrimSpace(gid))
	}
	// send the group to create

	return err
}
开发者ID:CPSSD,项目名称:MDFS,代码行数:34,代码来源:mdfs-client.go

示例7: doWriteString

func doWriteString(w *bufio.Writer) {
	if written, err := w.WriteString(", The Standard Library\n"); err != nil {
		log.Fatalf("failed writing string: %s", err)
	} else {
		log.Printf("Wrote string in %d bytes", written)
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:writing.go

示例8: Write

// Write embeddings to a binary file accepted by word2vec
func (e *Embeddings) Write(w *bufio.Writer) error {
	nWords := len(e.words)
	if nWords == 0 {
		return nil
	}

	if e.embedSize == 0 {
		return nil
	}

	if _, err := fmt.Fprintf(w, "%d %d\n", nWords, e.embedSize); err != nil {
		return err
	}

	for idx, word := range e.words {
		if _, err := w.WriteString(word + " "); err != nil {
			return err
		}

		if err := binary.Write(w, binary.LittleEndian, e.lookupIdx(idx)); err != nil {
			return err
		}

		w.WriteByte(0x0a)
	}

	return nil
}
开发者ID:postfix,项目名称:go2vec,代码行数:29,代码来源:go2vec.go

示例9: do

func (proto *LineProtoTriple) do(w *bufio.Writer, r *bufio.Reader) (err error) {
	var line string
	re := regexp.MustCompile(proto.GreetMatch)
	for {
		if line, err = r.ReadString('\n'); err != nil {
			return
		}
		line = strings.TrimRight(line, "\r")

		if re.MatchString(line) {
			break
		}
	}

	if _, err = w.WriteString(proto.AuthReq + "\r\n"); err != nil {
		return
	}
	if err = w.Flush(); err != nil {
		return
	}

	if line, err = r.ReadString('\n'); err != nil {
		return
	}
	line = strings.TrimRight(line, "\r")

	re = regexp.MustCompile(proto.ResponseMatch)
	if !re.MatchString(line) {
		return errors.New("Server does not support STARTTLS (" + strings.TrimSpace(line) + ")")
	}

	return
}
开发者ID:nunogt,项目名称:Heartbleed,代码行数:33,代码来源:starttls.go

示例10: writeFrame

/*
	Frame physical write.
*/
func (f *Frame) writeFrame(w *bufio.Writer, l string) error {
	// Write the frame Command
	if _, e := w.WriteString(f.Command + "\n"); e != nil {
		return e
	}
	// Content length - Always add it if client does not suppress it and
	// does not supply it.
	if _, ok := f.Headers.Contains("suppress-content-length"); !ok {
		if _, clok := f.Headers.Contains("content-length"); !clok {
			f.Headers = append(f.Headers, "content-length", strconv.Itoa(len(f.Body)))
		}
	}
	// Write the frame Headers
	for i := 0; i < len(f.Headers); i += 2 {
		if l > SPL_10 && f.Command != CONNECT {
			f.Headers[i] = encode(f.Headers[i])
			f.Headers[i+1] = encode(f.Headers[i+1])
		}
		_, e := w.WriteString(f.Headers[i] + ":" + f.Headers[i+1] + "\n")
		if e != nil {
			return e
		}
	}
	// Write the last Header LF
	if e := w.WriteByte('\n'); e != nil {
		return e
	}
	// Write the body
	if len(f.Body) != 0 { // Foolish to write 0 length data
		if _, e := w.Write(f.Body); e != nil {
			return e
		}
	}
	return nil
}
开发者ID:danieltmiles,项目名称:stompngo,代码行数:38,代码来源:writer.go

示例11: SaveCache

// Write a FileAttr object to cache file.
func (me *FileAttr) SaveCache(writer *bufio.Writer) error {
	str := fmt.Sprintf("%v|%v|%v|%v\n",
		me.Path, me.ModTime, me.Size, &me.SHA256)

	_, err := writer.WriteString(str)
	return err
}
开发者ID:toalexjin,项目名称:dedup,代码行数:8,代码来源:scan.go

示例12: write

/**
 * Write long data packet
 */
func (pkt *packetLongData) write(writer *bufio.Writer) (err os.Error) {
	// Construct packet header
	pkt.header = new(packetHeader)
	pkt.header.length = 7 + uint32(len(pkt.data))
	pkt.header.sequence = pkt.sequence
	err = pkt.header.write(writer)
	if err != nil {
		return
	}
	// Write command
	err = writer.WriteByte(byte(pkt.command))
	if err != nil {
		return
	}
	// Write statement id
	err = pkt.writeNumber(writer, uint64(pkt.statementId), 4)
	if err != nil {
		return
	}
	// Write param number
	err = pkt.writeNumber(writer, uint64(pkt.paramNumber), 2)
	if err != nil {
		return
	}
	// Write data
	_, err = writer.WriteString(pkt.data)
	if err != nil {
		return
	}
	// Flush
	err = writer.Flush()
	return
}
开发者ID:thomaslee,项目名称:GoMySQL,代码行数:36,代码来源:mysql_packet.go

示例13: WriteResponse

func (r *AsyncResponse) WriteResponse(buf *bufio.Writer) error {
	_, err := buf.WriteString("+ASYNC ")
	_, err = buf.WriteString(r.asyncID)
	err = buf.WriteByte(' ')
	err = r.resp.WriteResponse(buf)
	return err
}
开发者ID:vburenin,项目名称:firempq,代码行数:7,代码来源:response.go

示例14: newlineStream

func newlineStream(dst *bufio.Writer, prefix, indent string, depth int) {
	dst.WriteByte('\n')
	dst.WriteString(prefix)
	for i := 0; i < depth; i++ {
		dst.WriteString(indent)
	}
}
开发者ID:QianChenglong,项目名称:json,代码行数:7,代码来源:indent.go

示例15: deleteGroup

func deleteGroup(r *bufio.Reader, w *bufio.Writer, args []string, thisUser *utils.User) (err error) {

	if len(args) < 2 {
		fmt.Println("Not enough arguments for call to group-remove:")
		fmt.Println("Format should be: delete-group GID")
		return nil
	}

	err = w.WriteByte(24)
	w.Flush()
	if err != nil {
		return err
	}

	w.WriteString(args[1] + "\n")
	w.Flush()

	// get success (1) or fail (2)
	success, _ := r.ReadByte()
	if success != 1 {
		fmt.Println("You cannot remove this group. Does it exist/are you the owner?")
		return err
	}

	fmt.Println("Removed: " + args[1])

	return err
}
开发者ID:CPSSD,项目名称:MDFS,代码行数:28,代码来源:mdfs-client.go


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