Go - (Package) main

Card Puncher Data Processing


Language - (Main|Application Entry point) in Go.

Package main is special. It defines a standalone executable program, not a library.


Os.Args variable

  • Reprint the argument. Os.Args is an array
var s, sep string
for i := 1; i < len(os.Args); i++ {
	s += sep + os.Args[i]
	sep = " "

Argument Parsing with the flag package

package main

import (

var n = flag.Bool("n", false, "omit trailing newline")
var sep = flag.String("s", " ", "separator")

func main() {
	fmt.Print(strings.Join(flag.Args(), *sep))
	if !*n {

Documentation / Reference

Discover More
Card Puncher Data Processing
Go - Array

In each iteration of the loop, range produces a pair of values: the index and the value of the element at that index. Example: print of the main argument.
Card Puncher Data Processing
Go - Flag (Argument Parsing)

The Flag package to parse Go arguments passed to entry point of the application (main) To change the usage output, you need to overwrite the Usage variable. Example...
Card Puncher Data Processing
Go - Goroutine (concurrent function execution)

A goroutine is a concurrent function execution. A channel is a communication mechanism that allows one goroutine to pass values of a specified type to another goroutine. The function main runs in a goroutine...
Card Puncher Data Processing
Go - Variable

in Go Either the type or the = expression part may be omitted, but not both. If: the type is omitted, it is determined by the initializer expression. the expression is omitted, the initial...

Share this page:
Follow us:
Task Runner