Code Room
Code reviewHard
Question
Review this Go lazy-connection initializer.
What is the bug with this sync.Once usage?
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
type DB struct { once sync.Once conn *sql.DB} func (d *DB) Conn() (*sql.DB, error) { var err error d.once.Do(func() { d.conn, err = sql.Open("postgres", dsn()) if err == nil { err = d.conn.Ping() // verify connectivity } }) return d.conn, err}Run or narrate your approach, then ask the coach.