From ee5e96693735776c11d8f3769708ec4ae2329390 Mon Sep 17 00:00:00 2001 From: QBL bot Date: Thu, 10 Aug 2023 07:16:14 +0000 Subject: [PATCH 1/5] Create intro_to_golang_&_basic_concurrency-setting_up_go --- ...o_golang_&_basic_concurrency-setting_up_go | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 course_content/intro_to_golang_&_basic_concurrency-setting_up_go diff --git a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go new file mode 100644 index 0000000..4622f6f --- /dev/null +++ b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go @@ -0,0 +1,123 @@ +Unit_name: Intro to Golang & Basic Concurrency +Page_name: Setting up Go + +1. Which command initializes a new Go module in your current directory? + + A) `go init module` + - Incorrect. Remember that the command structure uses 'mod' instead of 'module' and 'init' is not the first keyword. + + B) `go mod init` + - Correct. `go mod init` initializes a new Go module in your current directory. It creates a `go.mod` file that describes the module. + + C) `go module start` + - Incorrect. 'go module start' is not a valid command in Go. Revisit the commands used to create a module in Go. + +2. What is the default file created when you initialize a new Go module and what does it contain? + + A) `go.mod`, which contains the module path and its dependencies. + - Correct. Initializing a Go module creates a `go.mod` file, listing the module path and its dependencies. + + B) `go.pack`, which contains all the Go packages in the module + - Incorrect. Go does not generate a `go.pack` file upon module initialization. The main file of each module has a specific name. + + C) `mod.go`, which contains the main function + - Incorrect. `mod.go` is not the file created during module initialization. Go uses a specific file to maintain the module details. + +3. Looking at the following code, what does `go.mod` do in this context? + +```go +module github.com/my/repo + +go 1.14 + +require ( + github.com/pkg/errors v0.8.1 + golang.org/x/net v0.0.0-20200202094626-16171245cfb2 +) +``` + + A) It specifies the version of Go used in the project + - Incorrect. Although `go.mod` specifies the language version "go 1.14", it serves a broader purpose in a module. + + B) It defines the module path and its dependencies + - Correct. The `go.mod` file defines the module path, the Go version, and all the dependencies required by the project. + + C) It is the main script that runs the module + - Incorrect. `go.mod` does not contain any runnable code. Try to remember its actual purpose. + +4. What is the difference between packages and modules in Go? + + A) Modules are older; packages were introduced in Go 1.13 + - Incorrect. Both packages and modules have been part of Go since its earlier versions, but they serve different purposes. + + B) A module is a collection of Go packages, while a package is a way to organize code within a module + - Correct. Modules can contain multiple packages, and each of the packages can contain multiple Go source files. + + C) There is no difference, the terms are interchangeable + - Incorrect. Although dependencies can be a mix of packages and modules, these are distinct concepts in Go. + +5. How is 'v1.2.3' interpreted in Go module versioning? + + A) Go version 1, Module update 2, Bug fix 3 + - Incorrect. The 'vx.y.z' is more to do with the version of the particular module, rather than the Go language or types of updates. + + B) Major version 1, Minor version 2, Patch version 3 + - Correct. The version string 'v1.2.3' represents Major, Minor, and Patch versions respectively in semantic versioning. + + C) It is an invalid module versioning format + - Incorrect. 'v1.2.3' is a valid semantic versioning format in Go, where each position has a specific meaning. + +6. How would you add a new dependency to your Go module? + + A) By adding the import path to the `go.mod` file + - Incorrect. Adding the import manually in `go.mod` is not how Go handles dependencies. It has a built-in methodology for it. + + B) By importing the package in the Go source file where it's needed + - Correct. When you import a package in your Go source file, it gets added to your module dependencies automatically. + + C) By copying the package source code to the module directory + - Incorrect. Copying source code into the module is not a recommended way to handle dependencies and could potentially lead to issues. + +7. What happens when you execute `go mod tidy` in a module with unused dependencies? + + A) It deletes all unused Go files in the module + - Incorrect. `go mod tidy` does not delete any Go source files. It affects a different component in a module. + + B) It adds missing dependencies and removes unnecessary ones + - Correct. `go mod tidy` ensures that the go.mod file matches the source code in the module by adding required and removing unused dependencies. + + C) It compiles all Go source files in the module + - Incorrect. `go mod tidy` is not involved in the compilation process. It helps manage module dependencies. + +8. How can you keep track of direct and indirect imports in your Go module? + + A) Go automatically maintains direct and indirect imports in different files + - Incorrect. Go does not maintain imports in different files. It uses a specific method to manage them. + + B) You have to manually maintain a list of direct and indirect imports + - Incorrect. You do not need to maintain the list manually. Go provides in-built functionality to handle this. + + C) Direct and indirect imports are both maintained in the `go.mod` file + - Correct. The `go.mod` file includes details of both direct and indirect imports in your Go module. + +9. If packages are a way to organize code within a module in Go, what is the purpose of creating a new module in your Go project? + + A) To group related packages + - Incorrect. While related packages could be grouped in a module, there is a more specific reason for creating a new module in a Go project. + + B) To isolate dependencies for different features or components + - Correct. Creating a new module can be helpful when we want to isolate dependencies for different features or components in a Go project. + + C) To create a new main function + - Incorrect. Creating a new module does not necessarily mean creating a new main function. Reconsider the purpose of a module in a Go project. + +10. How can you ensure that your Go module is using the latest version of its dependencies? + + A) By manually editing the version numbers in the `go.mod` file + - Incorrect. Manually editing the version numbers in `go.mod` is not a recommended practice in Go programming as there's an in-built methodology for it. + + B) By executing `go get -u` + - Correct. `go get -u` updates all the direct and indirect dependencies to the latest version. + + C) Versions are automatically updated each time the module is run + - Incorrect. The Go module does not update dependency versions each time it is run. Explicit command is required to update dependencies. \ No newline at end of file From d0082cf04c481bc1db7d737cff0599c5b7e51acd Mon Sep 17 00:00:00 2001 From: Storsorken <54906004+Storsorken@users.noreply.github.com> Date: Fri, 11 Aug 2023 00:39:54 +0300 Subject: [PATCH 2/5] Update Q3 in unit_1/page_2 --- .../intro_to_golang_&_basic_concurrency-setting_up_go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go index 4622f6f..e70f8f2 100644 --- a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go +++ b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go @@ -23,7 +23,7 @@ Page_name: Setting up Go C) `mod.go`, which contains the main function - Incorrect. `mod.go` is not the file created during module initialization. Go uses a specific file to maintain the module details. -3. Looking at the following code, what does `go.mod` do in this context? +3. Looking at the following code, what does `go.mod` file do in this context? ```go module github.com/my/repo @@ -39,7 +39,7 @@ require ( A) It specifies the version of Go used in the project - Incorrect. Although `go.mod` specifies the language version "go 1.14", it serves a broader purpose in a module. - B) It defines the module path and its dependencies + B) It defines the module path, the project's dependencies, and the Go version - Correct. The `go.mod` file defines the module path, the Go version, and all the dependencies required by the project. C) It is the main script that runs the module @@ -120,4 +120,4 @@ require ( - Correct. `go get -u` updates all the direct and indirect dependencies to the latest version. C) Versions are automatically updated each time the module is run - - Incorrect. The Go module does not update dependency versions each time it is run. Explicit command is required to update dependencies. \ No newline at end of file + - Incorrect. The Go module does not update dependency versions each time it is run. Explicit command is required to update dependencies. From 7931867227e1c351391ccd7e315cf7b2e0d7b756 Mon Sep 17 00:00:00 2001 From: Storsorken <54906004+Storsorken@users.noreply.github.com> Date: Fri, 11 Aug 2023 18:39:20 +0300 Subject: [PATCH 3/5] Remove Q5 from module_1/page_2 --- .../intro_to_golang_&_basic_concurrency-setting_up_go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go index e70f8f2..b6d84be 100644 --- a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go +++ b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go @@ -56,17 +56,6 @@ require ( C) There is no difference, the terms are interchangeable - Incorrect. Although dependencies can be a mix of packages and modules, these are distinct concepts in Go. -5. How is 'v1.2.3' interpreted in Go module versioning? - - A) Go version 1, Module update 2, Bug fix 3 - - Incorrect. The 'vx.y.z' is more to do with the version of the particular module, rather than the Go language or types of updates. - - B) Major version 1, Minor version 2, Patch version 3 - - Correct. The version string 'v1.2.3' represents Major, Minor, and Patch versions respectively in semantic versioning. - - C) It is an invalid module versioning format - - Incorrect. 'v1.2.3' is a valid semantic versioning format in Go, where each position has a specific meaning. - 6. How would you add a new dependency to your Go module? A) By adding the import path to the `go.mod` file From cd7659df03530ae913bcf81b87bf81bea395ef14 Mon Sep 17 00:00:00 2001 From: Storsorken <54906004+Storsorken@users.noreply.github.com> Date: Fri, 11 Aug 2023 18:41:55 +0300 Subject: [PATCH 4/5] Remove Q6 and fix Q7 in module_1/page_2 --- ...ntro_to_golang_&_basic_concurrency-setting_up_go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go index b6d84be..1e500cc 100644 --- a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go +++ b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go @@ -56,24 +56,13 @@ require ( C) There is no difference, the terms are interchangeable - Incorrect. Although dependencies can be a mix of packages and modules, these are distinct concepts in Go. -6. How would you add a new dependency to your Go module? - - A) By adding the import path to the `go.mod` file - - Incorrect. Adding the import manually in `go.mod` is not how Go handles dependencies. It has a built-in methodology for it. - - B) By importing the package in the Go source file where it's needed - - Correct. When you import a package in your Go source file, it gets added to your module dependencies automatically. - - C) By copying the package source code to the module directory - - Incorrect. Copying source code into the module is not a recommended way to handle dependencies and could potentially lead to issues. - 7. What happens when you execute `go mod tidy` in a module with unused dependencies? A) It deletes all unused Go files in the module - Incorrect. `go mod tidy` does not delete any Go source files. It affects a different component in a module. B) It adds missing dependencies and removes unnecessary ones - - Correct. `go mod tidy` ensures that the go.mod file matches the source code in the module by adding required and removing unused dependencies. + - Correct. `go mod tidy` ensures that the go.mod file matches the source code in the module by adding required and removing unused dependencies to the go.mod file. C) It compiles all Go source files in the module - Incorrect. `go mod tidy` is not involved in the compilation process. It helps manage module dependencies. From 211d51f8e49872e094cfbd3197dd12640e74eac4 Mon Sep 17 00:00:00 2001 From: Storsorken <54906004+Storsorken@users.noreply.github.com> Date: Fri, 11 Aug 2023 18:45:09 +0300 Subject: [PATCH 5/5] Remove Q8 and Q9 from module_1/page_2 --- ...o_golang_&_basic_concurrency-setting_up_go | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go index 1e500cc..c63e524 100644 --- a/course_content/intro_to_golang_&_basic_concurrency-setting_up_go +++ b/course_content/intro_to_golang_&_basic_concurrency-setting_up_go @@ -67,28 +67,6 @@ require ( C) It compiles all Go source files in the module - Incorrect. `go mod tidy` is not involved in the compilation process. It helps manage module dependencies. -8. How can you keep track of direct and indirect imports in your Go module? - - A) Go automatically maintains direct and indirect imports in different files - - Incorrect. Go does not maintain imports in different files. It uses a specific method to manage them. - - B) You have to manually maintain a list of direct and indirect imports - - Incorrect. You do not need to maintain the list manually. Go provides in-built functionality to handle this. - - C) Direct and indirect imports are both maintained in the `go.mod` file - - Correct. The `go.mod` file includes details of both direct and indirect imports in your Go module. - -9. If packages are a way to organize code within a module in Go, what is the purpose of creating a new module in your Go project? - - A) To group related packages - - Incorrect. While related packages could be grouped in a module, there is a more specific reason for creating a new module in a Go project. - - B) To isolate dependencies for different features or components - - Correct. Creating a new module can be helpful when we want to isolate dependencies for different features or components in a Go project. - - C) To create a new main function - - Incorrect. Creating a new module does not necessarily mean creating a new main function. Reconsider the purpose of a module in a Go project. - 10. How can you ensure that your Go module is using the latest version of its dependencies? A) By manually editing the version numbers in the `go.mod` file