go-aptproxy/entry.go

32 lines
611 B
Go
Raw Normal View History

2016-04-24 09:32:32 +02:00
package main
import (
"encoding/json"
"os"
)
// Entry represents a file in storage.
type Entry struct {
URL string `json:"url"`
ContentLength int64 `json:"content_length"`
ContentType string `json:"content_type"`
}
// LoadEntry loads an entry from disk.
2016-04-25 10:01:01 +02:00
func (e *Entry) LoadEntry(filename string) error {
2016-04-24 09:32:32 +02:00
f, err := os.Open(filename)
if err != nil {
2016-04-25 10:01:01 +02:00
return err
2016-04-24 09:32:32 +02:00
}
2016-04-25 10:01:01 +02:00
return json.NewDecoder(f).Decode(e)
2016-04-24 09:32:32 +02:00
}
// Save writes the entry to disk.
func (e *Entry) Save(filename string) error {
f, err := os.Create(filename)
if err != nil {
return err
}
return json.NewEncoder(f).Encode(e)
}