diff --git a/main.go b/main.go index 3052f48..2fe378d 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "log" "net/http" "os" - "strconv" "github.com/gin-gonic/gin" "github.com/jackc/pgx/v5/pgxpool" @@ -165,12 +164,7 @@ func listVideos(c *gin.Context) { func getVideo(c *gin.Context) { var err error - inputId, err := strconv.Atoi(c.Param("id")) - if err != nil { - log.Panicf("getVideo: %v\n", err) - } - - rows, _ := dbpool.Query(context.Background(), "select filepath from videos where id = $1", inputId) + rows, _ := dbpool.Query(context.Background(), "select filepath from videos where id = $1", c.Param("id")) rows.Next() err = rows.Err() if err != nil { @@ -189,12 +183,8 @@ func getVideo(c *gin.Context) { } func deleteVideo(c *gin.Context) { - inputId, err := strconv.Atoi(c.Param("id")) - if err != nil { - log.Panicf("deleteVideo: %v\n", err) - } - - rows, _ := dbpool.Query(context.Background(), "select filepath from videos where id = $1", inputId) + var err error + rows, _ := dbpool.Query(context.Background(), "select filepath from videos where id = $1", c.Param("id")) rows.Next() err = rows.Err() if err != nil { @@ -209,7 +199,7 @@ func deleteVideo(c *gin.Context) { log.Panicf("deleteVideo: %v\n", err) } - _, err = dbpool.Exec(context.Background(), "delete from videos where id = $1", inputId) + _, err = dbpool.Exec(context.Background(), "delete from videos where id = $1", c.Param("id")) if err != nil { c.JSON(http.StatusInternalServerError, "Id was likely invalid") log.Panicf("deleteVideo: %v\n", err)