From 679561226804825f1696fe1285c129dbed1e39f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Fri, 22 Jul 2022 13:07:16 +0200 Subject: [PATCH] Initial version of golang examples. --- README.md | 3 +++ control_blocks/go.mod | 3 +++ hello/go.mod | 3 +++ hello/hello.go | 7 +++++++ rand/go.mod | 3 +++ rand/rand.go | 21 +++++++++++++++++++++ time/go.mod | 3 +++ time/time.go | 11 +++++++++++ 8 files changed, 54 insertions(+) create mode 100644 README.md create mode 100644 control_blocks/go.mod create mode 100644 hello/go.mod create mode 100644 hello/hello.go create mode 100644 rand/go.mod create mode 100644 rand/rand.go create mode 100644 time/go.mod create mode 100644 time/time.go diff --git a/README.md b/README.md new file mode 100644 index 0000000..ecd8a63 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Golang examples repository + +TODO diff --git a/control_blocks/go.mod b/control_blocks/go.mod new file mode 100644 index 0000000..74ae74c --- /dev/null +++ b/control_blocks/go.mod @@ -0,0 +1,3 @@ +module examples/control_blocks + +go 1.16 diff --git a/hello/go.mod b/hello/go.mod new file mode 100644 index 0000000..46f9ec0 --- /dev/null +++ b/hello/go.mod @@ -0,0 +1,3 @@ +module examples/hello + +go 1.18 diff --git a/hello/hello.go b/hello/hello.go new file mode 100644 index 0000000..944e173 --- /dev/null +++ b/hello/hello.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello World!!!") +} diff --git a/rand/go.mod b/rand/go.mod new file mode 100644 index 0000000..ab57db0 --- /dev/null +++ b/rand/go.mod @@ -0,0 +1,3 @@ +module examples/rand + +go 1.16 diff --git a/rand/rand.go b/rand/rand.go new file mode 100644 index 0000000..d1eeb9b --- /dev/null +++ b/rand/rand.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "math/rand" +) + +func swap(x, y string) (string, string) { + return y, x; +} + +func add(x int, y int) int { + return x + y; +} + +func main() { + fmt.Println("My favourite number is", rand.Intn(10)) + fmt.Println("Sum is", add(4, 5)) + a, b := swap("Hello", "World") + fmt.Println("A: ", a, "B: ", b) +} diff --git a/time/go.mod b/time/go.mod new file mode 100644 index 0000000..5b2a085 --- /dev/null +++ b/time/go.mod @@ -0,0 +1,3 @@ +module examples/time + +go 1.16 diff --git a/time/time.go b/time/time.go new file mode 100644 index 0000000..fe28970 --- /dev/null +++ b/time/time.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + "time" +) + +func main() { + fmt.Println("Welcome to the playground!") + fmt.Println("The time is", time.Now()) +}