mainLogger.Println("Given container_name:", *paramContainerName) // eg: binbsis50
- DBwrapper := dbhandling.NewDbWrapper(*paramRedisLocation, *paramSongsLocation, *paramContainerName, *paramBinbLocation)
+ DBwrapper := dbhandling.NewDbWrapperWithLogging(*paramRedisLocation, *paramSongsLocation, *paramContainerName, *paramBinbLocation, mainLogger)
// Setting up the routing
import (
"context"
"encoding/json"
+ "log"
"net/http"
"os"
"path/filepath"
PathToSongs string
ImageName string
BinbLocation string
+
+ log *log.Logger
}
func NewDbWrapper(redisLocation string, songsLocation string, imageName string, binbLocation string) DBWrapper {
songsLocation,
imageName,
binbLocation,
+ log.Default(),
+ }
+}
+
+func NewDbWrapperWithLogging(
+ redisLocation string, songsLocation string, imageName string,
+ binbLocation string, logger *log.Logger,
+) DBWrapper {
+ return DBWrapper {
+ redis.NewClient(&redis.Options{
+ Addr: redisLocation,
+ Password: "",
+ DB: 0,
+ Protocol: 2,
+ }),
+ context.Background(),
+ songsLocation,
+ imageName,
+ binbLocation,
+ logger,
}
}
* Create a new song in the database (only in the main list don't add to anything)
**/
func (dbw *DBWrapper) SongsCreate(w http.ResponseWriter, r *http.Request) {
- count := START_COUNT // safe high count to create new songs WARNING:, this should only be used once ideally
- START_COUNT += 1
-
+ count, err := dbw.getSongCount()
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
newSong := DBSong{}
- err := json.NewDecoder(r.Body).Decode(&newSong)
+ err = json.NewDecoder(r.Body).Decode(&newSong)
cmd := dbw.RedisDb.HSet(dbw.Ctx, "song:" + strconv.Itoa(count + 1),
"artistName", newSong.ArtistName,