Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericbeaumet committed Jul 10, 2024
1 parent f186ea8 commit 7c2a634
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
9 changes: 5 additions & 4 deletions ai/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=youruser
POSTGRES_PASSWORD=yourpassword
POSTGRES_DB=yourdbname
POSTGRES_USER=hearthands
POSTGRES_PASSWORD=hearthands
POSTGRES_DB=hearthands

QDRANT_HOST=localhost
QDRANT_PORT=6333
QDRANT_PORT=6333
36 changes: 27 additions & 9 deletions ai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package main
import (
"database/sql"
"fmt"
"io"
"log"
"net"
"net/http"
"net/url"
"os"

"github.com/joho/godotenv"
Expand All @@ -18,26 +21,41 @@ func main() {
log.Fatalf("Error loading .env file: %v", err)
}

// Connect to PostgreSQL
pgConnStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
os.Getenv("POSTGRES_HOST"), os.Getenv("POSTGRES_PORT"), os.Getenv("POSTGRES_USER"), os.Getenv("POSTGRES_PASSWORD"), os.Getenv("POSTGRES_DB"))
db, err := sql.Open("postgres", pgConnStr)
// Connect to the PostgreSQL instance
db, err := sql.Open("postgres", (&url.URL{
Scheme: "postgres",
User: url.UserPassword(os.Getenv("POSTGRES_USER"), os.Getenv("POSTGRES_PASSWORD")),
Host: net.JoinHostPort(os.Getenv("POSTGRES_HOST"), os.Getenv("POSTGRES_PORT")),
Path: os.Getenv("POSTGRES_DB"),
}).String())
if err != nil {
log.Fatalf("Error connecting to PostgreSQL: %v", err)
}
defer db.Close()

// Connect to Qdrant
qdrantURL := fmt.Sprintf("http://%s:%s", os.Getenv("QDRANT_HOST"), os.Getenv("QDRANT_PORT"))
resp, err := http.Get(qdrantURL + "/v1/collections")
// Query the Qdrant instance
qdrantBaseURL := (&url.URL{
Scheme: "http",
Host: net.JoinHostPort(os.Getenv("QDRANT_HOST"), os.Getenv("QDRANT_PORT")),
}).String()
resp, err := http.Get(qdrantBaseURL + "/v1/collections")
if err != nil {
log.Fatalf("Error connecting to Qdrant: %v", err)
}
defer resp.Body.Close()

// Simple HTTP server
// Declare your http routes

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Connected to PostgreSQL and Qdrant successfully!")
w.WriteHeader(http.StatusOK)
io.WriteString(w, "Hello, World!")

Check failure on line 51 in ai/main.go

View workflow job for this annotation

GitHub Actions / lint (./ai)

Error return value of `io.WriteString` is not checked (errcheck)
})

http.HandleFunc("/livez", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})

// Start the server, which will listen on http://localhost:8080
fmt.Println("Starting server on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}

0 comments on commit 7c2a634

Please sign in to comment.