Summary - Modules
- Go course
- Beginner
- Lesson 12/90
- 4 min
Combine module, package and import to set up a project.
Summary - Modules
In this section you learned module, package and import concepts:
- go mod init starts a module
- package main produces an executable
- import brings packages in
- go get adds dependencies
- go.sum keeps hashes
Now you will combine these concepts to set up a project skeleton.
Practice Print the package
Inside the empty main, print module ready with fmt.Println.
Starter code
package main
import "fmt"
func main() {
// buraya yaz
}Sample solution
package main
import "fmt"
func main() {
fmt.Println("module ready")
}Expected output
modül hazır
Practice Commented module
Add a // comment to the program and produce the output module running.
Starter code
package main
import "fmt"
func main() {
return
}Sample solution
package main
import "fmt"
func main() {
// Module running
fmt.Println("module running")
}Expected output
modül çalışıyor
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Module init
To start a new module:
____ init example/hello
To start a new module:
go mod init example/hello
Explanation: go mod init starts a new module.
2 Match the section concepts
| Term | Meaning |
|---|---|
go mod init |
Starts module |
package main |
Executable |
import "fmt" |
Opens package |
go get |
Downloads dependency |