diff --git a/cmd/app/app.go b/cmd/app/app.go deleted file mode 100644 index a11a549..0000000 --- a/cmd/app/app.go +++ /dev/null @@ -1,49 +0,0 @@ -package app - -import ( - "flag" - "log" - "net/http" - "os" - "time" -) - -var ( - APP_PORT = os.Getenv("APP_PORT") -) - -func App() { - // parse addr flag to dynamicaly change address value - addr := flag.String("addr", APP_PORT, "HTTP network address") - - // parse debug mode to enable debug mode in application - debug := flag.Bool("debug", false, "Enable debug mode") - // define logs - infoLog := log.New(os.Stderr, "INFO:\t", log.Ldate|log.Ltime) - errorLog := log.New(os.Stderr, "ERROR:\t", log.Ldate|log.Ltime|log.Llongfile) - - flag.Parse() - - if *debug { - infoLog.Println("Enabled debug mode...") - } - - _ = &Application{ - Debug: debug, - InfoLog: infoLog, - ErrorLog: errorLog, - } - - srv := http.Server{ - Addr: *addr, - ErrorLog: errorLog, - IdleTimeout: time.Minute, - ReadTimeout: 5 * time.Second, - WriteTimeout: 10 * time.Second, - } - - err := srv.ListenAndServe() - if err != nil { - errorLog.Fatalln(err) - } -} diff --git a/cmd/app/config.go b/cmd/app/config.go deleted file mode 100644 index 2df5b8f..0000000 --- a/cmd/app/config.go +++ /dev/null @@ -1,15 +0,0 @@ -package app - -import ( - "github.com/Nicolas-ggd/filestream" - "log" -) - -// Application struct is a wrap of application, which controls everything and have top management role, everything is united around this struct. -type Application struct { - Debug *bool - ErrorLog *log.Logger - InfoLog *log.Logger - RFileRequest *fstream.RFileRequest - File *fstream.File -} diff --git a/cmd/filestream/main.go b/cmd/filestream/main.go deleted file mode 100644 index 418ce79..0000000 --- a/cmd/filestream/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/Nicolas-ggd/filestream/cmd/app" - -func main() { - app.App() -} diff --git a/file.go b/file.go index 2957efb..3ef1487 100644 --- a/file.go +++ b/file.go @@ -57,7 +57,11 @@ func (r *File) generateUuidUniqueName(request *RFileRequest) { // RemoveUploadedFile function removes uploaded file from uploaded directory, it takes param and returns nothing: // -// RFileRequest struct +// Takes: +// +// - RFileRequest struct +// +// Use this function in your handler after file is uploaded func RemoveUploadedFile(r *RFileRequest) { filePath := filepath.Join(r.UploadDirectory, r.UploadFile.Filename) @@ -83,11 +87,11 @@ func prettyByteSize(b int) string { // StoreChunk cares slice of chunks and returns final results and error // -// File - struct is final version about file information +// - File - struct is final version about file information // -// error - functions cares about errors and returns error +// - error - functions cares about occurred errors and returns it. // -// function creates new directory for chunks if it doesn't exist, if directory already exists it appends received chunks in current chunks and if entire file is uploaded then File struct is returned +// Function creates new directory for chunks if it doesn't exist, if directory already exists it appends received chunks in current chunks and if entire file is uploaded then File struct is returned func StoreChunk(r *RFileRequest) (*File, error) { var rFile *File @@ -143,13 +147,13 @@ func StoreChunk(r *RFileRequest) (*File, error) { // IsAllowExtension function checks if file extension is allowed to upload, it takes following params // -// fileExtensions - array of strings, which is looks like: []string{".jpg", ".jpeg"}, note that this is fileExtensions which is allowed to receive +// - fileExtensions - array of strings, which is looks like: []string{".jpg", ".jpeg"}, note that this is fileExtensions which is allowed to receive // -// fileName - string, this parameter is file name which is like ".jpeg", ".jpg" +// - fileName - string, this parameter is file name which is like ".jpeg", ".jpg" // // Returns: // -// bool - function returns false if extension isn't allowed to receive, it returns true if extension is allowed to receive +// - bool - function returns false if extension isn't allowed to receive, it returns true if extension is allowed to receive func IsAllowExtension(fileExtensions []string, fileName string) bool { ext := strings.ToLower(filepath.Ext(fileName))