This commit is contained in:
Adrien Marquès 2019-05-01 21:30:16 +02:00
parent 0912e07f4f
commit 0e498607ba
4 changed files with 20 additions and 21 deletions

View File

@ -6,6 +6,18 @@ import (
"io"
)
// Reader is a multipart reader.
type Reader struct {
// io.Reader used for http.Request.Body reading
reader *bufio.Reader
// boundary used to separate multipart MultipartDatas
boundary string
// result will be inside this field
Data map[string]*Component
}
// NewReader creates a new reader from a reader and a boundary.
func NewReader(r io.Reader, boundary string) (*Reader, error) {
reader := &Reader{
@ -21,7 +33,7 @@ func NewReader(r io.Reader, boundary string) (*Reader, error) {
}
reader.reader = dst
// 2. Place reader after the first boundary
// 2. "move" reader right after the first boundary
var err error
line := make([]byte, 0)
@ -40,7 +52,7 @@ func NewReader(r io.Reader, boundary string) (*Reader, error) {
// Parse parses the multipart components from the request
func (reader *Reader) Parse() error {
/* (1) For each component (until boundary) */
// for each component (until boundary)
for {
comp := &Component{

View File

@ -1,9 +1,5 @@
package multipart
import (
"bufio"
)
// ConstError is a wrapper to set constant errors
type ConstError string
@ -32,15 +28,3 @@ type Component struct {
// actual data
Data []byte
}
// Reader represents a multipart reader
type Reader struct {
// reader used for http.Request.Body reading
reader *bufio.Reader
// boundary used to separate multipart MultipartDatas
boundary string
// result will be inside this field
Data map[string]*Component
}

View File

@ -1,6 +1,7 @@
package aicra
import (
"io"
"log"
"net/http"
"os"
@ -22,8 +23,10 @@ type Server struct {
// New creates a framework instance from a configuration file
func New(configPath string) (*Server, error) {
var err error
var (
err error
configFile io.ReadCloser
)
// 1. init instance
var i = &Server{
@ -33,7 +36,7 @@ func New(configPath string) (*Server, error) {
}
// 2. open config file
configFile, err := os.Open(configPath)
configFile, err = os.Open(configPath)
if err != nil {
return nil, err
}