import ( "bytes" "fmt" ) func main() { var buffer bytes.Buffer buffer.WriteString("Hello, ") buffer.WriteString("World!") fmt.Println(buffer.String()) buffer.Reset() buffer.WriteString("Goodbye, ") buffer.WriteString("World!") fmt.Println(buffer.String()) }
Hello, World! Goodbye, World!
import ( "bytes" "fmt" ) func main() { data := []byte("Hello, World!") var buffer bytes.Buffer buffer.Write(data) fmt.Println(buffer.String()) buffer.Reset() fmt.Println(buffer.String()) }
Hello, World!In the first example, we use the `bytes` package library to create a buffer, write some data to it, reset it and write some more data to it. The result is printed to the console. In the second example, we create a byte slice and use it to initialize a buffer. We then write some data to the buffer and reset it. The result is printed to the console. Package library: bytes