本文整理汇总了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('}')
}
}
}
示例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")
}
示例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()
}
示例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)
}
}
示例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{'/', '>'})
}
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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
}