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