The syntax for type switch in Go resembles a regular _______ statement.

  • For
  • If
  • Select
  • Switch
Type switch in Go shares a similar syntax with a regular switch statement. However, instead of checking values of expressions, it checks the types of values. This construct allows the execution of different blocks of code based on the type of an interface variable, providing flexibility and readability in handling diverse types. Understanding this syntax is crucial for effective type-based branching in Go programs.

What is the purpose of a JSON Web Token (JWT) in authentication?

  • To authenticate and authorize
  • To encrypt data during transit
  • To provide a digital signature
  • To store user session data
The purpose of a JSON Web Token (JWT) in authentication is to authenticate and authorize users. JWTs are used to securely transmit information between parties and can contain claims that assert information about the user, which can be verified and trusted.

In Go, a _______ function is a function that can accept one or more functions as arguments or return a function.

  • Callback
  • Higher-order
  • Nested
  • Recursive
In Go, a higher-order function is a function that can accept one or more functions as arguments or return a function. This capability allows for more flexible and modular code by enabling functions to be passed as parameters and returned as values.

What are the common strategies for session management in web applications?

  • Using JSON Web Tokens (JWT)
  • Using URL rewriting
  • Using cookies
  • Using session tokens
Session management in web applications involves various strategies. Using session tokens is a common approach where a unique token is generated for each session and stored either in a database or in-memory. This token is then validated on subsequent requests to authenticate the user's session.

You're developing a Go application where you need to declare a constant named 'MaxRetryAttempts' to specify the maximum number of retry attempts. Which data type would you use for this constant?

  • bool
  • float64
  • int
  • string
In Go, constants can be of various types including numeric constants. Since 'MaxRetryAttempts' is specifying the maximum number of retry attempts, it would typically be represented as an integer. Therefore, you'd use the 'int' data type for this constant.

In database migration, what does the term 'down' typically signify?

  • Connecting to a database
  • Creating a backup of the database
  • Reverting applied migrations to roll back changes
  • Updating database records
In database migration, the term 'down' typically signifies reverting applied migrations to roll back changes made to the database schema. This involves executing scripts or commands to undo previous migrations, restoring the database schema to its previous state before the migration was applied.

Using reflection, you can dynamically create _______ and call their methods.

  • arrays
  • interfaces
  • maps
  • structs
Using reflection in Go, you can dynamically create interfaces and call their methods. Reflection allows you to inspect and manipulate types, functions, and variables at runtime, which can be useful in scenarios like building generic algorithms or implementing plugins. With reflection, you can create instances of interfaces, invoke their methods, and inspect their properties dynamically.

Database migration scripts are often version-controlled using _______.

  • Git
  • Mercurial
  • Perforce
  • Subversion
Version control systems like Git are commonly used to manage changes to database migration scripts, allowing for tracking, collaboration, and rollback.

Which method in the database/sql package is used to close a database connection?

  • Close
  • Shutdown
  • Disconnect
  • End
The correct option is Close. In Go's database/sql package, the Close method is used to close a database connection explicitly. It's essential to close connections properly to release resources and prevent leaks.

How are fields accessed in a struct?

  • By using arrow notation
  • By using bracket notation
  • By using dot notation
  • By using parenthesis notation
Fields in a struct are accessed using dot notation in Go. This involves typing the name of the struct variable followed by a dot (.) and then the name of the field to access its value.