mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-12-02 01:46:02 +03:00
34 lines
560 B
Go
34 lines
560 B
Go
|
package data
|
||
|
|
||
|
import "io"
|
||
|
|
||
|
type Store interface {
|
||
|
Open(string) (io.ReadWriteCloser, error)
|
||
|
}
|
||
|
|
||
|
|
||
|
type StorageType int
|
||
|
|
||
|
const (
|
||
|
DiskStorage StorageType = 1 << iota
|
||
|
TempStorage
|
||
|
MemoryStorage
|
||
|
)
|
||
|
|
||
|
func NewStore(t StorageType) Store {
|
||
|
switch t {
|
||
|
case MemoryStorage:
|
||
|
return newMemoryStorage( /*...*/ )
|
||
|
case DiskStorage:
|
||
|
return newDiskStorage( /*...*/ )
|
||
|
default:
|
||
|
return newTempStorage( /*...*/ )
|
||
|
}
|
||
|
}
|
||
|
|
||
|
s, _ := NewStore(data.MemoryStorage)
|
||
|
f, _ := s.Open("file")
|
||
|
|
||
|
n, _ := f.Write([]byte("data"))
|
||
|
defer f.Close()
|