代码拉取完成,页面将自动刷新
package main
import (
"sync"
dep "github.com/hashicorp/consul-template/dependency"
)
// Brain is what Template uses to determine the values that are
// available for template parsing.
type Brain struct {
sync.RWMutex
// data is the map of individual dependencies (by HashCode()) and the most
// recent data for that dependency.
data map[string]interface{}
// receivedData is an internal tracker of which dependencies have stored data
// in the brain.
receivedData map[string]struct{}
}
// NewBrain creates a new Brain with empty values for each
// of the key structs.
func NewBrain() *Brain {
return &Brain{
data: make(map[string]interface{}),
receivedData: make(map[string]struct{}),
}
}
// Remember accepts a dependency and the data to store associated with that
// dep. This function converts the given data to a proper type and stores
// it interally.
func (b *Brain) Remember(d dep.Dependency, data interface{}) {
b.Lock()
defer b.Unlock()
b.data[d.HashCode()] = data
b.receivedData[d.HashCode()] = struct{}{}
}
// Recall gets the current value for the given dependency in the Brain.
func (b *Brain) Recall(d dep.Dependency) (interface{}, bool) {
b.RLock()
defer b.RUnlock()
// If we have not received data for this dependency, return now.
if _, ok := b.receivedData[d.HashCode()]; !ok {
return nil, false
}
return b.data[d.HashCode()], true
}
// ForceSet is used to force set the value of a dependency
// for a given hash code
func (b *Brain) ForceSet(hashCode string, data interface{}) {
b.Lock()
defer b.Unlock()
b.data[hashCode] = data
b.receivedData[hashCode] = struct{}{}
}
// Forget accepts a dependency and removes all associated data with this
// dependency. It also resets the "receivedData" internal map.
func (b *Brain) Forget(d dep.Dependency) {
b.Lock()
defer b.Unlock()
delete(b.data, d.HashCode())
delete(b.receivedData, d.HashCode())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。