Go - (Package) main

1 - About

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

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

3 - Argument

3.1 - 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 = " "
}
fmt.Println(s)

3.2 - Argument Parsing with the flag package


package main

import (
	"flag"
	"fmt"
	"strings"
)

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

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

4 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap