update records an updated GODEBUG setting. def is the default GODEBUG setting for the running binary, and env is the current value of the $GODEBUG environment variable.
(def, env string)
| 175 | // def is the default GODEBUG setting for the running binary, |
| 176 | // and env is the current value of the $GODEBUG environment variable. |
| 177 | func update(def, env string) { |
| 178 | updateMu.Lock() |
| 179 | defer updateMu.Unlock() |
| 180 | |
| 181 | // Update all the cached values, creating new ones as needed. |
| 182 | // We parse the environment variable first, so that any settings it has |
| 183 | // are already locked in place (did[name] = true) before we consider |
| 184 | // the defaults. |
| 185 | did := make(map[string]bool) |
| 186 | parse(did, env) |
| 187 | parse(did, def) |
| 188 | |
| 189 | // Clear any cached values that are no longer present. |
| 190 | cache.Range(func(name, s any) bool { |
| 191 | if !did[name.(string)] { |
| 192 | s.(*setting).value.Store(&empty) |
| 193 | } |
| 194 | return true |
| 195 | }) |
| 196 | } |
| 197 | |
| 198 | // parse parses the GODEBUG setting string s, |
| 199 | // which has the form k=v,k2=v2,k3=v3. |