CodeBlanks Logo Icon CodeBlanks

Summary - Modules

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

main.go
package main

import "fmt"

func main() {
    // buraya yaz
}

Sample solution

main.go
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

main.go
package main

import "fmt"

func main() {
    return
}

Sample solution

main.go
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

Question
To start a new module:
____ init example/hello
Answer
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

All lessons in Beginner