package main import ( "bytes" "fmt" ) func main() { buffer := bytes.Buffer{} buffer.WriteByte('G') buffer.WriteByte('o') buffer.WriteByte('l') buffer.WriteByte('a') buffer.WriteByte('n') buffer.WriteByte('g') fmt.Println(buffer.String()) }
package main import ( "bytes" "io" "os" ) func main() { buffer := bytes.Buffer{} buffer.WriteByte('H') buffer.WriteByte('e') buffer.WriteByte('l') buffer.WriteByte('l') buffer.WriteByte('o') io.Copy(os.Stdout, &buffer) }This example creates a new buffer, writes the characters "Hello" to it using the `WriteByte` method, and then copies the contents of the buffer to the standard output using the `io.Copy` function. In conclusion, the `bytes.Buffer` package from the Go standard library provides the `WriteByte` method to write a single byte to an existing buffer. The examples demonstrated its use in writing characters to a buffer and printing or copying the contents of the buffer.