-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting.go
72 lines (54 loc) · 1.3 KB
/
setting.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package exportlistmapping
import (
"errors"
"github.com/nekonbu72/sjson/sjson"
"github.com/tealeg/xlsx"
)
type Setting struct {
Sheet string `json:"sheet"`
Start int `json:"start"`
Date struct {
Remove string `json:"remove"`
Row int `json:"row"`
Column int `json:"column"`
} `json:"date"`
Invoice struct {
Remove string `json:"remove"`
Row int `json:"row"`
Column int `json:"column"`
} `json:"invoice"`
Kata int `json:"kata"`
Lot int `json:"lot"`
Qty int `json:"qty"`
}
func NewSetting(p string) (*Setting, error) {
s := new(Setting)
if err := sjson.OpenDecode(p, s); err != nil {
return nil, err
}
return s, nil
}
func (s *Setting) isValid(sheet *xlsx.Sheet) error {
if isWithinMaxRow(s.Date.Row, sheet) == false {
return errors.New("Data.Row")
}
if isWithinMaxRow(s.Invoice.Row, sheet) == false {
return errors.New("Invoice.Row")
}
if isWithinMaxCol(s.Kata, sheet) == false {
return errors.New("Kata.Col")
}
if isWithinMaxCol(s.Lot, sheet) == false {
return errors.New("Lot.Col")
}
if isWithinMaxCol(s.Qty, sheet) == false {
return errors.New("Qty.Col")
}
return nil
}
func isWithinMaxRow(row int, sheet *xlsx.Sheet) bool {
return row <= sheet.MaxRow
}
func isWithinMaxCol(col int, sheet *xlsx.Sheet) bool {
return col <= sheet.MaxCol
}