Golang bytes.Buffer Examples
Examples of Golang bytes.Buffer
The bytes package provides the Buffer type for efficient manipulation of byte slices. A Buffer starts out empty but grows as data of types like string, byte, and []byte are written to it.
...
In Golang, using the crypto/aes package is the easiest way to encrypt a string using AES GCM 256.
In cryptography, Galois/Counter Mode (GCM) is a mode of operation for symmetric-key cryptographic block ciphers which is widely adopted for its performa...
In Golang, there are 2 ways to convert a bool to a string.
Using strconv.FormatBool Function
The strconv.FormatBool() function returns "true" or "false" according to the value of b. For example,
package main
import (
"fmt"
"strconv"
)
fun...
In Golang, there are 4 ways to generate a uuid.
Using uuid Package
install
Use the following command to download the repository to the local file system.
install
go mod tidy
go get github.com/google/uuid
go install github.com...
In Golang, there are 2 ways to convert byte array to string.Using string Function
The easiest way to convert []byte to string in Golang:
package main
import "fmt"
func main() {
b := []byte{'a', 'b', 'c'}
s := string(b[:])
fmt.Printf("%...
In Golang, there are three ways to find the type of an object.Using fmt.Sprintf Function
You can use fmt.Sprintf function to get a string representation. For example,
package main
import "fmt"
func main() {
i := 10
f := 2.0
var m map[s...
In Golang, there are two ways to format the time.The layout string
Go doesn’t use yyyy-mm-dd layout to format a time. Instead, you format a special layout parameter.
2006-01-02 15:04:05.999999999 -0700 MST
package main
import (
"fmt"
"tim...
3 ways to convert int64 to string in Golang.Using strconv.Itoa Function
The code snippet below shows how to convert an int to a string using the Itoa function.
package main
import (
"fmt"
"strconv"
)
func main() {
s := strconv.Itoa(100)
f...
Convert File Size to a human friendly format.Get file size in human-readable units like kilobytes (KB), Megabytes (MB) or GigaBytes (GB)
SI (Decimal 1 k = 1,000)
A metric prefix is a unit prefix that precedes a basic unit of measure to indicate a mul...
Formatting PHP Strings with printf and sprintf.
Using sprintf Function
The sprintf() return a formatted string.
sprintf(string $format, mixed ...$values): string
// iPhone 14 Pro
echo sprintf("%s %d Pro\n", "iPhone", 14);
// iPhone 14 Pro
prin...
Reduce Bandwidth Usage by Supporting If-Modified-Since in PHP.
If-Modified-Since
The If-Modified-Since request HTTP header makes the request conditional: the server sends back the requested resource, with a 200 status, only if it has been last modif...
Reading from a url resource in Go.Fetching a URL
Go provides a collection of packages, grouped under net, that make it easy to send and receive information through the Internet. Package http provides HTTP client and server implementations.
packag...
Format a string without printing in Go.Basics
Package fmt implements formatted I/O with functions analogous to C's printf and scanf. The format 'verbs' are derived from C's but are simpler.
fmt.Sprintf
Sprintf formats according to a format specif...
Interface variable conversion in Golang.Type Assertion
To convert interface to int64 in Go, Using Type Assertion.
A type assertion provides access to an interface value's underlying concrete value.
package main
import "fmt"
// t := i.(T)
// t, ok ...
Type casting an interface to a string in go.Using fmt.Sprintf Function
To convert interface to string in Go, use fmt.Sprintf function.
Sprintf formats according to a format specifier and returns the resulting string.
package main
import "fmt"
var ...