pull updates from demo plugin pr
This commit is contained in:
parent
eb2678c625
commit
75eccc0628
1 changed files with 10 additions and 2 deletions
|
@ -6,8 +6,7 @@ import (
|
||||||
|
|
||||||
// configuration captures the plugin's external configuration as exposed in the Mattermost server
|
// configuration captures the plugin's external configuration as exposed in the Mattermost server
|
||||||
// configuration, as well as values computed from the configuration. Any public fields will be
|
// configuration, as well as values computed from the configuration. Any public fields will be
|
||||||
// deserialized from the Mattermost server configuration in OnConfigurationChange, while any
|
// deserialized from the Mattermost server configuration in OnConfigurationChange.
|
||||||
// private fields will be ignored.
|
|
||||||
//
|
//
|
||||||
// As plugins are inherently concurrent (hooks being called asynchronously), and the plugin
|
// As plugins are inherently concurrent (hooks being called asynchronously), and the plugin
|
||||||
// configuration can change at any time, access to the configuration must be synchronized. The
|
// configuration can change at any time, access to the configuration must be synchronized. The
|
||||||
|
@ -45,9 +44,18 @@ func (p *Plugin) getConfiguration() *configuration {
|
||||||
// Do not call setConfiguration while holding the configurationLock, as sync.Mutex is not
|
// Do not call setConfiguration while holding the configurationLock, as sync.Mutex is not
|
||||||
// reentrant. In particular, avoid using the plugin API entirely, as this may in turn trigger a
|
// reentrant. In particular, avoid using the plugin API entirely, as this may in turn trigger a
|
||||||
// hook back into the plugin. If that hook attempts to acquire this lock, a deadlock may occur.
|
// hook back into the plugin. If that hook attempts to acquire this lock, a deadlock may occur.
|
||||||
|
//
|
||||||
|
// This method panics if setConfiguration is called with the existing configuration. This almost
|
||||||
|
// certainly means that the configuration was modified without being cloned and may result in
|
||||||
|
// an unsafe access.
|
||||||
func (p *Plugin) setConfiguration(configuration *configuration) {
|
func (p *Plugin) setConfiguration(configuration *configuration) {
|
||||||
p.configurationLock.Lock()
|
p.configurationLock.Lock()
|
||||||
defer p.configurationLock.Unlock()
|
defer p.configurationLock.Unlock()
|
||||||
|
|
||||||
|
if configuration != nil && p.configuration == configuration {
|
||||||
|
panic("setConfiguration called with the existing configuration")
|
||||||
|
}
|
||||||
|
|
||||||
p.configuration = configuration
|
p.configuration = configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue