package main import ( "database/sql" _ "modernc.org/sqlite" "text/template" "os" "strings" ) var opml = ` Bahá'í Prayers {{- range .}} {{- end}} ` type Prayer struct{ Phelps string ID string Language string Author string Text string } func main() { var prayers []Prayer db, err := sql.Open("sqlite", "holywritings.db") if err != nil { panic(err) } rows, err := db.Query("select id, author, language, text, phelps from writings;") if err != nil { panic(err) } for rows.Next() { var prayer Prayer rows.Scan(&prayer.ID, &prayer.Author, &prayer.Language, &prayer.Text, &prayer.Phelps) switch prayer.Author { case "Báb": prayer.Author = "bab" case "`Abdu'l-Bahá": prayer.Author = "abdulbaha" case "Bahá'u'lláh": prayer.Author = "bahaullah" } prayer.Text = template.HTMLEscapeString(prayer.Text) prayer.Text = strings.ReplaceAll(prayer.Text, "\r", "") prayer.Text = strings.ReplaceAll(prayer.Text, "\n", " ") if prayer.Text == "" {println(prayer.ID)} prayers = append(prayers, prayer) } tmpl, err := template.New("opml").Parse(opml) if err != nil { panic(err) } err = tmpl.Execute(os.Stdout, prayers) if err != nil { panic(err) } }