diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2017-07-03 08:10:28 +0200 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2017-07-12 08:02:14 +0200 |
commit | 78754a7b23e5fc7a40bd3c450d54a193aaf585b1 (patch) | |
tree | 5aff6436cbf93212aab6bb59a077a5718c0fbc23 /storage/storage.go | |
parent | 43d099919d1e1a8d6b38a300182d0cc075237fe6 (diff) | |
download | petrific-78754a7b23e5fc7a40bd3c450d54a193aaf585b1.tar.gz petrific-78754a7b23e5fc7a40bd3c450d54a193aaf585b1.tar.bz2 petrific-78754a7b23e5fc7a40bd3c450d54a193aaf585b1.zip |
Implementing backup methods
Diffstat (limited to 'storage/storage.go')
-rw-r--r-- | storage/storage.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/storage/storage.go b/storage/storage.go new file mode 100644 index 0000000..424661c --- /dev/null +++ b/storage/storage.go @@ -0,0 +1,37 @@ +package storage + +import ( + "bytes" + "code.laria.me/petrific/objects" + "errors" +) + +var ( + ObjectNotFound = errors.New("Object not found") +) + +type Storage interface { + Get(id objects.ObjectId) ([]byte, error) + Has(id objects.ObjectId) (bool, error) + Set(id objects.ObjectId, typ objects.ObjectType, raw []byte) error + List(typ objects.ObjectType) ([]objects.ObjectId, error) +} + +func SetObject(s Storage, o objects.RawObject) (id objects.ObjectId, err error) { + buf := new(bytes.Buffer) + + id, err = o.SerializeAndId(buf, objects.OIdAlgoDefault) + if err != nil { + return + } + + ok, err := s.Has(id) + if err != nil { + return + } + + if !ok { + err = s.Set(id, o.Type, buf.Bytes()) + } + return +} |