package templates import ( "fmt" ) // Result list definition const result_list_open string = `` // Result item definition const result_item string = `
  • %s
  • ` // Table wrapper definitions const table_open string = `` const table_close string = `
    ` // Header definitions const table_head_open string = `` const table_head_close string = `` const table_head_row string = `%s` // Body definitions const table_body_open string = `` const table_body_close string = `` const table_body_row string = `%v` // Error message const query_error_message string = `

    Query Error: %s

    ` const query_error_message_blank string = `` func ErrorQueryResults(e error) string { return result_list_open + result_list_close + fmt.Sprintf(query_error_message, e.Error()) } func ConcatResults(items []string) string { var html string = result_list_open for _, h := range items { html += h } return html + result_list_close } func QueryResult(cols []string, rows []map[string]interface{}) string { head := generateHead(cols) body := table_body_open for _, row := range rows { body += generateRow(cols, row) } body += table_body_close return fmt.Sprintf(result_item, table_open+head+body+table_close+query_error_message_blank) } // Generate the tables head row func generateHead(cols []string) string { html := table_head_open for _, col := range cols { html += fmt.Sprintf(table_head_row, col) } return html + table_head_close } func generateRow(cols []string, data map[string]interface{}) string { row := "" for _, col := range cols { row += fmt.Sprintf(table_body_row, data[col]) } return row + "" }