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) { 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

31
main.go
View file

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"fmt" "fmt"
"flag"
"log" "log"
"time" "time"
@ -13,6 +14,8 @@ import (
"github.com/go-chi/chi/v5/middleware" "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) // "json:"json_code_name,omitempty"" (omit empty)
// if you use `json:"-"` it doesn't encode it // if you use `json:"-"` it doesn't encode it
type Transaction struct { type Transaction struct {
@ -40,31 +43,13 @@ func main() {
log.SetPrefix("RecountServer: ") log.SetPrefix("RecountServer: ")
log.SetFlags(0) log.SetFlags(0)
/* var nFlag = flag.Bool("d", false, "whether to enable debug mode")
jsonExample := `{ flag.Parse()
"Id": 3,
"Amount": "100",
"Description": {
"String": "Transaction 3",
"Valid": true
},
"Account": 1,
"Bucket": {
"Int64": 1,
"Valid": true
},
"TransactionDate": "2023-11-11T00:00:00Z"
}`
var trns Transaction = Transaction{} if *nFlag {
err = json.Unmarshal([]byte(jsonExample), &trns) log.Println("Is debugging")
if err != nil {
log.Println(err)
} else {
log.Println(trns.Amount)
} }
*/
r := chi.NewRouter() r := chi.NewRouter()
// A good base middleware stack // A good base middleware stack

View file