package page import ( "fmt" "os" "path/filepath" "reflect" "strings" ) // Checkup will return a map[string]PageList of all the pages broken down by // the status of their fields. For instance, whehter or not they have a date. func (p *Page) Checkup() (map[string]PageList, error) { Logger.Println("Checking up on all files...") out := make(map[string]PageList) _ = filepath.Walk(filepath.Dir("."), func(path string, info os.FileInfo, err error) error { if err != nil { return err } if !info.IsDir() && strings.HasSuffix(info.Name(), Suffix) { p2 := NewPage(strings.ReplaceAll(path, Suffix, "")) err = p2.Read() if err != nil { Logger.Println("Error encountered: ", err) return err } r := reflect.ValueOf(*p2) for i := 0; i < r.NumField(); i++ { key := "" f := r.Field(i) fi := r.Type().Field(i) if fi.PkgPath != "" { continue } name := fi.Name switch f.Interface().(type) { case string: if f.String() == "" { key = fmt.Sprintf("Empty \"%s\"", name) } else { key = fmt.Sprintf("Not Empty \"%s\"", name) } case bool: if !f.Bool() { key = fmt.Sprintf("\"%s\" is false", name) } else { key = fmt.Sprintf("\"%s\" is true", name) } case map[string]interface{}: case *PageTime: if f.IsNil() { key = fmt.Sprintf("\"%s\" is empty", name) } } if key == "" { continue } if _, ok := out[key]; !ok { out[key] = []*Page{p2} } else { out[key] = append(out[key], p2) } } } return nil }) return out, nil }