This is a creation in Article, where the information may have evolved or changed.
Whether it's a C or Golang language or any other language, you can start the application with some parameters, and then the system works according to the parameters that are passed in. such as:./main-b/home/backupdir-d True
So how to better parse these parameters? The first two weeks of doing your own project are through the range OS. Args to parse these parameters. I saw flag today. String This method, feel that before doing a good silly, feel more should use Golang own flag. String to parse the parameter.
1 Package Main2 3 Import (4 "Flag"5 "FMT"6 )7 8 Func Main () {9Backup_dir: = flag. String ("b","/home/default_dir","Backup Path")TenDebug_mode: = flag. Bool ("D",false,"Debug Mode") One A flag. Parse () - -Fmt. Println ("Backup_dir:", *Backup_dir) theFmt. Println ("Debug_mode:", *Debug_mode) - } - - /** + Start command: Go run Main.go-b/home/backup - Output Result: + Backup_dir:/home/backup//The default path is overwritten because a path is specified A debug_mode:false//Start command with the-d parameter, so enable default values at */