func getStringSlice(r livestatus.Record, key string) ([]string, error) { data, err := r.GetSlice(key) if err != nil { return []string{}, err } result := []string{} for _, entry := range data { value, ok := entry.(string) if ok { result = append(result, value) } } return result, nil }
func getComments(r livestatus.Record) ([]Comment, error) { data, err := r.GetSlice("comments_with_extra_info") if err != nil { return []Comment{}, err } result := []Comment{} for _, entry := range data { slice, ok := entry.([]interface{}) if !ok || len(slice) != 5 { logger.Error("poller", "skipping comment entry %v", entry) continue } ct, ok := slice[3].(float64) if !ok { logger.Error("poller", "unable to parse comment type: skipping entry %v", entry) continue } cd, ok := slice[4].(float64) if !ok { logger.Error("poller", "unable to parse comment date: skipping entry %v", entry) continue } result = append(result, Comment{ Author: fmt.Sprintf("%v", slice[1]), Content: fmt.Sprintf("%v", slice[2]), Type: int64(ct), Date: time.Unix(int64(cd), 0), }) } return result, nil }