2023-12-19 20:13:32 -08:00
|
|
|
package main
|
2023-12-17 21:21:29 -08:00
|
|
|
|
2023-12-19 20:13:32 -08:00
|
|
|
import (
|
2023-12-19 22:03:09 -08:00
|
|
|
//"database/sql"
|
2023-12-19 20:13:32 -08:00
|
|
|
"fmt"
|
|
|
|
"log"
|
2023-12-19 22:03:09 -08:00
|
|
|
"time"
|
2023-12-19 20:51:52 -08:00
|
|
|
"net/http"
|
|
|
|
|
2023-12-19 22:03:09 -08:00
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
_ "github.com/lib/pq"
|
|
|
|
"github.com/jmoiron/sqlx"
|
2023-12-19 20:13:32 -08:00
|
|
|
)
|
2023-12-17 21:21:29 -08:00
|
|
|
|
2023-12-19 22:03:09 -08:00
|
|
|
type Transaction struct {
|
|
|
|
id int
|
|
|
|
amount decimal.Decimal
|
|
|
|
description string
|
|
|
|
account int
|
|
|
|
bucket int
|
|
|
|
date time.Time
|
|
|
|
}
|
|
|
|
|
2023-12-19 20:51:52 -08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-17 21:21:29 -08:00
|
|
|
func main() {
|
2023-12-19 20:13:32 -08:00
|
|
|
log.SetPrefix("RecountServer: ")
|
|
|
|
log.SetFlags(0)
|
|
|
|
|
2023-12-19 22:03:09 -08:00
|
|
|
//
|
|
|
|
db, err := sqlx.Connect("postgres", "user=rcntuser password=Devel@pmentPa$$w0rd host=10.0.0.183 dbname=Borealis sslmode=disable")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
log.Print("Database connected")
|
|
|
|
|
|
|
|
// Confirm a successful connection.
|
|
|
|
if err := db.Ping(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
log.Print("Database successfully pinged")
|
|
|
|
|
|
|
|
transactions := []Transaction{}
|
|
|
|
err = db.Select(&transactions, "SELECT * FROM rcnt.transactions ORDER BY trns_id DESC")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
fmt.Print(fmt.Sprintf("%+v\n", transactions))
|
|
|
|
log.Print("Select has been run")
|
|
|
|
|
|
|
|
for _, trns := range transactions {
|
|
|
|
log.Print(fmt.Sprintf("%#v : %#v", trns.amount, trns.id))
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("select all run is done")
|
|
|
|
|
2023-12-19 20:51:52 -08:00
|
|
|
http.HandleFunc("/hello", hello)
|
|
|
|
http.HandleFunc("/headers", headers)
|
|
|
|
|
|
|
|
http.ListenAndServe(":8090", nil)
|
|
|
|
|
|
|
|
//fmt.Println("Hello World")
|
2023-12-17 21:21:29 -08:00
|
|
|
}
|