ctdo.de/events.go

56 lines
1.0 KiB
Go

package main
func getEvents() []event {
db := ctdoConnect()
rows := dbQuerry(db, "SELECT * FROM events;")
events := []event{}
for rows.Next() {
Event := new(event)
err := rows.Scan(&Event.id, &Event.title, &Event.description, &Event.media, &Event.date)
if err != nil {
panic(err.Error())
}
events = append(events, *Event)
}
return events
}
func addEvent(Event event) bool {
db := ctdoConnect()
if len(Event.title) > 80 || len(Event.description) > 500 || len(Event.media) > 10000 || len(Event.date) > 10 {
return false
}
dbQuerry(db, "insert into events (title, description, media, date) values ('"+Event.title+"', '"+Event.description+"', '"+Event.media+"', '"+Event.date+"');")
return true
}
func getAdminKeys() []string {
db := ctdoConnect()
rows := dbQuerry(db, "select * from adminKeys;")
output := []string{}
for rows.Next() {
temp := ""
err := rows.Scan(&temp)
if err != nil {
panic(err.Error())
}
output = append(output, temp)
}
if len(output) == 0 {
return nil
}
return output
}