-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsuperfile.go
52 lines (41 loc) · 1.04 KB
/
superfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package superfile
import (
"errors"
"io"
"io/ioutil"
"strings"
"github.com/helloticket/superfile/file"
"github.com/helloticket/superfile/model"
"github.com/helloticket/superfile/parser"
"gopkg.in/yaml.v2"
)
func NewLayout(modelo *strings.Reader) (model.Layout, error) {
data, err := ioutil.ReadAll(modelo)
if err != nil {
return nil, err
}
config := map[interface{}]interface{}{}
if err := yaml.Unmarshal(data, config); err != nil {
return nil, err
}
if len(config) == 0 {
return nil, errors.New("Arquivo de definição de layout vazio")
}
layout, err := parser.NewModeloLayout(config)
if err != nil {
return nil, err
}
if err := layout.Validate(); err != nil {
return nil, err
}
return layout, err
}
func NewRemessa(data model.Layout) *model.Remessa {
return model.NewRemessa(data)
}
func NewRetornoFile(layout model.Layout, content io.Reader) (file.RetornoFile, error) {
return file.NewRetornoFile(layout, content)
}
func NewRemessaDebug(remessa *model.Remessa) *file.RemessaDebug {
return file.NewRemessaDebug(remessa)
}