configMenu returns a list of items to add to a menu in the web UI.
(fname string, u url.URL)
| 79 | |
| 80 | // configMenu returns a list of items to add to a menu in the web UI. |
| 81 | func configMenu(fname string, u url.URL) []configMenuEntry { |
| 82 | // Start with system configs. |
| 83 | configs := []namedConfig{{Name: "Default", config: defaultConfig()}} |
| 84 | if settings, err := readSettings(fname); err == nil { |
| 85 | // Add user configs. |
| 86 | configs = append(configs, settings.Configs...) |
| 87 | } |
| 88 | |
| 89 | // Convert to menu entries. |
| 90 | result := make([]configMenuEntry, len(configs)) |
| 91 | lastMatch := -1 |
| 92 | for i, cfg := range configs { |
| 93 | dst, changed := cfg.makeURL(u) |
| 94 | if !changed { |
| 95 | lastMatch = i |
| 96 | } |
| 97 | // Use a relative URL to work in presence of stripping/redirects in webui.go. |
| 98 | rel := &url.URL{RawQuery: dst.RawQuery, ForceQuery: true} |
| 99 | result[i] = configMenuEntry{ |
| 100 | Name: cfg.Name, |
| 101 | URL: rel.String(), |
| 102 | UserConfig: (i != 0), |
| 103 | } |
| 104 | } |
| 105 | // Mark the last matching config as current |
| 106 | if lastMatch >= 0 { |
| 107 | result[lastMatch].Current = true |
| 108 | } |
| 109 | return result |
| 110 | } |
| 111 | |
| 112 | // editSettings edits settings by applying fn to them. |
| 113 | func editSettings(fname string, fn func(s *settings) error) error { |
searching dependent graphs…