This commit is contained in:
2025-05-01 14:42:12 -06:00
parent 693d11c506
commit bd59f428ba
13 changed files with 288 additions and 124 deletions
+13 -5
View File
@@ -14,6 +14,7 @@ import (
"time"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
)
@@ -34,7 +35,7 @@ func serve() {
var wg sync.WaitGroup
driver_ctx := context.Background()
driver, err := neo4j.NewDriverWithContext("bolt://localhost:7687", neo4j.BasicAuth("neo4j", "jzLbsy2C23WHzQ-", ""))
driver, err := neo4j.NewDriverWithContext(os.Getenv("NEO4J_BOLT"), neo4j.BasicAuth("neo4j", os.Getenv("NEO4J_PASSWORD"), ""))
if err != nil {
panic(err)
}
@@ -43,18 +44,19 @@ func serve() {
err = driver.VerifyConnectivity(driver_ctx)
if err != nil {
log.Println("Error connecting to neo4j.")
panic(err)
}
fmt.Println("neo4j connection established.")
rsrc_endpoints := []string{
"/auth",
"/users",
"/users",
"/users/{user_id}",
"/users/{user_id}",
"/users/{user_id}",
"/users/{user_id}",
"/users/{user_id}/posts",
"/users/{user_id}/spaces",
"/spaces",
@@ -74,9 +76,9 @@ func serve() {
methods := []string{
http.MethodPost,
http.MethodGet,
http.MethodGet,
http.MethodPost,
http.MethodGet,
http.MethodGet,
http.MethodPatch,
http.MethodDelete,
http.MethodGet,
@@ -97,10 +99,10 @@ func serve() {
}
functions := []func(http.ResponseWriter, *http.Request){
auth_user(driver, driver_ctx),
create_new_user(driver, driver_ctx),
retrieve_all_users(driver, driver_ctx),
retrieve_user(driver, driver_ctx),
auth_user(driver, driver_ctx),
update_user(driver, driver_ctx),
delete_user(driver, driver_ctx),
retrieve_users_posts(driver, driver_ctx),
@@ -168,5 +170,11 @@ func serve() {
}
func main() {
err := godotenv.Load("../.env")
if err != nil {
log.Println("Error loading .env.")
return
}
serve()
}