use json marshalling

use-redis
Chakib Benziane 5 years ago
parent aa892eca4c
commit 8808bc69f3

@ -3,7 +3,7 @@ version: "3.4"
volumes:
redis:
file-storage:
sqlite:
#sqlite:
gocache:
services:
@ -12,7 +12,7 @@ services:
build: ./docker
environment:
- GO111MODULE=on
- BIT4SAT_DB_PATH=/sqlite
#- BIT4SAT_DB_PATH=/sqlite
- BIT4SAT_STORAGE_PATH=/storage
- GOPATH=/go

@ -0,0 +1,5 @@
package encoding
func ToJson(v interface) ([]byte, error) {
enc := json.NewEncoder()
}

@ -1,10 +1,10 @@
package storage
import (
"encoding/json"
"fmt"
"git.sp4ke.com/sp4ke/bit4sat/db"
"git.sp4ke.com/sp4ke/bit4sat/encoding"
"github.com/mediocregopher/radix/v3"
)
@ -70,7 +70,7 @@ func GetByID(id string) (*Upload, error) {
}
var up Upload
err = encoding.FromBytes(buf, &up)
err = json.Unmarshal(buf, &up)
return &up, err
}
@ -79,10 +79,10 @@ func (u *Upload) Write() error {
// Create a new upload hash upload:id --> [Files]
key := fmt.Sprintf("upload:%s", u.ID)
raw, err := encoding.ToBytes(u)
enc, err := json.Marshal(u)
if err != nil {
return err
}
return DB.Do(radix.FlatCmd(nil, "SET", key, raw))
return DB.Do(radix.FlatCmd(nil, "SET", key, enc))
}

Loading…
Cancel
Save