github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume1/section2/repeatgreetings/repeatgreetings.go (about)

     1  // An example of using a command line argument.
     2  package main
     3  
     4  import (
     5  	"fmt"
     6  	"log"
     7  	"os"
     8  	"strconv"
     9  )
    10  
    11  func main() {
    12  
    13  	var repeatCount int
    14  	var err error
    15  
    16  	if len(os.Args) >= 2 {
    17  		repeatCount, err = strconv.Atoi(os.Args[1])
    18  		if err != nil {
    19  			log.Fatal(err)
    20  		}
    21  
    22  		for i := 0; i < repeatCount; i++ {
    23  			fmt.Println("Hello Gopher!")
    24  		}
    25  
    26  	}
    27  
    28  }