GopherSnippetsStar

Code snippets with tests and testable examples for the Go programming language

Conversions
How to convert int to string
HTTP
How to print a raw HTTP response
How to read an HTTP response status code
Interfaces
How to check if a type satisfies an interface at runtime
Logging
How to create multiple loggers
How to disable log output
How to include the filename and the line number in a logger output
Maps
How to copy a map
How to create a set using a map
Numbers
How to calculate the sum of multiple numbers
What is the maximum value of numeric types
Other
How to format Go code programmatically
How to print the binary representation of an integer
How to print the same variable multiple times using printf
Parser
How to parse comments from Go Code
Runtime
How to print Go version
How to print information about the operating system, architecture and pointer size
Slices
How to check if a slice contains a specific element
How to delete an element from a slice
How to filter a slice
How to find the maximum element of a slice
How to find the minimum element of a slice
How to remove duplicate elements from a slice
How to reverse a slice
How to shuffle a slice
How to split a slice in chunks
Strings
How to calculate the hamming distance between two strings
How to check if a string ends with a substring
How to check if a string is lowercase
How to check if a string is uppercase
How to check if a string starts with substring
How to check if string is valid JSON
How to concatenate strings
How to count the number of words in a string
How to define a custom string representation for a type
How to get the md5 checksum of a string
How to get the sha1 checksum of a string
How to get the sha256 checksum of a string
How to pretty print JSON
How to reverse a string
Testing
How to test a function that panics
Time
How to check that a time value is a specific day of the week
How to measure the execution time of a function

by psampaz - source code