diff --git a/internal/config/types.go b/internal/config/config.go similarity index 100% rename from internal/config/types.go rename to internal/config/config.go diff --git a/internal/multipart/reader.go b/internal/multipart/reader.go index f62bc59..dda82e4 100644 --- a/internal/multipart/reader.go +++ b/internal/multipart/reader.go @@ -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{ diff --git a/internal/multipart/types.go b/internal/multipart/types.go index 2419a28..01ed8c4 100644 --- a/internal/multipart/types.go +++ b/internal/multipart/types.go @@ -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 -} diff --git a/server.go b/server.go index a737a98..18175bf 100644 --- a/server.go +++ b/server.go @@ -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 }