"github.com/jinzhu/now" ) func main() { time.Now() // 2020-08-31 22:04:25.54499 +0200 CEST m=+0.000405346 now.BeginningOfYear() // 2020-01-01 00:00:00 +0100 CET now.EndOfWeek() // 2020-09-05 23:59:59.999999999 +0200 CEST } Speaker notes: * Many pre-defined functions like EndOfWeek, StartOfWeek * Based on current time
"github.com/rickar/cal/v2" ) func main() { // ... t := time.Now() if c.IsWorkday(t) { // ... } if c.WorkdaysRemain(t) == 0 { // ... } } Speaker notes: * Interact with them * For example check if its the last workday so that you send out receipts, emails etc * Or is it holiday
) func main() { // Age of our users ages := stats.LoadRawData([]int{30, 35, 18, 25, 23, 27}) median, err := stats.Median(ages) if err != nil { // ... } _ = median // 26 } Speaker notes: * Sometimes you’ve to do statistic calculations * Almost all possible functions available
"github.com/mingrammer/commonregex" ) func main() { text := `John, please get that article on www.linkedin.com or www.xing.com.` _ = cregex.Links(text) // [www.linkedin.com www.xing.com] _ = cregex.Phones(`You can reach me at (519)-236-2723`) // [(519)-236-2723] } Speaker notes: * Sometimes you want to extract some parts out of a text * To filter spam or not allowed content
// ... c, err := location.CreateContainer("profile_pictures") if err != nil { // ... } // "i" created via os.Open and "s" via image.Stat().Size() _, err = c.Put("avatar.jpg", i, s, map[string]interface{}{}) if err != nil { // ... } } Speaker notes: * Create a container and add files to it * Later you can walk over containers, collect items and process them
"os" "github.com/corona10/goimagehash" ) func main() { file1, _ := os.Open("Poolbild.jpg") file2, _ := os.Open("Poolbild.jpg") defer file1.Close() defer file2.Close() img1, _ := jpeg.Decode(file1) img2, _ := jpeg.Decode(file2) hash1, _ := goimagehash.AverageHash(img1) hash2, _ := goimagehash.AverageHash(img2) distance, _ := hash1.Distance(hash2) // 0 } Speaker notes: * Use it if you want to know which users uses the same profile picture * You can calculate the hash for every image and later find duplicates easily * There are more hashing algorithms available
) func main() { // Generate a password that is 32 characters long with 10 digits, 2 symbols, allowing upper and lower case letters, disallowing repeat characters pass, err := password.Generate(32, 10, 2, false, false) if err != nil { // ... } _ = pass // 73g6QcNDj2BqH:FZiMeW`09ItV51EO84 } Speaker notes: * Based on requirements as described by AgileBits 1Password
) func main() { pool, _ := dockertest.NewPool("") // pulls an image, creates a container based on it and runs it resource, _ := pool.Run("mysql", "5.7", []string{"MYSQL_ROOT_PASSWORD=secret"}) } Speaker notes: * If you want not only to mock dependencies * Easily interact with Docker in integration tests
"log" ) func main() { // ... var err error var db *sql.DB if err = pool.Retry(func() error { db, _ = sql.Open("mysql", "...") return db.Ping() }); err != nil { ... } // Your code _ = pool.Purge(resource) } Speaker notes: * The retry is needed because you need to wait until the container is ready * Purge the container at the end