added debug mode

This commit is contained in:
Nickiel12 2023-12-30 15:16:26 -08:00
parent 8342a8f5f4
commit c16ffe3a2e
3 changed files with 9 additions and 24 deletions

2
api.go
View file

@ -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)
}

31
main.go
View file

@ -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

View file