71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
_ "encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
_ "github.com/lib/pq"
|
|
)
|
|
|
|
type Item struct {
|
|
Id int32 `json:"id"`
|
|
Name int32 `json:"name"`
|
|
ValueCents int32 `json:"valueCents"`
|
|
PurchaseCostCents int32 `json:"purchasedCostCents"`
|
|
Aquired time.Time `json:"aquired"`
|
|
Description string `json:"description"`
|
|
Notes string `json:"notes"`
|
|
SoldForCents int32 `json:"soldForCents"`
|
|
SoldTo string `json:"soldTo"`
|
|
Category Category `json:"category"`
|
|
Subcategory Subcategory `json:"subcategory"`
|
|
}
|
|
|
|
type Category struct {
|
|
Id int32 `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type Subcategory struct {
|
|
Id int32 `json:"id"`
|
|
Name string `json:"name"`
|
|
CategoryId int32 `json:"categoryId"`
|
|
}
|
|
|
|
func main() {
|
|
http.HandleFunc("/data", get)
|
|
err := http.ListenAndServe(":8080", nil)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
}
|
|
|
|
func get(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusBadGateway)
|
|
w.Write([]byte("Hell world!"))
|
|
}
|
|
|
|
func sql_test() {
|
|
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", "localhost", 5432, "postgres", "", "inventory")
|
|
db, err := sql.Open("postgres", psqlInfo)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
rows, err := db.Query("")
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
defer rows.Close()
|
|
}
|