Recount-Server/main.go
2023-12-30 15:16:26 -08:00

76 lines
2 KiB
Go

package main
import (
"database/sql"
"net/http"
"fmt"
"flag"
"log"
"time"
//"github.com/shopspring/decimal"
"github.com/go-chi/chi/v5"
"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 {
Id int `db:"trns_id" json:"Id"`
Amount string `db:"trns_amount" json:"Amount"`
Description sql.NullString `db:"trns_description" json:"Description"`
Account int `db:"trns_account" json:"Account"`
Bucket sql.NullInt64 `db:"trns_bucket" json:"Bucket"`
Date time.Time `db:"trns_date" json:"TransactionDate"`
}
func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello\n")
}
func headers(w http.ResponseWriter, req *http.Request) {
for name, headers := range req.Header {
for _, h := range headers {
fmt.Fprintf(w, "%v: %v\n", name, h)
}
}
}
func main() {
log.SetPrefix("RecountServer: ")
log.SetFlags(0)
var nFlag = flag.Bool("d", false, "whether to enable debug mode")
flag.Parse()
if *nFlag {
log.Println("Is debugging")
}
r := chi.NewRouter()
// A good base middleware stack
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Recoverer)
r.Use(middleware.Logger)
// Set a timeout value on the request context (ctx), that will signal
// through ctx.Done() that the request has timed out and further
// processing should be stopped.
//r.Use(middleware.Timeout(60 * time.Second))
r.Get("/", hello)
r.Get("/headers", headers)
r.Mount("/api", apiRouter())
err := http.ListenAndServe(":8090", r)
if err != nil {
log.Fatal(err)
}
//fmt.Println("Hello World")
}