Skip to content

Instantly share code, notes, and snippets.

@dviramontes
Created February 4, 2018 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dviramontes/45977d7b59bd5780372c34eb2daf3ab4 to your computer and use it in GitHub Desktop.
Save dviramontes/45977d7b59bd5780372c34eb2daf3ab4 to your computer and use it in GitHub Desktop.
// print name of calling program,
// list args passed each on a new line,
// print time elapsed
package main
import (
"fmt"
"os"
"strings"
"time"
)
func main() {
start := time.Now()
fmt.Println("binary's name => ", os.Args[0])
// op1
// ---
// s, sep := "", " "
// for i, arg := range os.Args[1:] {
// s = strconv.Itoa(i) + sep + arg
// fmt.Println(s)
// }
// op2
// ---
// (fastest but cant get reference to index ?)
fmt.Println(strings.Join(os.Args[1:], "\n"))
end := time.Now()
elapsed := end.Sub(start)
fmt.Println("time elapsed: " + elapsed.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment