lotus/node/config/doc_util.go
2021-07-23 15:17:22 +02:00

45 lines
689 B
Go

package config
import (
"fmt"
"strings"
)
func findDoc(root interface{}, section, name string) *DocField {
rt := fmt.Sprintf("%T", root)[len("*config."):]
doc := findDocSect(rt, section, name)
if doc != nil {
return doc
}
return findDocSect("Common", section, name)
}
func findDocSect(root string, section, name string) *DocField {
path := strings.Split(section, ".")
docSection := Doc[root]
for _, e := range path {
if docSection == nil {
return nil
}
for _, field := range docSection {
if field.Name == e {
docSection = Doc[field.Type]
break
}
}
}
for _, df := range docSection {
if df.Name == name {
return &df
}
}
return nil
}