Initial commit
This commit is contained in:
19
first/README.md
Normal file
19
first/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
**The course videos follow this directory.**
|
||||
|
||||
So, you can find the lecture files in the same place as they are explained in the course videos. But then I've moved them into their own directories. This directory is here just for your convenience.
|
||||
|
||||
---
|
||||
|
||||
# ☢️ USE THE FOLLOWING DIRECTORIES INSTEAD! ☢️
|
||||
|
||||
**For the first part of the course; only the following directories contains exercises and quizzes.**
|
||||
|
||||
01-get-started/
|
||||
|
||||
02-write-your-first-program/
|
||||
|
||||
03-packages-and-scopes/
|
||||
|
||||
04-statements-expressions-comments/
|
||||
|
||||
05-write-your-first-library-package/
|
21
first/explain/comments/main.go
Normal file
21
first/explain/comments/main.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
// Package main makes this package an executable program
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
/*
|
||||
main function
|
||||
Go executes this program using this function.
|
||||
There should be only one main file in a main package.
|
||||
Executable programs are also called as "commands".
|
||||
*/
|
||||
func main() {
|
||||
fmt.Println("Hello Gopher!")
|
||||
}
|
16
first/explain/expressions/01-operator/main.go
Normal file
16
first/explain/expressions/01-operator/main.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello!" + "!")
|
||||
}
|
18
first/explain/expressions/02-call-expression/main.go
Normal file
18
first/explain/expressions/02-call-expression/main.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// runtime.NumCPU() is a call expression
|
||||
fmt.Println(runtime.NumCPU() + 1)
|
||||
}
|
3
first/explain/expressions/README
Normal file
3
first/explain/expressions/README
Normal file
@@ -0,0 +1,3 @@
|
||||
I've moved the main.go file for the expressions coding lecture into:
|
||||
|
||||
02-call-expression/
|
14
first/explain/importing/01-file-scope/main.go
Normal file
14
first/explain/importing/01-file-scope/main.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello!")
|
||||
}
|
16
first/explain/importing/02-renaming/main.go
Normal file
16
first/explain/importing/02-renaming/main.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import f "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello!")
|
||||
f.Println("There!")
|
||||
}
|
14
first/explain/packages/scopes/bye.go
Normal file
14
first/explain/packages/scopes/bye.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func bye() {
|
||||
fmt.Println("Bye!")
|
||||
}
|
14
first/explain/packages/scopes/hey.go
Normal file
14
first/explain/packages/scopes/hey.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func hey() {
|
||||
fmt.Println("Hey!")
|
||||
}
|
38
first/explain/packages/scopes/main.go
Normal file
38
first/explain/packages/scopes/main.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello!")
|
||||
|
||||
// two files belong to the same package
|
||||
// calling `bye()` of bye.go here
|
||||
bye()
|
||||
}
|
||||
|
||||
// EXERCISE: Remove the comments from the below function
|
||||
// And analyze the error message
|
||||
|
||||
// func bye() {
|
||||
// fmt.Println("Bye!")
|
||||
// }
|
||||
|
||||
// ***** EXPLANATION *****
|
||||
//
|
||||
// ERROR: "bye" function "redeclared"
|
||||
// in "this block"
|
||||
//
|
||||
// "this block" means = "main package"
|
||||
//
|
||||
// "redeclared" means = you're using the same name
|
||||
// in the same scope again
|
||||
//
|
||||
// main package's scope is:
|
||||
// all source-code files which are in the same main package
|
14
first/explain/packages/what/bye.go
Normal file
14
first/explain/packages/what/bye.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func bye() {
|
||||
fmt.Println("Bye!")
|
||||
}
|
14
first/explain/packages/what/hey.go
Normal file
14
first/explain/packages/what/hey.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func hey() {
|
||||
fmt.Println("Hey!")
|
||||
}
|
25
first/explain/packages/what/main.go
Normal file
25
first/explain/packages/what/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello!")
|
||||
|
||||
// You can access functions from other files
|
||||
// which are in the same package
|
||||
|
||||
// Here, `main()` can access `bye()` and `hey()`
|
||||
|
||||
// It's because: bye.go, hey.go and main.go
|
||||
// are in the main package.
|
||||
|
||||
bye()
|
||||
hey()
|
||||
}
|
24
first/explain/scopes/01-scopes/main.go
Normal file
24
first/explain/scopes/01-scopes/main.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// file scope
|
||||
import "fmt"
|
||||
|
||||
// package scope
|
||||
const ok = true
|
||||
|
||||
// package scope
|
||||
func main() { // block scope starts
|
||||
|
||||
var hello = "Hello"
|
||||
|
||||
// hello and ok are visible here
|
||||
fmt.Println(hello, ok)
|
||||
|
||||
} // block scope ends
|
26
first/explain/scopes/02-block-scope/main.go
Normal file
26
first/explain/scopes/02-block-scope/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
func nope() { // block scope starts
|
||||
|
||||
// hello and ok are only visible here
|
||||
const ok = true
|
||||
var hello = "Hello"
|
||||
|
||||
_ = hello
|
||||
} // block scope ends
|
||||
|
||||
func main() { // block scope starts
|
||||
|
||||
// hello and ok are not visible here
|
||||
|
||||
// ERROR:
|
||||
// fmt.Println(hello, ok)
|
||||
|
||||
} // block scope ends
|
39
first/explain/scopes/03-nested-scope/main.go
Normal file
39
first/explain/scopes/03-nested-scope/main.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// I didn't talk about this in a lecture
|
||||
// As a side-note, I wanted to put it here
|
||||
// Please review it.
|
||||
|
||||
var declareMeAgain = 10
|
||||
|
||||
func nested() { // block scope starts
|
||||
|
||||
// declares the same variable
|
||||
// they both can exist together
|
||||
// this one only belongs to this scope
|
||||
// package's variable is still intact
|
||||
var declareMeAgain = 5
|
||||
fmt.Println("inside nope:", declareMeAgain)
|
||||
|
||||
} // block scope ends
|
||||
|
||||
func main() { // block scope starts
|
||||
|
||||
fmt.Println("inside main:", declareMeAgain)
|
||||
|
||||
nested()
|
||||
|
||||
// package-level declareMeAgain isn't effected
|
||||
// from the change inside the nested func
|
||||
fmt.Println("inside main:", declareMeAgain)
|
||||
|
||||
} // block scope ends
|
22
first/explain/statements/01-execution-flow/main.go
Normal file
22
first/explain/statements/01-execution-flow/main.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello!")
|
||||
|
||||
// Statements change the execution flow
|
||||
// Especially the control flow statements like `if`
|
||||
if 5 > 1 {
|
||||
fmt.Println("bigger")
|
||||
}
|
||||
}
|
16
first/explain/statements/02-semicolons/main.go
Normal file
16
first/explain/statements/02-semicolons/main.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello"); fmt.Println("World!")
|
||||
}
|
27
first/first/exercises/01/main.go
Normal file
27
first/first/exercises/01/main.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// Print your name and your best friend's name using
|
||||
// Println twice
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// YourName
|
||||
// YourBestFriendName
|
||||
//
|
||||
// BONUS
|
||||
// Use `go run` first.
|
||||
// And after that use `go build` and run your program.
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// ?
|
||||
// ?
|
||||
}
|
20
first/first/exercises/01/solution/main.go
Normal file
20
first/first/exercises/01/solution/main.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// go run main.go
|
||||
|
||||
// go build
|
||||
// ./solution
|
||||
|
||||
func main() {
|
||||
fmt.Println("Nikola")
|
||||
fmt.Println("Thomas")
|
||||
}
|
7
first/first/exercises/02/exercise.md
Normal file
7
first/first/exercises/02/exercise.md
Normal file
@@ -0,0 +1,7 @@
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// Print your GOPATH using `go env` tool
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// The physical folder path that is referenced by $GOPATH
|
||||
// ---------------------------------------------------------
|
3
first/first/exercises/02/solution/solution.md
Normal file
3
first/first/exercises/02/solution/solution.md
Normal file
@@ -0,0 +1,3 @@
|
||||
You should type this:
|
||||
|
||||
go env GOPATH
|
59
first/first/main.go
Normal file
59
first/first/main.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
// package main is a special package
|
||||
// it allows Go to create an executable file
|
||||
package main
|
||||
|
||||
/*
|
||||
This is a multi-line comment.
|
||||
|
||||
import keyword makes another package available
|
||||
for this .go "file".
|
||||
|
||||
import "fmt" lets you access fmt package's functionality
|
||||
here in this file.
|
||||
*/
|
||||
import "fmt"
|
||||
|
||||
// "func main" is special.
|
||||
//
|
||||
// Go has to know where to start
|
||||
//
|
||||
// func main creates a starting point for Go
|
||||
//
|
||||
// After compiling the code,
|
||||
// Go runtime will first run this function
|
||||
func main() {
|
||||
// after: import "fmt"
|
||||
// Println function of "fmt" package becomes available
|
||||
|
||||
// Look at what it looks like by typing in the console:
|
||||
// godoc -src fmt Println
|
||||
|
||||
// Println is just an exported function from
|
||||
// "fmt" package
|
||||
|
||||
// Exported = First Letter is uppercase
|
||||
fmt.Println("Hello Gopher!")
|
||||
|
||||
// Go cannot call Println function by itself.
|
||||
// That's why you need to call it here.
|
||||
// It only calls `func main` automatically.
|
||||
|
||||
// -----
|
||||
|
||||
// Go supports Unicode characters in string literals
|
||||
// And also in source-code: KÖSTEBEK!
|
||||
|
||||
// EXERCISE: Remove the comments from below --> //
|
||||
// fmt.Println("Merhaba Köstebek!")
|
||||
|
||||
// Unnecessary note:
|
||||
// "Merhaba Köstebek" means "Hello Gopher"
|
||||
// in Turkish language
|
||||
}
|
19
first/first/questions/01-gopath-questions.md
Normal file
19
first/first/questions/01-gopath-questions.md
Normal file
@@ -0,0 +1,19 @@
|
||||
## Where you should put your Go source code into?
|
||||
* Anywhere on my computer
|
||||
* Under $GOPATH
|
||||
* Under $GOPATH/src *CORRECT*
|
||||
|
||||
## What $GOPATH means?
|
||||
* It's a file for Go runtime
|
||||
* Stores Go source code files and compiled packages
|
||||
* It's a path for gophers to follow
|
||||
|
||||
## Do you need to set your $GOPATH?
|
||||
* Yes
|
||||
* No: It's stored on my desktop
|
||||
* No: It's stored under my user path *CORRECT*
|
||||
|
||||
## How can you print your $GOPATH?
|
||||
* Using `ls` command
|
||||
* Using `go env GOPATH` command *CORRECT*
|
||||
* Using `go environment` command
|
151
first/first/questions/02-code-your-first-program-questions.md
Normal file
151
first/first/questions/02-code-your-first-program-questions.md
Normal file
@@ -0,0 +1,151 @@
|
||||
## What does the package keyword do in the following program?
|
||||
```go
|
||||
package main
|
||||
|
||||
func main() {
|
||||
}
|
||||
```
|
||||
1. func
|
||||
2. package *CORRECT*
|
||||
3. fmt.Println
|
||||
4. import
|
||||
|
||||
> 1. This keyword is used to declare a new function.
|
||||
> 2. That's right! package keyword allows you to define which package a Go file belongs to.
|
||||
> 3. This is not a keyword. It's the Println function of the fmt package.
|
||||
> 4. This keyword is used to import a package.
|
||||
|
||||
|
||||
## Which keyword is used to declare a new function?
|
||||
* func *CORRECT*
|
||||
* package
|
||||
* Println
|
||||
* import
|
||||
|
||||
|
||||
## What is a function?
|
||||
1. It's like a mini-program. It's a reusable and executable block of code. *CORRECT*
|
||||
2. It allows Go to execute a program.
|
||||
3. It allows Go to import a package called function.
|
||||
4. It prints a message to the console.
|
||||
|
||||
> 2. Go looks for package main and func main to do that. A function doesn't do that on its own.
|
||||
> 3. `import` keyword does that.
|
||||
> 4. For example: `fmt.Println` does that.
|
||||
|
||||
|
||||
## Do you have to call the main function yourself?
|
||||
1. Yes, so that, I can execute my program.
|
||||
2. No, Go calls the main function automatically. *CORRECT*
|
||||
|
||||
> 1. No, you don't need to call the main function. Go automatically executes it.
|
||||
|
||||
|
||||
## Do you have to call the other functions yourself?
|
||||
1. Yes, so that, I can execute that function. *CORRECT*
|
||||
2. Yes, so that, Go can execute my program.
|
||||
3. No, Go calls the functions automatically.
|
||||
|
||||
> 1. That's right. You need to call a function yourself. Go won't execute it automatically. Go only calls the main function automatically (and some other functions which you didn't learn about yet).
|
||||
|
||||
> 2. That's only the job of the `func main`. There's only one `func main`.
|
||||
|
||||
> 3. Go doesn't call any function automatically except the main func (and some other functions which you didn't learn about yet). So, except the main func, you need to call the functions yourself.
|
||||
|
||||
|
||||
## What does `package main` do?
|
||||
```go
|
||||
package main
|
||||
|
||||
func main() {
|
||||
}
|
||||
```
|
||||
* It controls everything
|
||||
* It allows you to properly exit from a program
|
||||
* It allows you to create an executable Go program *CORRECT*
|
||||
|
||||
|
||||
## What does `func main` do?
|
||||
```go
|
||||
package main
|
||||
|
||||
func main() {
|
||||
}
|
||||
```
|
||||
1. It contains a package called main
|
||||
2. Go starts executing your program by using the code inside func main *CORRECT*
|
||||
3. It prints a message to the console
|
||||
|
||||
> 1. main function doesn't contain a package.
|
||||
> 2. That's right. Go automatically calls the main function to execute your program.
|
||||
> 3. It doesn't print anything at least directly.
|
||||
|
||||
|
||||
## What does `import "fmt"` do?
|
||||
```go
|
||||
package main
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hi!")
|
||||
}
|
||||
```
|
||||
1. It prints "fmt" to the console
|
||||
2. It defines a new package called "fmt"
|
||||
3. It imports the `fmt` package; so you can use its functionalities *CORRECT*
|
||||
|
||||
> 1. `fmt.Println` prints a message not the `import "fmt"`.
|
||||
> 2. `package` keyword does that, not the `import` keyword.
|
||||
> 3. Yes. For example, after you import the fmt package you can call its Println function to print a message to the console.
|
||||
|
||||
|
||||
## What this program does?
|
||||
```go
|
||||
package main
|
||||
|
||||
func main() {
|
||||
}
|
||||
```
|
||||
1. It prints a message to the console
|
||||
2. It's a correct program but it doesn't print anything *CORRECT*
|
||||
3. It's an incorrect program
|
||||
|
||||
> 1. It doesn't print a message. To do that you can use fmt.Println function.
|
||||
|
||||
> 2. Yes, it's a correct program but since it doesn't contain fmt.Println it doesn't print anything.
|
||||
|
||||
> 3. It's a correct program. It uses the package keyword and it has a main function. So, this is a valid and an executable Go program.
|
||||
|
||||
|
||||
## What does this program print?
|
||||
```go
|
||||
package main
|
||||
|
||||
func main() {
|
||||
fmt.Println(Hi! I want to be a Gopher!)
|
||||
}
|
||||
```
|
||||
* Hi! I want to be a Gopher!
|
||||
* It doesn't print anything
|
||||
* This program is incorrect *CORRECT*
|
||||
|
||||
> 1. It doesn't pass the message to Println wrapped between double-quotes. It should be like: fmt.Println("Hi! I want to be a Gopher")
|
||||
|
||||
> 3. It doesn't import "fmt" package. Also see #1.
|
||||
|
||||
|
||||
## What does this program print?
|
||||
```go
|
||||
package main
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hi there!")
|
||||
}
|
||||
```
|
||||
* Hi there! *CORRECT*
|
||||
* fmt
|
||||
* This program is incorrect; it imports the wrong package or there isn't a function called `Println`
|
||||
|
||||
> 2. import "fmt" imports the `fmt` package; so you can use its functionalities.
|
||||
> 3. Actually, this program is correct.
|
43
first/first/questions/03-run-your-first-program-questions.md
Normal file
43
first/first/questions/03-run-your-first-program-questions.md
Normal file
@@ -0,0 +1,43 @@
|
||||
## What's the difference between `go build` and `go run`?
|
||||
1. `go run` just compiles a program; whereas `go build` both compiles and runs it.
|
||||
2. `go run` both compiles and runs a program; whereas `go build` just compiles it. *CORRECT*
|
||||
|
||||
> 1. It's opposite actually.
|
||||
> 2. `go run` compiles your program and puts it in a temporary directory. Then it runs the compiled program in there.
|
||||
|
||||
|
||||
## Which directory `go build` puts the compiled code into?
|
||||
1. The same directory where you call `go build` *CORRECT*
|
||||
2. $GOPATH/src directory
|
||||
3. $GOPATH/pkg directory
|
||||
4. Into a temporary directory.
|
||||
|
||||
> 2. There only lives Go source-code files
|
||||
> 3. Go only puts your code there when you call `go install`.
|
||||
|
||||
|
||||
## Which directory `go run` puts the compiled code into?
|
||||
1. The same directory where you call `go run`
|
||||
2. $GOPATH/src directory
|
||||
3. $GOPATH/pkg directory
|
||||
4. Into a temporary directory. *CORRECT*
|
||||
|
||||
|
||||
## Which one below is true for runtime?
|
||||
1. It happens when your program starts running in a computer *CORRECT*
|
||||
2. It happens while your program is being compiled
|
||||
|
||||
|
||||
## Which one below is true for the compile-time?
|
||||
1. It happens when your program starts running in a computer
|
||||
2. It happens while your program is being compiled *CORRECT*
|
||||
|
||||
|
||||
## In which stage your program can print a message to the console?
|
||||
1. While it's being compiled.
|
||||
2. While it runs (after compile-time). *CORRECT*
|
||||
3. While it runs (inside the compile-time).
|
||||
|
||||
> 1. In the compilation step your program cannot print a message. In that stage, it's literally dead.
|
||||
> 2. That's right. That's the only time which your program can interact with a computer and instruct it to print a message to the console.
|
||||
> 3. Running can only happen after the compile-time
|
20
first/printer-exercise/solution/golang/cmd/main.go
Normal file
20
first/printer-exercise/solution/golang/cmd/main.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
// You should replace this with your username
|
||||
// If you remove this, vs code will do that for you
|
||||
"github.com/inancgumus/learngo/first/printer-exercise/solution/golang"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(golang.Version())
|
||||
}
|
17
first/printer-exercise/solution/golang/go.go
Normal file
17
first/printer-exercise/solution/golang/go.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package golang
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// Version returns the current Go version
|
||||
func Version() string {
|
||||
return runtime.Version()
|
||||
}
|
15
first/printer/cmd/main.go
Normal file
15
first/printer/cmd/main.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// Automatically imports!... AWESOME!
|
||||
import "github.com/inancgumus/learngo/first/printer"
|
||||
|
||||
func main() {
|
||||
printer.Hello()
|
||||
}
|
15
first/printer/printer.go
Normal file
15
first/printer/printer.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package printer
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Hello is an exported function
|
||||
func Hello() {
|
||||
fmt.Println("exported hello")
|
||||
}
|
Reference in New Issue
Block a user