Skip to content

Instantly share code, notes, and snippets.

@maciakl
Last active October 1, 2024 01:41
Show Gist options
  • Save maciakl/b5877bcb8b1ad21e2e798d3da3bff13b to your computer and use it in GitHub Desktop.
Save maciakl/b5877bcb8b1ad21e2e798d3da3bff13b to your computer and use it in GitHub Desktop.
Hello World in Go
package main
import (
"os"
"fmt"
"path/filepath"
)
const version = "0.1.0"
func main() {
if len(os.Args) > 1 {
switch os.Args[1] {
case "-v", "--version":
Version()
case "-h", "--help":
Usage()
default:
Usage()
}
} else {
Usage()
}
}
func Version() {
fmt.Println(filepath.Base(os.Args[0]), "version", version)
os.Exit(0)
}
func Usage() {
fmt.Println("Usage:", filepath.Base(os.Args[0]), "[options]")
fmt.Println("Options:")
fmt.Println(" -v, --version Print version information and exit")
fmt.Println(" -h, --help Print this message and exit")
os.Exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment