diff --git a/README.md b/README.md index 11d6f8a..d627819 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # golang_course +##Setting you GOPATH + +`go env` will display your current GO Environment variables + +### Windows + +set GOPATH=C:\Users\Gideon\go\src\golang_course diff --git a/hello/hello.go b/hello/hello.go new file mode 100644 index 0000000..f03e7f4 --- /dev/null +++ b/hello/hello.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "runtime" +) + +var ( + name string + course string + module float64 +) + +func main() { + fmt.Println("Hello from: ", runtime.GOOS) +} diff --git a/hello/pointers.go b/hello/pointers.go new file mode 100644 index 0000000..6058908 --- /dev/null +++ b/hello/pointers.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "os" +) + +var my_name = "Drew" +var program_name = os.Args[0] + +func main() { + fmt.Println("Starting up program:", program_name) + change_name(&my_name) + fmt.Println("Ok so you name is:", my_name) + +} + +func change_name(name *string) { + *name = "Your name is no longer useful" +} diff --git a/hello/reflection.go b/hello/reflection.go new file mode 100644 index 0000000..ad1c069 --- /dev/null +++ b/hello/reflection.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "reflect" +) + +var ( + // alternative method + // name, course, module = "Nigel", "Docker Deep Dive", 3.2 + name string = "Drew" + course string = "Docker Deep Dive" + module float64 = 3.2 +) + +func main() { + + fmt.Println("Name is", name, "and is of type", reflect.TypeOf(name)) + fmt.Println("Module is", module, "and is of type", reflect.TypeOf(module)) +} diff --git a/hello/reflection2.go b/hello/reflection2.go new file mode 100644 index 0000000..bc3fec3 --- /dev/null +++ b/hello/reflection2.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "reflect" +) + +func main() { + + a := 10.000000000 + b := 3 + + fmt.Println("\nA is type", reflect.TypeOf(a), "and B is of type", reflect.TypeOf(b)) + + c := int(a) + b + + fmt.Println("\nC has value:", c, "and is of type", reflect.TypeOf(c)) +} diff --git a/hello/reflection3.go b/hello/reflection3.go new file mode 100644 index 0000000..f83fda8 --- /dev/null +++ b/hello/reflection3.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "reflect" +) + +func main() { + + name := "Drew" + //GO won't let us use unused variables inside of functions + //course string = "Docker Deep Dive" + module := 3.2 + + fmt.Println("Name is", name, "and is of type", reflect.TypeOf(name)) + fmt.Println("Module is", module, "and is of type", reflect.TypeOf(module)) +} diff --git a/hello/variable.go b/hello/variable.go new file mode 100644 index 0000000..993864f --- /dev/null +++ b/hello/variable.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" +) + +var ( + name string + course string + module float64 +) + +func main() { + fmt.Println("Name is set to ", name) + fmt.Println("Module is set to ", module) +}