From 7734e5d911cb4dfb6e36ab4f8dfed960304a6829 Mon Sep 17 00:00:00 2001 From: CornierKhan1 Date: Thu, 18 Oct 2018 16:49:29 +1100 Subject: [PATCH] It's messy rn, but I'll clean it up. uwu --- config.json | 5 +++++ core.go | 16 ++++++++++++++++ main.go | 19 +++++++++++++++++++ structure.go | 6 ++++++ 4 files changed, 46 insertions(+) create mode 100644 config.json create mode 100644 core.go diff --git a/config.json b/config.json new file mode 100644 index 0000000..31af0b7 --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "SQLUser":"username", + "SQLPass":"password", + "Port":"2018" +} \ No newline at end of file diff --git a/core.go b/core.go new file mode 100644 index 0000000..49dacbe --- /dev/null +++ b/core.go @@ -0,0 +1,16 @@ +package main + +import ( + "database/sql" + _ "github.com/go-sql-driver/mysql" + "log" +) + +func StartSQL() { + db, err := sql.Open("mysql", + "opensoap:@tcp(127.0.0.1:3306)/hello") + if err != nil { + log.Fatal(err) + } + defer db.Close() +} diff --git a/main.go b/main.go index 81e0021..5b0fb1b 100644 --- a/main.go +++ b/main.go @@ -19,8 +19,10 @@ package main import ( "bytes" + "encoding/json" "encoding/xml" "fmt" + _ "github.com/go-sql-driver/mysql" "io/ioutil" "log" "net/http" @@ -35,7 +37,24 @@ const ( Header = `` + "\n" ) +var configs []Config + +// CheckError makes error handling not as ugly and inefficient. +func CheckError(e error) { + if e != nil { + log.Fatal("There has been an error while performing this action. Reason: ", e) + } +} + func main() { + configblob, err := ioutil.ReadFile("config.json") + CheckError(err) + err = json.Unmarshal(configblob, &configs) + CheckError(err) + + fmt.Println("Open SOAP-GO for Server Environments.") + fmt.Println("Initializing core...") + fmt.Println("Starting HTTP connection (Port 2018)...") fmt.Println("NOTICE: The SOAP Server runs under a port that doesn't work with WSC naturally.") fmt.Println("You can either use proxying from Nginx (recommended) or another web server software, or edit this script to use port 80.") diff --git a/structure.go b/structure.go index 6aa97a5..75dec73 100644 --- a/structure.go +++ b/structure.go @@ -24,6 +24,12 @@ import "encoding/xml" ///////////////////// // The structures may seem repetitive and redundant, but blame WSC's inconsistent SOAP requests. +type Config struct { + SQLUser string + SQLPass string + Port string +} + // CheckDeviceStatus type CDS struct { XMLName xml.Name `xml:"Envelope"`