Snapshot mutex copied
Review this Go config holder. `Snapshot` returns a copy of the config for read-only use by handlers.
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.
0:00 of about 28 min
Mark a line and say what kind of problem it is.0 findings
1type Config struct {
2 mu sync.Mutex
3 Values map[string]string
4}
5
6func (c *Config) Set(k, v string) {
7 c.mu.Lock()
8 c.Values[k] = v
9 c.mu.Unlock()
10}
11
12func (c *Config) Snapshot() Config {
13 c.mu.Lock()
14 defer c.mu.Unlock()
15 return *c // copy under lock
16}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.