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()) } func (f File) GoString() string { return "domain.File(" + f.Path + ")" }