Code Room
Code reviewMedium
Question
Review this Go lazy initializer that replaces a hand-rolled double-checked lock with sync.Once.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
var ( once sync.Once db *sql.DB) func DB() *sql.DB { once.Do(func() { conn, err := sql.Open("postgres", dsn) if err != nil { return } if err := conn.Ping(); err != nil { return } db = conn }) return db}Run or narrate your approach, then ask the coach.