Reverting a file's history – command line

The final component we'd like to add to this application suite is a command-line file revision process. We can keep this one fairly simple, as we know where a file is located, where its backups are located, and how to replace the former with the latter. As with before, we have some global configuration variables and a replication of our generateHash() function:

var liveFolder = "/mnt/sharedir " var backupFolder = "/mnt/backup func generateHash(name string) string { hash := md5.New() io.WriteString(hash,name) hashString := hex.EncodeToString(hash.Sum(nil)) return hashString } func main() { revision := flag.Int("r",0,"Number of versions back") fileName := flag.String("f","","File Name") flag.Parse() if *fileName ...

Get Go: Building Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.