webadmin: make routes configurable: globally, per domain, per account

this simplifies some of the code that makes modifications to the config file. a
few protected functions can make changes to the dynamic config, which webadmin
can use. instead of having separate functions in mox-/admin.go for each type of
change.

this also exports the parsed full dynamic config to webadmin, so we need fewer
functions for specific config fields too.
This commit is contained in:
Mechiel Lukkien
2024-04-18 11:14:24 +02:00
parent baf4df55a6
commit a69887bfab
19 changed files with 1165 additions and 189 deletions

View File

@ -181,15 +181,21 @@ func parseSection(t *doc.Type, pp *parsedPackage) *section {
}
// Ensure type "t" (used in a field or argument) defined in package pp is parsed
// and added to the section.
func ensureNamedType(t *doc.Type, sec *section, pp *parsedPackage) {
typePath := pp.Path + "." + t.Name
// and added to the section. The returned string is the name as used in the
// sherpadoc, it may have been renamed.
func ensureNamedType(t *doc.Type, sec *section, pp *parsedPackage) (name string) {
if s, ok := renames[renameSrc{pp.Pkg.Name, t.Name}]; ok {
name = s
} else {
name = t.Name
}
typePath := pp.Path + "." + name
if _, have := sec.Typeset[typePath]; have {
return
}
tt := &namedType{
Name: t.Name,
Name: name,
Text: strings.TrimSpace(t.Doc),
}
// add it early, so self-referencing types can't cause a loop
@ -360,6 +366,7 @@ func ensureNamedType(t *doc.Type, sec *section, pp *parsedPackage) {
default:
logFatalLinef(pp, t.Decl.TokPos, "unsupported field/param/return type %T", ts.Type)
}
return
}
func hasOmitEmpty(tag *ast.BasicLit) bool {
@ -407,8 +414,8 @@ func gatherFieldType(typeName string, f *field, e ast.Expr, fieldTag *ast.BasicL
case *ast.Ident:
tt := pp.lookupType(t.Name)
if tt != nil {
ensureNamedType(tt, sec, pp)
return []string{t.Name}
name := ensureNamedType(tt, sec, pp)
return []string{name}
}
commaString := isCommaString(fieldTag)
name := t.Name
@ -465,8 +472,8 @@ func parseArgType(e ast.Expr, sec *section, pp *parsedPackage) typewords {
case *ast.Ident:
tt := pp.lookupType(t.Name)
if tt != nil {
ensureNamedType(tt, sec, pp)
return []string{t.Name}
name := ensureNamedType(tt, sec, pp)
return []string{name}
}
name := t.Name
switch name {
@ -560,8 +567,7 @@ func parseSelector(t *ast.SelectorExpr, srcTypeName string, sec *section, pp *pa
if tt == nil {
logFatalLinef(pp, t.Pos(), "could not find type %q in package %q", typeName, importPath)
}
ensureNamedType(tt, sec, opp)
return typeName
return ensureNamedType(tt, sec, opp)
}
type replacement struct {