O'Reilly logo

Go Programming Blueprints - Second Edition by Mat Ryer

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

The user command-line tool

The first of two tools we will build allows the user to add, list, and remove paths for the backup daemon tool (which we will write later). You can expose a web interface or even use the binding packages for the desktop user interface integration, but we are going to keep things simple and build ourselves a command-line tool.

Create a new folder called cmds inside the backup folder and create another backup folder inside that so you have backup/cmds/backup.

Inside our new backup folder, add the following code to main.go:

func main() { var fatalErr error defer func() { if fatalErr != nil { flag.PrintDefaults() log.Fatalln(fatalErr) } }() var ( dbpath = flag.String("db", "./backupdata", "path to database directory") ) flag.Parse() ...

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