config für datenbankwerte angelegt und dessen lesen ermöglicht
This commit is contained in:
parent
4891a786d2
commit
8d2032829c
|
@ -0,0 +1,5 @@
|
|||
username: root
|
||||
password:
|
||||
address: localhost
|
||||
port: 3306
|
||||
database: events
|
|
@ -1,7 +1,9 @@
|
|||
package main
|
||||
|
||||
func getEvents() []event {
|
||||
db := dbConnect("root", "", "localhost", "3306", "ctdo")
|
||||
dbValues := readDatabaseYML()
|
||||
|
||||
db := dbConnect(dbValues.username, dbValues.password, dbValues.address, dbValues.port, dbValues.database)
|
||||
|
||||
rows := dbQuerry(db, "SELECT * FROM events;")
|
||||
|
||||
|
|
34
func.go
34
func.go
|
@ -206,3 +206,37 @@ func getNextTopic() topic {
|
|||
|
||||
return output
|
||||
}
|
||||
|
||||
func readDatabaseYML() database {
|
||||
file := fileRead("./config/database.yml")
|
||||
|
||||
rows := [][]string{}
|
||||
|
||||
for _, row := range strings.Split(file, "\n") {
|
||||
rows = append(rows, strings.Split(row, ": "))
|
||||
}
|
||||
|
||||
output := new(database)
|
||||
|
||||
for i, row := range rows {
|
||||
switch i {
|
||||
case 0:
|
||||
output.username = row[1]
|
||||
break
|
||||
case 1:
|
||||
output.password = row[1]
|
||||
break
|
||||
case 2:
|
||||
output.address = row[1]
|
||||
break
|
||||
case 3:
|
||||
output.port = row[1]
|
||||
break
|
||||
case 4:
|
||||
output.database = row[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return *output
|
||||
}
|
||||
|
|
|
@ -22,3 +22,11 @@ type topic struct {
|
|||
date string
|
||||
days int
|
||||
}
|
||||
|
||||
type database struct {
|
||||
username string
|
||||
password string
|
||||
address string
|
||||
port string
|
||||
database string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue