diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..698ac6c --- /dev/null +++ b/config/database.yml @@ -0,0 +1,5 @@ +username: root +password: +address: localhost +port: 3306 +database: events \ No newline at end of file diff --git a/events.go b/events.go index fde085a..b6d7c8f 100644 --- a/events.go +++ b/events.go @@ -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;") diff --git a/func.go b/func.go index 54835b0..054b9e2 100644 --- a/func.go +++ b/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 +} diff --git a/structs.go b/structs.go index daff66b..6a3ce74 100644 --- a/structs.go +++ b/structs.go @@ -22,3 +22,11 @@ type topic struct { date string days int } + +type database struct { + username string + password string + address string + port string + database string +}