Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Demonstrate common go tool commands via code comments and a real program. // $ go build -o myapp . — compile to binary named "myapp" // $ go run main.go — compile and run in one step // $ go test ./... — run all tests recursively // $ go fmt ./... — format all Go files // $ go vet ./... — static analysis // $ go mod tidy — add/remove module dependencies // $ go doc fmt.Println — show docs for fmt.Println package main import ( "flag" "fmt" "log" "os" ) func main() { // flag demonstrates idiomatic Go CLI argument parsing name := flag.String("name", "world", "whom to greet") verbose := flag.Bool("v", false, "enable verbose output") flag.Parse() if *verbose { log.SetOutput(os.Stderr) log.Printf("Running with name=%q ", *name) } fmt.Printf("Hello, %s! ", *name) } // Build and run: // $ go build -o greet . // $ ./greet -name=Go -v
Result
Open