diff options
Diffstat (limited to 'http/files.go')
-rw-r--r-- | http/files.go | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/http/files.go b/http/files.go deleted file mode 100644 index 06e5fd24..00000000 --- a/http/files.go +++ /dev/null @@ -1,58 +0,0 @@ -package http - -import ( - "mime/multipart" - "strings" - "github.com/sirupsen/logrus" -) - -type fileData map[string]interface{} - -type FileUpload struct { - Name string `json:"name"` - MimeType string `json:"mimetype"` -} - -func (d fileData) push(k string, v []*multipart.FileHeader) { - if len(v) == 0 { - // doing nothing - return - } - - chunks := make([]string, 0) - for _, chunk := range strings.Split(k, "[") { - chunks = append(chunks, strings.Trim(chunk, "]")) - } - - d.pushChunk(chunks, v) -} - -func (d fileData) pushChunk(k []string, v []*multipart.FileHeader) { - logrus.Print(v) - if len(v) == 0 || v[0] == nil { - return - } - - head := k[0] - tail := k[1:] - if len(k) == 1 { - d[head] = FileUpload{ - Name: v[0].Filename, - MimeType: v[0].Header.Get("Content-Type"), - } - return - } - - // unnamed array - if len(tail) == 1 && tail[0] == "" { - d[head] = v - return - } - - if p, ok := d[head]; !ok { - d[head] = make(fileData) - d[head].(fileData).pushChunk(tail, v) - } else { - p.(fileData).pushChunk(tail, v) - } -} |