Modules, Packages, and Imports Flashcards

1
Q

What is a repository in Go?

A

A repository stores the project’s source code and is placed in a version control system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a module in Go?

A

A module is a bundle of Go source code, distributed and versioned as a unit, stored in a repository, and contains one or more packages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a package in Go?

A

A package is a directory of source code that provides organization and structure to a module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many modules should be in a repository?

A

One module per repository to track versions separately for different modules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is a package in Go similar to a package in Node.js?

A

In Node.js, “package” is similar to Go’s “module.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the go.mod file do?

A

It converts a directory tree into a module, specifies the Go version, and includes module dependencies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What command initializes a go.mod file?

A

The command go mod init MODULE_PATH initializes the go.mod file, making the directory the root of a module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of the require directive in go.mod?

A

The require directive lists the modules your module depends on, including direct and indirect dependencies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between importing and exporting in Go?

A

Importing grants access to exported identifiers, and exporting makes identifiers available outside the package, starting with a capital letter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you import a package in Go?

A

You import external packages using their module paths, ensuring at least one identifier from the imported package is used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How should you name your packages?

A

Package names should be descriptive, typically nouns, while functions/methods are usually named with verbs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an internal package?

A

An internal package is a special package used to share code within a module but not accessible outside of its parent and sibling packages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can circular dependencies be avoided in Go?

A

Circular dependencies can be avoided by merging dependent packages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When should the init function be avoided in Go?

A

The init function should be avoided unless necessary, as it sets up code without being explicitly called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you import third-party code in Go?

A

Third-party code is imported by specifying the location and version in the go.mod file, and go get is used to add dependencies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Semantic Versioning (SemVer)?

A

SemVer is a versioning system with major, minor, and patch increments to indicate compatibility and bug fixes.

17
Q

What is pkg.go.dev used for?

A

pkg.go.dev indexes and provides documentation for Go modules, making it useful for discovering third-party modules.

18
Q

Do Go modules require a central repository?

A

No, there is no need for a central library repo.

19
Q

How do you version a Go module?

A

Use semantic versioning for releases, with pre-releases tagged like -beta1 (e.g., v1.3.4-beta1).