use gob instead of JSON

This commit is contained in:
1e99 2024-10-30 12:18:27 +01:00
parent 7536e5d9af
commit 5b29bb7285

View file

@ -1,7 +1,7 @@
package storage
import (
"encoding/json"
"encoding/gob"
"log"
"os"
"path"
@ -21,8 +21,8 @@ type dir struct {
}
type dirEntry struct {
Password []byte `json:"password"`
ExpiresAt time.Time `json:"expires-at"`
Password []byte
ExpiresAt time.Time
}
func (store *dir) Create(password []byte, expiresAt time.Time) (string, error) {
@ -49,7 +49,7 @@ func (store *dir) Create(password []byte, expiresAt time.Time) (string, error) {
ExpiresAt: expiresAt,
}
err = json.NewEncoder(file).Encode(&entry)
err = gob.NewEncoder(file).Encode(&entry)
if err != nil {
log.Printf("%s", err)
return "", err
@ -78,7 +78,7 @@ func (store *dir) Get(id string) ([]byte, error) {
defer file.Close()
var entry dirEntry
err = json.NewDecoder(file).Decode(&entry)
err = gob.NewDecoder(file).Decode(&entry)
if err != nil {
return nil, err
}
@ -119,7 +119,7 @@ func (store *dir) ClearExpired() error {
defer file.Close()
var entry dirEntry
err = json.NewDecoder(file).Decode(&entry)
err = gob.NewDecoder(file).Decode(&entry)
if err != nil {
return err
}