O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter03/recipe12.
  2. Navigate to the directory.
  1. Create the content.dat file with the following content:
        This is content to check
  1. Create the checksum.go file with the following content:
        package main        import (          "crypto/md5"          "fmt"          "io"          "os"        )        var content = "This is content to check"         func main() {          checksum := MD5(content)          checksum2 := FileMD5("content.dat")          fmt.Printf("Checksum 1: %s\n", checksum)          fmt.Printf("Checksum 2: %s\n", checksum2)          if checksum == checksum2 {            fmt.Println("Content matches!!!")          }        }        // MD5 creates the md5        // hash for given content encoded in        // hex string        func MD5(data string) string {          h := md5.Sum([]byte(data))          return fmt.Sprintf("%x", h)        } // FileMD5 creates hex ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required