MCPcopy Index your code
hub / github.com/foxcpp/maddy / ProcessWith

Method ProcessWith

framework/config/map.go:653–743  ·  view source on GitHub ↗

Process maps variables from global configuration and block passed in arguments.

(globalCfg map[string]interface{}, block Node)

Source from the content-addressed store, hash-verified

651
652// Process maps variables from global configuration and block passed in arguments.
653func (m *Map) ProcessWith(globalCfg map[string]interface{}, block Node) (unknown []Node, err error) {
654 unknown = make([]Node, 0, len(block.Children))
655 matched := make(map[string]bool)
656 m.Values = make(map[string]interface{})
657
658 for _, subnode := range block.Children {
659 matcher, ok := m.entries[subnode.Name]
660 if !ok {
661 if !m.allowUnknown {
662 return nil, NodeErr(subnode, "unexpected directive: %s", subnode.Name)
663 }
664 unknown = append(unknown, subnode)
665 continue
666 }
667
668 if matcher.customCallback != nil {
669 if err := matcher.customCallback(m, subnode); err != nil {
670 return nil, err
671 }
672 matched[subnode.Name] = true
673 continue
674 }
675
676 if matched[subnode.Name] {
677 return nil, NodeErr(subnode, "duplicate directive: %s", subnode.Name)
678 }
679 matched[subnode.Name] = true
680
681 val, err := matcher.mapper(m, subnode)
682 if err != nil {
683 return nil, err
684 }
685 m.Values[matcher.name] = val
686 if matcher.store != nil {
687 matcher.assign(val)
688 }
689 }
690
691 for _, matcher := range m.entries {
692 if matched[matcher.name] {
693 continue
694 }
695 if matcher.mapper == nil {
696 continue
697 }
698
699 var val interface{}
700 globalVal, ok := globalCfg[matcher.name]
701 if matcher.inheritGlobal && ok {
702 val = globalVal
703 } else if !matcher.required {
704 if matcher.defaultVal == nil {
705 continue
706 }
707
708 val, err = matcher.defaultVal()
709 if err != nil {
710 return nil, err

Callers 2

ProcessMethod · 0.95

Calls 2

assignMethod · 0.80
NodeErrFunction · 0.70