settings.go (go1.19.src) | : | settings.go (go1.19.1.src) | ||
---|---|---|---|---|
skipping to change at line 82 | skipping to change at line 82 | |||
// configMenuEntry holds information for a single config menu entry. | // configMenuEntry holds information for a single config menu entry. | |||
type configMenuEntry struct { | type configMenuEntry struct { | |||
Name string | Name string | |||
URL string | URL string | |||
Current bool // Is this the currently selected config? | Current bool // Is this the currently selected config? | |||
UserConfig bool // Is this a user-provided config? | UserConfig bool // Is this a user-provided config? | |||
} | } | |||
// configMenu returns a list of items to add to a menu in the web UI. | // configMenu returns a list of items to add to a menu in the web UI. | |||
func configMenu(fname string, url url.URL) []configMenuEntry { | func configMenu(fname string, u url.URL) []configMenuEntry { | |||
// Start with system configs. | // Start with system configs. | |||
configs := []namedConfig{{Name: "Default", config: defaultConfig()}} | configs := []namedConfig{{Name: "Default", config: defaultConfig()}} | |||
if settings, err := readSettings(fname); err == nil { | if settings, err := readSettings(fname); err == nil { | |||
// Add user configs. | // Add user configs. | |||
configs = append(configs, settings.Configs...) | configs = append(configs, settings.Configs...) | |||
} | } | |||
// Convert to menu entries. | // Convert to menu entries. | |||
result := make([]configMenuEntry, len(configs)) | result := make([]configMenuEntry, len(configs)) | |||
lastMatch := -1 | lastMatch := -1 | |||
for i, cfg := range configs { | for i, cfg := range configs { | |||
dst, changed := cfg.config.makeURL(url) | dst, changed := cfg.config.makeURL(u) | |||
if !changed { | if !changed { | |||
lastMatch = i | lastMatch = i | |||
} | } | |||
// Use a relative URL to work in presence of stripping/redirects | ||||
in webui.go. | ||||
rel := &url.URL{RawQuery: dst.RawQuery, ForceQuery: true} | ||||
result[i] = configMenuEntry{ | result[i] = configMenuEntry{ | |||
Name: cfg.Name, | Name: cfg.Name, | |||
URL: dst.String(), | URL: rel.String(), | |||
UserConfig: (i != 0), | UserConfig: (i != 0), | |||
} | } | |||
} | } | |||
// Mark the last matching config as currennt | // Mark the last matching config as currennt | |||
if lastMatch >= 0 { | if lastMatch >= 0 { | |||
result[lastMatch].Current = true | result[lastMatch].Current = true | |||
} | } | |||
return result | return result | |||
} | } | |||
End of changes. 4 change blocks. | ||||
3 lines changed or deleted | 6 lines changed or added |