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 chapter06/recipe09.
  2. Navigate to the directory.
  3. Create the comparison.go file with the following content:
        package main        import (          "bufio"          "crypto/md5"          "fmt"          "io"          "os"        )        var data = []struct {          name string          cont string          perm os.FileMode        }{          {"test1.file", "Hello\nGolang is great", 0666},          {"test2.file", "Hello\nGolang is great", 0666},          {"test3.file", "Not matching\nGolang is great\nLast line",           0666},        }        func main() {          files := []*os.File{}          for _, fData := range data {            f, err := os.Create(fData.name)            if err != nil {              panic(err)            }            defer f.Close()            _, err = io.WriteString(f, fData.cont)            if err != nil {              panic(err)            }            files = append(files, f)          }          // Compare by checksum          checksums := []string{} for _, f := ...

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