Exemple #1
0
// makeNews returns TOP 30 from hackernews
func makeNews(news *News, top int, table *tablewriter.Table, wg *sync.WaitGroup) {
	defer wg.Done()
	storyURL := fmt.Sprintf("https://hacker-news.firebaseio.com/v0/item/%s.json", strconv.Itoa(top))
	story, err := http.Get(storyURL)
	defer story.Body.Close()
	if err != nil {
		fmt.Errorf(err.Error())
	}
	json.NewDecoder(story.Body).Decode(&news)
	table.Append([]string{news.Title, news.URL})
}
Exemple #2
0
func (r *REPL) printPrettyRow(table *tablewriter.Table, keys []string, row map[string]interface{}) {

	buf := []string{}
	for _, k := range keys {
		js, err := json.Marshal(row[k])
		if err != nil {
			buf = append(buf, err.Error())
		} else {
			buf = append(buf, string(js))
		}
	}

	// Add fields to table in sorted order.
	table.Append(buf)
}
Exemple #3
0
func (r *Results) writeRows(t *tablewriter.Table, es *EntrySet) {
	for _, e := range es.Entries {
		t.Append(e.Row())
	}
}