What is the difference between interface{} and empty interface in Go?

  • They are the same.
  • They are used interchangeably depending on the context.
  • empty interface{} can hold any type, while interface{} can hold only nil.
  • interface{} can hold any type, while empty interface{} can hold only nil.
In Go, interface{} is known as the empty interface and it can hold any type, whereas an empty interface{} can hold any type as well but with a distinction that it can't hold any value (except nil). Understanding this subtle difference is crucial in Go programming.

In Go, which data type is used to store complex numbers?

  • complex
  • complex128
  • complex64
  • int
In Go, the complex128 data type is used to store complex numbers. The complex128 type represents complex numbers with float64 real and imaginary parts, offering higher precision compared to complex64, which uses float32 parts.

Redis offers a _______ feature that allows for the creation of data structures with a predefined maximum capacity.

  • Eviction Policy
  • Expiration Policy
  • Memory Management Policy
  • Time-To-Live (TTL) Policy
Redis offers an "Eviction Policy" feature that allows for the creation of data structures with a predefined maximum capacity. This policy determines how Redis handles data when the memory limit is reached.

In Go unit testing, the _______ function is used to indicate a failed test and continue executing subsequent tests.

  • Error
  • Fail
  • FailNow
  • Fatal
In Go unit testing, the FailNow function is used to indicate a failed test and stop execution immediately. It marks the test as failed and terminates the test execution, preventing further test cases from running.

What is the syntax for a type switch statement in Go?

  • switch x.(type) { case Type1: // code break case Type2: // code break default: // code }
  • switch x.(type) { case Type1: // code case Type2: // code default: // code }
  • switch x.(type) { case Type1: // code continue case Type2: // code continue default: // code }
  • switch x.(type) { case Type1: // code fallthrough case Type2: // code fallthrough default: // code }
The correct syntax for a type switch statement in Go is switch x.(type) { case Type1: // code case Type2: // code default: // code }. Type switches in Go allow you to perform different actions based on the type of an interface variable. It evaluates the type of x and compares it with each case. If a match is found, the corresponding code block is executed. If none of the cases match, the default case (if provided) is executed.

Can structs have circular references in Go?

  • It depends
  • No
  • Sometimes
  • Yes
No, structs cannot have circular references in Go. Unlike some other languages, Go does not allow self-referencing or circular structures directly in structs.

What is type assertion used for in Go?

  • To declare a new type based on an existing type.
  • To define custom behavior for operators in Go.
  • To handle errors in Go programs.
  • To test and extract the underlying concrete value of an interface.
Type assertion in Go is primarily used to test whether an interface value holds a specific type and to extract the underlying concrete value of that type if it does. This allows Go programmers to work with the concrete type safely within the scope of the assertion.

In database migration, the 'up' method is responsible for _______ the database schema.

  • Creating
  • Deleting
  • Modifying
  • Updating
Creating

A struct in Go can have _______ methods associated with it.

  • Constructor
  • Instance
  • Pointer
  • Static
In Go, a struct can have pointer methods associated with it. Pointer methods are functions that have a receiver of a pointer type. They allow modifying the state of the struct instance directly, which is particularly useful when working with large struct types or when mutations need to be reflected outside of the method scope.

Using _______ can help to synchronize goroutines in Go.

  • Arrays
  • Channels
  • Mutexes
  • Pointers
Using channels can help to synchronize goroutines in Go. Channels provide a way for goroutines to communicate and coordinate their execution safely without race conditions.