From 1311fe103c29417ceb30ff937844c67e46f7d160 Mon Sep 17 00:00:00 2001 From: CornierKhan1 Date: Mon, 10 Dec 2018 11:34:49 +1100 Subject: [PATCH] Added DB Ping. Updated Structures. Updated Config. --- config.xml.example | 2 ++ main.go | 7 +++++-- structure.go | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config.xml.example b/config.xml.example index 19d73e0..a8e105c 100644 --- a/config.xml.example +++ b/config.xml.example @@ -1,6 +1,8 @@ uwu owo + uwu + 127.0.0.1:3306 127.0.0.1:8080 diff --git a/main.go b/main.go index 430ca04..a8cab5e 100644 --- a/main.go +++ b/main.go @@ -64,9 +64,12 @@ func main() { // Start SQL. db, err := sql.Open("mysql", - CON.SQLUser+":"+CON.SQLPass+"@tcp(127.0.0.1:3306)/hello") + CON.SQLUser+":"+CON.SQLPass+"@tcp("+CON.SQLPort+")/"+CON.SQLDB) CheckError(err) + defer db.Close() + err = db.Ping() + CheckError(err) // Start the HTTP server. fmt.Println("Starting HTTP connection (" + CON.Port + ")...") @@ -92,7 +95,7 @@ func handler(w http.ResponseWriter, r *http.Request) { // The switch converts the HTTP Body of the request into a string. There is no need to convert the cases to byte format. switch string(body) { - // TODO: Make the case functions cleaner. (e.g. The should the response be a variable?) + // TODO: Make the case functions cleaner. (e.g. Should the response be a variable?) // TODO: Update the responses so that they query the SQL Database for the proper information (e.g. Device Code, Token, etc). case "CheckDeviceStatus": diff --git a/structure.go b/structure.go index 0d8670d..2a0c132 100644 --- a/structure.go +++ b/structure.go @@ -1,6 +1,8 @@ package main -import "encoding/xml" +import ( + "encoding/xml" +) // Copyright (C) 2018 CornierKhan1 // @@ -28,7 +30,9 @@ type Config struct { XMLName xml.Name `xml:"Config"` SQLUser string `xml:"SQLUser"` SQLPass string `xml:"SQLPass"` + SQLPort string `xml:"SQLPort"` Port string `xml:"Port"` + SQLDB string `xml:"SQLDB"` } // CheckDeviceStatus