[feature] Use Read/Write lock for config (#1969)

This commit is contained in:
Daenney 2023-07-10 13:56:14 +02:00 committed by GitHub
parent 6de5ca46f8
commit f0dad439f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 323 additions and 323 deletions

View File

@ -105,9 +105,9 @@ func generateFields(output io.Writer, prefixes []string, t reflect.Type) {
// ConfigState structure helper methods
fmt.Fprintf(output, "// Get%s safely fetches the Configuration value for state's '%s' field\n", name, fieldPath)
fmt.Fprintf(output, "func (st *ConfigState) Get%s() (v %s) {\n", name, fieldType)
fmt.Fprintf(output, "\tst.mutex.Lock()\n")
fmt.Fprintf(output, "\tst.mutex.RLock()\n")
fmt.Fprintf(output, "\tv = st.config.%s\n", fieldPath)
fmt.Fprintf(output, "\tst.mutex.Unlock()\n")
fmt.Fprintf(output, "\tst.mutex.RUnlock()\n")
fmt.Fprintf(output, "\treturn\n")
fmt.Fprintf(output, "}\n\n")
fmt.Fprintf(output, "// Set%s safely sets the Configuration value for state's '%s' field\n", name, fieldPath)

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ import (
type ConfigState struct { //nolint
viper *viper.Viper
config Configuration
mutex sync.Mutex
mutex sync.RWMutex
}
// NewState returns a new initialized ConfigState instance.