What keyword is used to declare a variable in Go?

  • const
  • int
  • let
  • var
In Go, the keyword 'var' is used to declare a variable. It's followed by the variable name and its type. For example, var age int declares a variable named 'age' of type 'int'. 'var' is a fundamental keyword in Go for variable declaration.

What is a closure in the context of anonymous functions?

  • A closure can only be defined within a struct
  • A closure captures and retains the surrounding state
  • A closure is a built-in data type in Go
  • A closure is an anonymous function
In Go, a closure is an anonymous function that captures and retains the surrounding state. This means it can access and manipulate variables defined outside of its body. Closures are commonly used in situations where you need to create functions with dynamic behavior that relies on external variables.

When defining a method in Go, which convention is followed for the receiver parameter?

  • It is commonly a single letter that represents the type, like 't' for type
  • It must always be named 'receiver'
  • It must be a pointer to the type
  • It must be of interface type
In Go, the convention for the receiver parameter in a method definition is to use a single letter that represents the type, often the first letter of the type's name. This parameter can be either a value or a pointer type, depending on whether the method needs to mutate the receiver.

Which testing framework in Go allows you to write behavior-driven tests using a natural language style?

  • GSpec
  • GUnit
  • Ginkgo
  • GoConvey
Ginkgo is a popular testing framework in Go that enables developers to write behavior-driven tests using a natural language style. It provides clear and readable test cases, enhancing the readability of tests.

What is the purpose of the http.HandleFunc function in Go's HTTP server package?

  • Registering a handler function for a specific route
  • Creating a new HTTP server
  • Parsing HTTP requests
  • Sending HTTP responses
The correct option is registering a handler function for a specific route. http.HandleFunc is used to associate a handler function with a specific URL pattern. When a request matches the specified pattern, the associated handler function is called to handle the request.

Channels in Go can be _______ or _______ depending on whether they have a buffer.

  • Asynchronous, Buffered
  • Asynchronous, Unbuffered
  • Synchronous, Buffered
  • Synchronous, Unbuffered
Channels in Go can be synchronous or asynchronous and buffered or unbuffered. Synchronous channels block the sender until the receiver is ready, while asynchronous channels allow the sender to continue immediately. Buffered channels have a capacity, allowing multiple senders to store data without immediate consumption.

In Go, what is the purpose of the 'errors.New()' function?

  • Creating custom error messages
  • Handling panics
  • Initializing error variables
  • Parsing JSON data
In Go, the 'errors.New()' function is used to create custom error messages. This function takes a string as input and returns a new error that implements the 'error' interface. It's commonly used when a specific error message needs to be returned from a function.

The '_______' keyword in Go is used to defer the execution of a function until the surrounding function returns.

  • defer
  • delay
  • panic
  • recover
In Go, the defer keyword is used to defer the execution of a function until the surrounding function returns. It's commonly used to ensure cleanup actions are performed, such as closing files or unlocking mutexes.

Which interface in the database/sql package is used to represent a database row?

  • Entity
  • Record
  • Row
  • Tuple
In the database/sql package of Go, the interface used to represent a database row is Row. This interface provides methods to scan column values into Go variables. When executing a SQL query that returns rows, you typically use the QueryRow() method to fetch a single row and then scan its values using the Scan() method of the Row interface. The Row interface abstracts the notion of a database row, making it easy to work with individual rows of query results.

What keyword is used to define a function in Go?

  • def
  • func
  • function
  • procedure
In Go, the keyword "func" is used to define a function. It precedes the function name and parameter list in a function declaration. For example, func functionName(parameters) returnType { ... }.