Skip to content

Commit 1c6bb3e

Browse files
committed
add helloworld program
1 parent 2473b97 commit 1c6bb3e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

helloworld/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module helloworld
2+
3+
go 1.20

helloworld/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
// main is like any other programming language,
9+
// is the application's entry point.
10+
// Exactly 1 definition of this function is required in main package
11+
func main() {
12+
// check user has provided any
13+
// https://pkg.go.dev/os@go1.20.5#Args
14+
// https://pkg.go.dev/builtin#len
15+
if len(os.Args) > 1 {
16+
// take the second element of the array and print hello to user
17+
// https://pkg.go.dev/fmt@go1.20.5#Printf
18+
fmt.Printf("Hello, %s\n", os.Args[1])
19+
} else {
20+
// if no argument is provided, print message with new line
21+
// https://pkg.go.dev/fmt@go1.20.5#Println
22+
fmt.Println("Hello Guest")
23+
}
24+
}

0 commit comments

Comments
 (0)