Add comments and refactored map syntax for validLogViewerUIConfig

Co-authored-by: Jared Scheib <jared.scheib@gmail.com>
pull/3806/head
Alirie Gray 2018-07-03 11:12:07 -07:00 committed by Jared Scheib
parent 5894e8d881
commit c33d4aa856
1 changed files with 8 additions and 3 deletions

View File

@ -173,6 +173,11 @@ func (s *Service) ReplaceAuthConfig(w http.ResponseWriter, r *http.Request) {
encodeJSON(w, http.StatusOK, res, s.Logger)
}
// validLogViewerUIConfig ensures that the request body log viewer UI config is valid
// to be valid, it must: not be empty, have at least one column, not have multiple
// columns with the same name or position value, each column must have a visbility
// of either "visible" or "hidden" and if a column is of type severity, it must have
// at least one severity format of type icon, text, or both
func validLogViewerUIConfig(cfg chronograf.LogViewerUIConfig) error {
if len(cfg.Columns) == 0 {
return fmt.Errorf("Invalid log viewer UI config: must have at least 1 column")
@ -186,12 +191,12 @@ func validLogViewerUIConfig(cfg chronograf.LogViewerUIConfig) error {
textCount := 0
visibility := 0
if nameMatcher[clm.Name] == true {
// check that each column has a unique value for the name and position properties
if _, ok := nameMatcher[clm.Name]; ok {
return fmt.Errorf("Invalid log viewer UI config: Duplicate column name %s", clm.Name)
}
nameMatcher[clm.Name] = true
if positionMatcher[clm.Position] == true {
if _, ok := positionMatcher[clm.Position]; ok {
return fmt.Errorf("Invalid log viewer UI config: Multiple columns with same position value")
}
positionMatcher[clm.Position] = true