diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-11-09 19:13:25 -0500 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-11-09 19:13:25 -0500 |
commit | 8e1eb58d54e89b39828f973ece36a05dc39c10b3 (patch) | |
tree | 06a1e516cac5dab0f50dcc97fed3a60f70e67661 | |
parent | 287fb1555d504c79aa9685aa4e701321ddad9f14 (diff) |
Fix database name
-rw-r--r-- | backend/main.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/backend/main.go b/backend/main.go index 0ba59a8..f5a6e52 100644 --- a/backend/main.go +++ b/backend/main.go @@ -3,25 +3,31 @@ package main import "fmt" import "net/http" import "os" +import "strconv" import _ "github.com/lib/pq" import "database/sql" +import "encoding/json" func RecipeList(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { fmt.Printf("Return all recipe names...\n") - } else if r.Method == "POST" { - } else if r.Method == "DELETE" { } } func SingleRecipe(w http.ResponseWriter, r *http.Request) { - name := r.URL.Path[len("/recipes/"):] + recipe_id, err := strconv.Atoi(r.URL.Path[len("/recipes/"):]) + if err != nil { + fmt.Println("Not a valid ID") + return + } if r.Method == "GET" { - fmt.Printf("Return recipe \"%s\"...\n", name) + fmt.Printf("Return recipe \"%d\"...\n", recipe_id) } else if r.Method == "POST" { - fmt.Printf("Create recipe \"%s\"...\n", name) + fmt.Printf("Create recipe \"%d\"...\n", recipe_id) + } else if r.Method == "PUT" { + fmt.Printf("Update recipe \"%d\"...\n", recipe_id) } else if r.Method == "DELETE" { - fmt.Printf("Delete recipe \"%s\"...\n", name) + fmt.Printf("Delete recipe \"%d\"...\n", recipe_id) } } @@ -29,7 +35,7 @@ var DB_PASSWORD string var DB_USER string var db *sql.DB -const DB_NAME = "Recipes" +const DB_NAME = "recipe_buddy" func init() { DB_PASSWORD = os.Getenv("DATABASE_PASSWORD") @@ -37,10 +43,12 @@ func init() { } func main() { + var err error + dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", DB_USER, DB_PASSWORD, DB_NAME) fmt.Println(dbinfo) - db, err := sql.Open("postgres", dbinfo) + db, err = sql.Open("postgres", dbinfo) if err != nil || db.Ping() != nil { fmt.Println("Error connecting to database") } |