Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 67 lines (53 sloc) 1.431 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
package utils

import (
"bytes"
"fmt"
"io"
"strconv"
)

type StringBuilder struct {
buffer bytes.Buffer
}

func (self *StringBuilder) Write(strings ...string) *StringBuilder {
for _, str := range strings {
self.buffer.WriteString(str)
}
return self
}

func (self *StringBuilder) Printf(format string, args ...interface{}) *StringBuilder {
fmt.Fprintf(&self.buffer, format, args...)
return self
}

func (self *StringBuilder) Byte(value byte) *StringBuilder {
self.buffer.WriteByte(value)
return self
}

func (self *StringBuilder) WriteBytes(bytes []byte) *StringBuilder {
self.buffer.Write(bytes)
return self
}

func (self *StringBuilder) Int(value int) *StringBuilder {
self.buffer.WriteString(strconv.Itoa(value))
return self
}

func (self *StringBuilder) Uint(value uint) *StringBuilder {
self.buffer.WriteString(strconv.FormatUint(uint64(value), 10))
return self
}

func (self *StringBuilder) Float(value float64) *StringBuilder {
self.buffer.WriteString(strconv.FormatFloat(value, 'f', -1, 64))
return self
}

func (self *StringBuilder) Bool(value bool) *StringBuilder {
self.buffer.WriteString(strconv.FormatBool(value))
return self
}

func (self *StringBuilder) WriteTo(writer io.Writer) (n int64, err error) {
return self.buffer.WriteTo(writer)
}

func (self *StringBuilder) Bytes() []byte {
return self.buffer.Bytes()
}

func (self *StringBuilder) String() string {
return self.buffer.String()
}
Something went wrong with that request. Please try again.