Datenbank Script erstellt, mit Events angefangen
This commit is contained in:
parent
ea5e59b45d
commit
189fc4c5f2
|
@ -0,0 +1,28 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dbConnect(username string, password string, address string, port string, database string) *sql.DB {
|
||||||
|
db, err := sql.Open("mysql", username+":"+password+"@tcp("+address+":"+port+")/"+database)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
func dbClose(database *sql.DB) {
|
||||||
|
database.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func dbQuerry(database *sql.DB, sqlCode string) *sql.Rows {
|
||||||
|
results, err := database.Query("SELECT id, name FROM tags")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
func getEvents() []event {
|
||||||
|
db := dbConnect("root", "", "localhost", "3306", "ctdo")
|
||||||
|
|
||||||
|
rows := dbQuerry(db, "SELECT * FROM events;")
|
||||||
|
|
||||||
|
events := []event{}
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
Event := new(event)
|
||||||
|
err := rows.Scan(&Event.date, &Event.description, &Event.media, &Event.title)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
events = append(events, *Event)
|
||||||
|
}
|
||||||
|
|
||||||
|
return events
|
||||||
|
}
|
9
func.go
9
func.go
|
@ -134,6 +134,15 @@ func htmlReplacer(input string, activePage string) string {
|
||||||
output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet in "+string(getNextTopic().days)+" Tagen statt!", "class=\"topic\"")+htmlElement("p", "Am "+getNextTopic().date, "class=\"topic\""))
|
output = strings.ReplaceAll(output, "!TOPICTREFF", htmlElement("h3", "Nächster Topictreff findet in "+string(getNextTopic().days)+" Tagen statt!", "class=\"topic\"")+htmlElement("p", "Am "+getNextTopic().date, "class=\"topic\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events := getEvents()
|
||||||
|
|
||||||
|
if len(events) == 0 {
|
||||||
|
output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
||||||
|
} else {
|
||||||
|
|
||||||
|
output = strings.ReplaceAll(output, "!EVENTS", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
||||||
|
}
|
||||||
|
|
||||||
output = strings.ReplaceAll(output, "!NEWBANNER", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
output = strings.ReplaceAll(output, "!NEWBANNER", htmlNewBanner("Rundgang", "https://www.chaostreff-dortmund.de/rundgang/"))
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
Loading…
Reference in New Issue