From f917b4222cf0171e84d20e894ecae4d542ee123e Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 25 Jun 2017 13:03:59 +0100 Subject: [PATCH] unexport fileInfo Former-commit-id: e6492286dba14bb758f36da9a3f14d223e5b2d32 --- editor.go | 2 +- http.go | 4 ++-- http_checksum.go | 2 +- http_download.go | 2 +- http_listing.go | 2 +- http_single.go | 2 +- info.go | 22 +++++++++++----------- listing.go | 6 +++--- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/editor.go b/editor.go index d2b591d2..cfc3eeee 100644 --- a/editor.go +++ b/editor.go @@ -24,7 +24,7 @@ type Editor struct { } // GetEditor gets the editor based on a Info struct -func GetEditor(r *http.Request, i *FileInfo) (*Editor, error) { +func GetEditor(r *http.Request, i *fileInfo) (*Editor, error) { var err error // Create a new editor variable and set the mode diff --git a/http.go b/http.go index 206e14d8..54f62645 100644 --- a/http.go +++ b/http.go @@ -18,7 +18,7 @@ func matchURL(first, second string) bool { // ServeHTTP determines if the request is for this plugin, and if all prerequisites are met. func (c *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { var ( - fi *FileInfo + fi *fileInfo code int err error user *user @@ -131,7 +131,7 @@ func (c *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er if r.Method == http.MethodGet { // Gets the information of the directory/file - fi, err = GetInfo(r.URL, c, user) + fi, err = getInfo(r.URL, c, user) if err != nil { if r.Method == http.MethodGet { return htmlError(w, code, err) diff --git a/http_checksum.go b/http_checksum.go index eeeddcbc..ee418a17 100644 --- a/http_checksum.go +++ b/http_checksum.go @@ -14,7 +14,7 @@ import ( ) // checksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512. -func checksum(w http.ResponseWriter, r *http.Request, i *FileInfo) (int, error) { +func checksum(w http.ResponseWriter, r *http.Request, i *fileInfo) (int, error) { query := r.URL.Query().Get("checksum") file, err := os.Open(i.Path) diff --git a/http_download.go b/http_download.go index dc028dc2..8f5ddaa7 100644 --- a/http_download.go +++ b/http_download.go @@ -14,7 +14,7 @@ import ( // download creates an archive in one of the supported formats (zip, tar, // tar.gz or tar.bz2) and sends it to be downloaded. -func download(w http.ResponseWriter, r *http.Request, i *FileInfo) (int, error) { +func download(w http.ResponseWriter, r *http.Request, i *fileInfo) (int, error) { query := r.URL.Query().Get("download") if !i.IsDir { diff --git a/http_listing.go b/http_listing.go index 32d881e1..9e7ec555 100644 --- a/http_listing.go +++ b/http_listing.go @@ -10,7 +10,7 @@ import ( ) // serveListing presents the user with a listage of a directory folder. -func serveListing(w http.ResponseWriter, r *http.Request, c *FileManager, u *user, i *FileInfo) (int, error) { +func serveListing(w http.ResponseWriter, r *http.Request, c *FileManager, u *user, i *fileInfo) (int, error) { var err error // Loads the content of the directory diff --git a/http_single.go b/http_single.go index 3296b4dd..55943e28 100644 --- a/http_single.go +++ b/http_single.go @@ -7,7 +7,7 @@ import ( // serveSingle serves a single file in an editor (if it is editable), shows the // plain file, or downloads it if it can't be shown. -func serveSingle(w http.ResponseWriter, r *http.Request, c *FileManager, u *user, i *FileInfo) (int, error) { +func serveSingle(w http.ResponseWriter, r *http.Request, c *FileManager, u *user, i *fileInfo) (int, error) { var err error if err = i.RetrieveFileType(); err != nil { diff --git a/info.go b/info.go index 382b23a6..a0741a76 100644 --- a/info.go +++ b/info.go @@ -13,8 +13,8 @@ import ( humanize "github.com/dustin/go-humanize" ) -// FileInfo contains the information about a particular file or directory -type FileInfo struct { +// fileInfo contains the information about a particular file or directory. +type fileInfo struct { Name string Size int64 URL string @@ -31,12 +31,12 @@ type FileInfo struct { content []byte } -// GetInfo gets the file information and, in case of error, returns the +// getInfo gets the file information and, in case of error, returns the // respective HTTP error code -func GetInfo(url *url.URL, c *FileManager, u *user) (*FileInfo, error) { +func getInfo(url *url.URL, c *FileManager, u *user) (*fileInfo, error) { var err error - i := &FileInfo{URL: c.PrefixURL + url.Path} + i := &fileInfo{URL: c.PrefixURL + url.Path} i.VirtualPath = strings.Replace(url.Path, c.BaseURL, "", 1) i.VirtualPath = strings.TrimPrefix(i.VirtualPath, "/") i.VirtualPath = "/" + i.VirtualPath @@ -77,7 +77,7 @@ var textExtensions = [...]string{ // RetrieveFileType obtains the mimetype and a simplified internal Type // using the first 512 bytes from the file. -func (i *FileInfo) RetrieveFileType() error { +func (i *fileInfo) RetrieveFileType() error { i.Mimetype = mime.TypeByExtension(i.Extension) if i.Mimetype == "" { @@ -128,7 +128,7 @@ func (i *FileInfo) RetrieveFileType() error { } // Reads the file. -func (i *FileInfo) Read() error { +func (i *fileInfo) Read() error { if len(i.content) != 0 { return nil } @@ -142,22 +142,22 @@ func (i *FileInfo) Read() error { } // StringifyContent returns the string version of Raw -func (i FileInfo) StringifyContent() string { +func (i fileInfo) StringifyContent() string { return string(i.content) } // HumanSize returns the size of the file as a human-readable string // in IEC format (i.e. power of 2 or base 1024). -func (i FileInfo) HumanSize() string { +func (i fileInfo) HumanSize() string { return humanize.IBytes(uint64(i.Size)) } // HumanModTime returns the modified time of the file as a human-readable string. -func (i FileInfo) HumanModTime(format string) string { +func (i fileInfo) HumanModTime(format string) string { return i.ModTime.Format(format) } // CanBeEdited checks if the extension of a file is supported by the editor -func (i FileInfo) CanBeEdited() bool { +func (i fileInfo) CanBeEdited() bool { return i.Type == "text" } diff --git a/listing.go b/listing.go index 7a176d4f..15930f23 100644 --- a/listing.go +++ b/listing.go @@ -18,7 +18,7 @@ type Listing struct { // The full path of the request relatively to a File System Path string // The items (files and folders) in the path - Items []FileInfo + Items []fileInfo // The number of directories in the listing NumDirs int // The number of files (items that aren't directories) in the listing @@ -49,7 +49,7 @@ func GetListing(u *user, filePath string, baseURL string) (*Listing, error) { } var ( - fileinfos []FileInfo + fileinfos []fileInfo dirCount, fileCount int ) @@ -71,7 +71,7 @@ func GetListing(u *user, filePath string, baseURL string) (*Listing, error) { // Absolute URL url := url.URL{Path: baseURL + name} - i := FileInfo{ + i := fileInfo{ Name: f.Name(), Size: f.Size(), ModTime: f.ModTime(),