All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to Use bytes.Buffer in Golang

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. ...
ada

How to Encrypt and Decrypt a String Using AES GCM 256 in Go

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...
Tomoki

How to Convert a Bool to a String in Go

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...
Tomoki

How to Generate a UUID in Go

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...
Sambhav Khandelwal

How to Convert Byte Array to String in Go

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("%...
Tomoki

How to find the type of an object in Go

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...
Patcher56

How to format a date or time in Go

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...
aweis

How to convert an int to a string type in Go

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...
aweis

How to format byte size as kilobytes, megabytes in Go

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...
Sambhav Khandelwal

How to format a string in PHP

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...
Patcher56

How to handle If-modified-since header in PHP

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...
Patcher56

How to get content from a url in Go

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...
Patcher56

How to use fmt.Sprintf Function in Go

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...
Sambhav Khandelwal

How to convert interface to int64 in Go

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 ...
ada

How to convert interface to string in Go

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 ...
pooriabt