github.com/viant/toolbox@v0.34.5/storage/object.go (about) 1 package storage 2 3 import ( 4 "os" 5 ) 6 7 const ( 8 undefined int = iota 9 StorageObjectFolderType //folder type 10 StorageObjectContentType //file type 11 ) 12 13 //Object represents a storage object 14 type Object interface { 15 //URL return storage url 16 URL() string 17 //Type returns storage type either folder or file 18 Type() int 19 //IsFolder returns true if object is a folder 20 IsFolder() bool 21 //IsContent returns true if object is a file 22 IsContent() bool 23 //Wrap wraps source storage object 24 Wrap(source interface{}) 25 //Unwrap unwraps source storage object into provided target. 26 Unwrap(target interface{}) error 27 FileInfo() os.FileInfo 28 } 29 30 //AbstractObject represents abstract storage object 31 type AbstractObject struct { 32 Object 33 url string 34 objectType int 35 Source interface{} 36 fileInfo os.FileInfo 37 } 38 39 //URL return storage url 40 func (o *AbstractObject) URL() string { 41 return o.url 42 } 43 44 //Type returns storage type StorageObjectFolderType or StorageObjectContentType 45 func (o *AbstractObject) Type() int { 46 return o.objectType 47 } 48 49 //IsFolder returns true if object is a folder 50 func (o *AbstractObject) IsFolder() bool { 51 return o.objectType == StorageObjectFolderType 52 } 53 54 //IsContent returns true if object is a file 55 func (o *AbstractObject) IsContent() bool { 56 return o.objectType == StorageObjectContentType 57 } 58 59 //Wrap wraps source storage object 60 func (o *AbstractObject) Wrap(source interface{}) { 61 o.Source = source 62 } 63 64 func (o *AbstractObject) FileInfo() os.FileInfo { 65 return o.fileInfo 66 } 67 68 //NewAbstractStorageObject creates a new abstract storage object 69 func NewAbstractStorageObject(url string, source interface{}, fileInfo os.FileInfo) *AbstractObject { 70 var result = &AbstractObject{ 71 url: url, 72 Source: source, 73 fileInfo: fileInfo, 74 objectType: StorageObjectContentType, 75 } 76 if fileInfo.IsDir() { 77 result.objectType = StorageObjectFolderType 78 } 79 return result 80 }