-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Research] File Manager #12
Comments
PlanThis document aims to define the technical research in order to have an overview of the different process implemented by our competitors (Gin, Echo). GoalAs we are creating a framework, the ability of uploading or downloading files is necessary. This task is dedicated on analizing the technical implementations in the different http frameworks written in Concerned ressource
Workflow
OverviewUploadGin
This method is taking as parameter the pointer Echo
Here the process is different, the file is given by the http request itself it uses the DownloadGinGin does not even implement this method. Echo
It only opens the file, proceed to basic checks, and uses Recomendations
Sources
|
package main
import (
"io"
"mime/multipart"
"net/http"
"os"
)
var MaxMemory int64 = 32 << 20 // 32MB
type SomeBaseStruct struct {
Request http.Request
}
// HandleFile allow you to parse the request's multipart form by the file key and return the file.
func (sbs *SomeBaseStruct) HandleFile(formKey string) (*multipart.FileHeader, error) {
if sbs.Request.MultipartForm == nil {
if err := sbs.Request.ParseMultipartForm(MaxMemory); err != nil {
return nil, err
}
}
f, fh, err := sbs.Request.FormFile(formKey)
if err != nil {
return nil, err
}
f.Close()
return fh, nil
}
// Upload allow you to gather the file from the submitted form and copy the passed file to the system directory.
func (sbs *SomeBaseStruct) Upload(formKey string, dst string) error {
fh, err := sbs.HandleFile(formKey)
if err != nil {
return err
}
src, err := fh.Open()
if err != nil {
return err
}
defer src.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, src)
return err
}
// Download allow you to fetch a file from a designated path.
func (sbs SomeBaseStruct) Download(filePath string) (*os.File, error) {
f, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer f.Close()
fi, _ := f.Stat()
if fi.IsDir() {
f, err = os.Open(filePath)
if err != nil {
return nil, err
}
defer f.Close()
if fi, err = f.Stat(); err != nil {
return nil, err
}
}
return f, nil
} |
Faire des recherche sur les files manager des framework GO existant :
Echo :
Gin :
L'idée est de voir comment ses framework mette cela en place, es-ce qu'ils utilisent juste le module HTTP Go et le surcharge avec des helper plus lisible ou font il des choses un peu plus poussé
Es-ce que c'est nécessaire de développer ce genre de module au sein de notre framework ou peut ont se contenter de ce qui est dispo nativement ?
Drop des docs, des liens en commentaire et un petit texte sur ce que tu en pense et on verra ça tous ensemble avec tes conclusion pour décider ce qu'on fait (abandon, developpement, ou mise en pause selon le temps)
👋
The text was updated successfully, but these errors were encountered: