How can 'panic()' be recovered in Go?

  • By using 'panic()' inside a recoverable function
  • Catching the panic with a try-catch block
  • Using 'defer' with a function that calls 'recover()'
  • Using the 'recover()' function in a deferred function
In Go, panics can be recovered using 'defer' with a function that calls 'recover()'. The 'recover()' function returns the value passed to the call of panic() during a panic. Therefore, it's commonly used in deferred functions to catch and handle panics.

Anonymous functions in Go can capture variables from the surrounding scope. What is this concept called?

  • Function Overloading
  • Lexical Scoping
  • Namespace Isolation
  • Variable Encapsulation
In Go, anonymous functions have access to variables in the lexical scope where they are defined. This means they can capture and use variables from the surrounding scope, which is referred to as lexical scoping. Lexical scoping enables powerful and flexible programming constructs in Go.

The _______ method in mocking allows defining the behavior of a mock object.

  • Expect
  • MockFunc
  • OnCall
  • Return
In mocking frameworks, the Return method allows developers to define the behavior of a mock object. This method is used to specify the value that should be returned when a mocked function or method is called during testing. It enables developers to set up the expected behavior of the mock object for different test scenarios.

In MongoDB, what does BSON stand for?

  • Binary Serialized Object Notation
  • Binary Serialized Object Notation
  • Binary Serialized Object Notation
  • Binary Syntax Object
BSON stands for Binary Serialized Object Notation. It is a binary-encoded serialization of JSON-like documents used in MongoDB to represent complex data structures and to support data storage and interchange.

In Go, which package is used to interact with SQL databases?

  • database/sql
  • golang-sql
  • gosql
  • sql
In Go, the package used to interact with SQL databases is database/sql. It provides a powerful and flexible API for executing SQL queries, working with result sets, and managing database connections, making it essential for database access.

In a performance-critical section of your code, you need to efficiently swap the values of two variables. Which operator could you use to achieve this in Go?

  • a ^= b ^= a ^= b
  • a, b = b, a
  • swap(a, b)
  • temp := a; a = b; b = temp
Go supports multiple assignment, enabling swapping of variables using a, b = b, a. This approach is concise and efficient, ideal for performance-critical sections.

Suppose you're building a system where you need to represent and manipulate raw binary data. Which data type would be most appropriate for this task?

  • binary
  • bit
  • byte (uint8)
  • uint16
The byte (uint8) data type is most appropriate for representing raw binary data in Go. It has a size of 8 bits, making it suitable for storing individual bytes of binary data and manipulating them effectively.

Which Go tool is commonly used to run tests and display test coverage?

  • go build
  • go run
  • go test
  • go vet
The "go test" tool is commonly used in Go to run tests and display test coverage. It automatically identifies and executes test functions in files with a "_test" suffix and provides detailed output, including coverage analysis. It's an essential tool for maintaining code quality and ensuring thorough testing in Go projects.

The _______ type in Go represents an HTTP request handler.

  • http.Handler
  • http.RequestHandler
  • http.ResponseWriter
  • http.ServeMux
In Go, the http.ServeMux type represents an HTTP request handler. It provides a way to multiplex HTTP requests to different handlers based on the request URL's path.

What keyword is used to specify a condition in a switch statement in Go?

  • case
  • condition
  • if
  • select
The case keyword is used to specify a condition in a switch statement in Go. It helps in defining different cases and their corresponding actions within the switch statement.