48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package configkit
|
|
|
|
// Metadata provides detached effective presence/origin and chronological history
|
|
// queries for a load. Its zero value contains no paths.
|
|
type Metadata struct {
|
|
fields map[string]FieldInfo
|
|
history map[string][]Change
|
|
}
|
|
|
|
// Lookup returns information for an effective path. Unknown and invalid paths
|
|
// return false.
|
|
func (m Metadata) Lookup(path Path) (FieldInfo, bool) {
|
|
if !path.valid() {
|
|
return FieldInfo{}, false
|
|
}
|
|
info, ok := m.fields[path.String()]
|
|
if !ok {
|
|
return FieldInfo{}, false
|
|
}
|
|
return cloneFieldInfo(info), true
|
|
}
|
|
|
|
// IsExplicit reports whether a surviving input contribution explicitly defined
|
|
// path.
|
|
func (m Metadata) IsExplicit(path Path) bool {
|
|
info, ok := m.Lookup(path)
|
|
return ok && info.Explicit
|
|
}
|
|
|
|
// History returns detached definition and resolution records for path. A record's
|
|
// Path can be an ancestor when that container operation replaced or removed path.
|
|
// Removed historical paths can have history even though Lookup returns false.
|
|
// Unknown and invalid paths return nil.
|
|
func (m Metadata) History(path Path) []Change {
|
|
if !path.valid() {
|
|
return nil
|
|
}
|
|
history, ok := m.history[path.String()]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
cloned := make([]Change, len(history))
|
|
for i, change := range history {
|
|
cloned[i] = cloneChange(change)
|
|
}
|
|
return cloned
|
|
}
|