Storable -> Object
This commit is contained in:
18
object.go
Normal file
18
object.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Object interface {
|
||||||
|
GetType() string
|
||||||
|
GetId() string
|
||||||
|
}
|
||||||
|
|
||||||
|
func ObjectKey(obj Object) string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"%d:%s:%d:%s",
|
||||||
|
len(obj.GetType()),
|
||||||
|
obj.GetType(),
|
||||||
|
len(obj.GetId()),
|
||||||
|
obj.GetId(),
|
||||||
|
)
|
||||||
|
}
|
||||||
9
store.go
9
store.go
@@ -6,11 +6,6 @@ import "fmt"
|
|||||||
import "os"
|
import "os"
|
||||||
import "path/filepath"
|
import "path/filepath"
|
||||||
|
|
||||||
type Storable interface {
|
|
||||||
GetType() string
|
|
||||||
GetId() string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Store struct {
|
type Store struct {
|
||||||
root string
|
root string
|
||||||
}
|
}
|
||||||
@@ -21,7 +16,7 @@ func NewStore(root string) *Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) Write(obj Storable) error {
|
func (s *Store) Write(obj Object) error {
|
||||||
dir := filepath.Join(s.root, obj.GetType())
|
dir := filepath.Join(s.root, obj.GetType())
|
||||||
filename := hex.EncodeToString([]byte(obj.GetId()))
|
filename := hex.EncodeToString([]byte(obj.GetId()))
|
||||||
|
|
||||||
@@ -57,7 +52,7 @@ func (s *Store) Write(obj Storable) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) Read(obj Storable) error {
|
func (s *Store) Read(obj Object) error {
|
||||||
dir := filepath.Join(s.root, obj.GetType())
|
dir := filepath.Join(s.root, obj.GetType())
|
||||||
filename := hex.EncodeToString([]byte(obj.GetId()))
|
filename := hex.EncodeToString([]byte(obj.GetId()))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user