diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2024-05-27 21:30:54 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2024-05-27 23:52:44 +0200 |
commit | 81621c4f64f4a1c29906643f53314e2f71a014ae (patch) | |
tree | 503cc56b609dcad8f8eca6e64b6b9b15b02fd4fd /src/rest-api/cmd/main.go | |
parent | payload-processor: fmt (diff) | |
download | fs-tracer-backend-81621c4f64f4a1c29906643f53314e2f71a014ae.tar.gz fs-tracer-backend-81621c4f64f4a1c29906643f53314e2f71a014ae.tar.bz2 fs-tracer-backend-81621c4f64f4a1c29906643f53314e2f71a014ae.zip |
rest-api: connect to db and add /file/ GET endpoint
TODO: Only get files for your specific user
Diffstat (limited to 'src/rest-api/cmd/main.go')
-rw-r--r-- | src/rest-api/cmd/main.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/rest-api/cmd/main.go b/src/rest-api/cmd/main.go index d1e44b3..98f3722 100644 --- a/src/rest-api/cmd/main.go +++ b/src/rest-api/cmd/main.go @@ -9,6 +9,7 @@ import ( "time" "github.com/Baitinq/fs-tracer-backend/src/rest-api/handler" + "github.com/jmoiron/sqlx" "github.com/segmentio/kafka-go" "github.com/segmentio/kafka-go/sasl/plain" ) @@ -47,13 +48,22 @@ func main() { AllowAutoTopicCreation: true, } - handler := handler.NewHandler(kafka_writer) + db_password, ok := os.LookupEnv("DB_PASSWORD") + if !ok { + log.Fatal("DB_PASSWORD not set") + } + db, err := sqlx.Connect("postgres", fmt.Sprintf("postgres://postgres.slpoocycjgqsuoedhkbn:%s@aws-0-eu-central-1.pooler.supabase.com:5432/postgres", db_password)) + if err != nil { + log.Fatal("cannot initalize db client", err) + } + + handler := handler.NewHandler(db, kafka_writer) mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello folks!") }) - mux.Handle("/payload", handler) + mux.Handle("/file/", handler) http.ListenAndServe(":8080", mux) } |