🏷️ Created File domain
This commit is contained in:
parent
e74c0a0b66
commit
2cf99dcba1
|
@ -0,0 +1,44 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
Path string
|
||||
Updated time.Time
|
||||
Content []byte
|
||||
}
|
||||
|
||||
// LogicalName returns full file name without directory path.
|
||||
func (f File) LogicalName() string {
|
||||
return filepath.Base(f.Path)
|
||||
}
|
||||
|
||||
// BaseFileName returns file name without extention and directory path.
|
||||
func (f File) BaseFileName() string {
|
||||
base := filepath.Base(f.Path)
|
||||
|
||||
return strings.TrimSuffix(base, filepath.Ext(base))
|
||||
}
|
||||
|
||||
// Ext returns file extention.
|
||||
func (f File) Ext() string {
|
||||
if ext := filepath.Ext(f.Path); len(ext) > 1 {
|
||||
return ext[1:]
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// Dir returns file directory.
|
||||
func (f File) Dir() string {
|
||||
return filepath.Dir(f.Path)
|
||||
}
|
||||
|
||||
func (f File) MediaType() string {
|
||||
return mime.TypeByExtension(f.Ext())
|
||||
}
|
Loading…
Reference in New Issue