From c16ffe3a2e7a675b7c19db0df66df96a6417ec86 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sat, 30 Dec 2023 15:16:26 -0800 Subject: [PATCH] added debug mode --- api.go | 2 +- main.go | 31 ++++++++----------------------- tests/source_file.sqlite3 | 0 3 files changed, 9 insertions(+), 24 deletions(-) create mode 100644 tests/source_file.sqlite3 diff --git a/api.go b/api.go index 24ec9c1..a6197b8 100644 --- a/api.go +++ b/api.go @@ -32,7 +32,7 @@ func apiRouter() http.Handler { } func getTransactions(w http.ResponseWriter, req *http.Request) { - db, err := sqlx.Connect("postgres", "user=rcntuser password=Devel@pmentPa$$w0rd host=10.0.0.183 dbname=Borealis sslmode=disable") + db, err := sqlx.Connect("postgres", DB_CONNECTION_STRING) if err != nil { log.Fatal(err) } diff --git a/main.go b/main.go index 9494fc1..bdc9a7f 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "net/http" "fmt" + "flag" "log" "time" @@ -13,6 +14,8 @@ import ( "github.com/go-chi/chi/v5/middleware" ) +var DB_CONNECTION_STRING string = "user=rcntuser password=Devel@pmentPa$$w0rd host=10.0.0.183 dbname=Borealis sslmode=disable" + // "json:"json_code_name,omitempty"" (omit empty) // if you use `json:"-"` it doesn't encode it type Transaction struct { @@ -40,31 +43,13 @@ func main() { log.SetPrefix("RecountServer: ") log.SetFlags(0) - /* - jsonExample := `{ - "Id": 3, - "Amount": "100", - "Description": { - "String": "Transaction 3", - "Valid": true - }, - "Account": 1, - "Bucket": { - "Int64": 1, - "Valid": true - }, - "TransactionDate": "2023-11-11T00:00:00Z" - }` + var nFlag = flag.Bool("d", false, "whether to enable debug mode") + flag.Parse() - var trns Transaction = Transaction{} - err = json.Unmarshal([]byte(jsonExample), &trns) - - if err != nil { - log.Println(err) - } else { - log.Println(trns.Amount) + if *nFlag { + log.Println("Is debugging") } - */ + r := chi.NewRouter() // A good base middleware stack diff --git a/tests/source_file.sqlite3 b/tests/source_file.sqlite3 new file mode 100644 index 0000000..e69de29