This is a creation in Article, where the information may have evolved or changed.
The first item in "Go Language Programming" is Calc, which, according to the author's description in the book, runs without problems under Linux. However, after practice, the program can not print out the results described in the book.
After testing, it was found that the Windows command line performs calc Add 2 3 o'clock, which also takes Calc as a parameter, so that the subscript of the parameter array in the program is different from the one described in the book.
Now upload the revised program for your reference.
Calc.go
Package Mainimport "OS" import "FMT" import "Simplemath" import "StrConv" var Usage = func () {fmt. Println ("Usage:calc command [arguments] ...") fmt. Println ("\nthe commands are:\n\tadd\taddition of the values.\n\tsqrt\tsquare root of a non-negative value.")} Func main () {args: = os. Argsfmt.println ("args:", args)//print arguments, find some difference with it in the book if args = = Nil | | Len (args) < 2 {Usage () return}//arguments number is no sameswitch args[1] {case "add": If Len (args)! = 4 {//Arguments Number is not samefmt. Println ("Usage:calc add <integer1><integer2>") return}v1, err1: = StrConv. Atoi (args[2])//Arguments number is not samev2, err2: = StrConv. Atoi (args[3])//Arguments number is not sameif err1! = Nil | | Err2! = Nil {fmt. Println ("Usage:calc add <integer1><integer2>") Return}ret: = Simplemath. ADD (v1, v2) fmt. Println ("Result:", ret) case "sqrt": If Len (args)! = 3 {//Arguments number is not samefmt. Println ("Usage:calc sqrt <integer>") return}V, err: = StrConv. Atoi (args[2]) if err! = Nil {fmt. Println ("Usage:calc sqrt <integer>") Return}ret: = Simplemath. Sqrt (v) fmt. Println ("Result:", ret) Default:usage ()}}