Other IT & Programming Subjects
GO Programming
What is the common way to have several executables in your project?
Explanation:
Have a cmd directory with a subdirectory per executable. Each subdirectory contains a main.go with its own main() function, enabling multiple binaries from one project.
What is the correct way to pass this as a body of an HTTP POST request? data := "A group of Owls is called a parliament"
Explanation:
Use strings.NewReader(data) to create an io.Reader from the string. HTTP Post requires an io.Reader for the request body, which NewReader provides.
What is the risk of using multiple field tags in a single struct?
Explanation:
Multiple tags tightly couple different layers of your application. Mixing JSON, database, and validation tags in one struct makes it harder to maintain separation of concerns.
What is the correct syntax ta start a goroutine that will print Hello Gopher!?
Explanation:
go fmt.Println("Hello Gopher!") starts a goroutine. The 'go' keyword before a function call executes it concurrently in a new goroutine.
What is the difference between the time package’s Time.Sub() and Time.Add() methods?
Explanation:
Time.Add() accepts Duration and returns Time; Time.Sub() accepts Time and returns Duration. Add advances time forward, Sub calculates the difference between two times.
What is a channel?
Explanation:
A channel is a medium for sending values between goroutines. Channels provide synchronized communication, allowing goroutines to safely share data without explicit locks.
What is the select statement used for?
Explanation:
Select executes different cases based on which channel returns first. It's used for concurrent channel operations, enabling non-blocking communication and timeouts.
What is a side effect of using time.After in a select statement?
Explanation:
The goroutine doesn't end until the time passes. time.After creates a goroutine with a timer that remains in memory until expiration, potentially causing memory leaks in loops.
What is an idiomatic way to customize the representation of a custom struct in a formatted string?
Explanation:
Implement String() string method. The fmt package calls String() when formatting values with %v or %s, allowing custom string representations.
What is the value of Read?
Explanation:
In Const (Write = iota; Read; Execute;), Read equals 1. iota starts at 0 for Write, increments to 1 for Read, and 2 for Execute in constant declarations.
What is an idiomatic way to pause execution of the current scope until an arbitrary number of goroutines have returned?
Explanation:
Sync.WaitGroup waits for goroutines to complete. Use Add() before starting goroutines, Done() when they finish, and Wait() to block until all are done.
What is the default case sensitivity of the JSON Unmarshal function?
Explanation:
JSON Unmarshal is case insensitive by default. It matches JSON fields to struct fields regardless of case, making JSON parsing more flexible and forgiving.
Filter by Difficulty
Difficulty Filter
Sign in to unlock
Sign in to unlock