-
Notifications
You must be signed in to change notification settings - Fork 42
/
webConfig.go
182 lines (155 loc) · 4 KB
/
webConfig.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package cmd
import (
"log"
"os"
"time"
"github.com/howeyc/ledger"
"github.com/pelletier/go-toml"
)
type accountOp struct {
Name string `toml:"name"`
Operation string `toml:"operation"` // +, -
MultiplicationFactor float64 `toml:"factor"`
SubAccount string `toml:"other_account"` // *, /
}
type calculatedAccount struct {
Name string `toml:"name"`
UseAbs bool `toml:"use_abs"`
AccountOperations []accountOp `toml:"account_operation"`
}
type reportConfig struct {
Name string
Chart string
RangeBalanceType ledger.RangeType `toml:"range_balance_type"`
RangeBalanceSkipZero bool `toml:"range_balance_skip_zero"`
DateRange string `toml:"date_range"`
DateFreq string `toml:"date_freq"`
Accounts []string
ExcludeAccountTrans []string `toml:"exclude_account_trans"`
ExcludeAccountsSummary []string `toml:"exclude_account_summary"`
CalculatedAccounts []calculatedAccount `toml:"calculated_account"`
}
type reportConfigStruct struct {
Reports []reportConfig `toml:"report"`
}
var reportConfigData reportConfigStruct
type quickviewAccountConfig struct {
Name string
ShortName string `toml:"short_name"`
}
type quickviewConfigStruct struct {
Accounts []quickviewAccountConfig `toml:"account"`
}
var quickviewConfigData quickviewConfigStruct
type stockConfig struct {
Name string
SecurityType string `toml:"security_type"`
Section string
Ticker string
Account string
Shares float64
}
type stockInfo struct {
Name string
Section string
Type string
Ticker string
Account string
Shares float64
Price float64
PriceChangeDay float64
PriceChangePctDay float64
PriceChangeOverall float64
PriceChangePctOverall float64
Cost float64
MarketValue float64
GainLossDay float64
GainLossOverall float64
Weight float64
AnnualDividends float64
AnnualYield float64
}
type portfolioStruct struct {
Name string
ShowDividends bool `toml:"show_dividends"`
ShowWeight bool `toml:"show_weight"`
Stocks []stockConfig `toml:"stock"`
}
type portfolioConfigStruct struct {
Portfolios []portfolioStruct `toml:"portfolio"`
AVToken string `toml:"av_token"`
}
var portfolioConfigData portfolioConfigStruct
type pageData struct {
Reports []reportConfig
Transactions []*ledger.Transaction
Accounts []*ledger.Account
Stocks []stockInfo
Portfolios []portfolioStruct
AccountNames []string
ReadOnly bool
}
func (p *pageData) Init() {
p.ReadOnly = webReadOnly
p.Reports = reportConfigData.Reports
p.Portfolios = portfolioConfigData.Portfolios
}
func configLoaders(dur time.Duration) {
if len(reportConfigFileName) > 0 {
go func() {
for {
var rLoadData reportConfigStruct
ifile, ierr := os.Open(reportConfigFileName)
if ierr != nil {
log.Println(ierr)
}
tdec := toml.NewDecoder(ifile)
err := tdec.Decode(&rLoadData)
if err != nil {
log.Println(err)
}
ifile.Close()
reportConfigData = rLoadData
time.Sleep(dur)
}
}()
}
if len(quickviewConfigFileName) > 0 {
go func() {
for {
var sLoadData quickviewConfigStruct
ifile, ierr := os.Open(quickviewConfigFileName)
if ierr != nil {
log.Println(ierr)
}
tdec := toml.NewDecoder(ifile)
err := tdec.Decode(&sLoadData)
if err != nil {
log.Println(err)
}
ifile.Close()
quickviewConfigData = sLoadData
time.Sleep(dur)
}
}()
}
if len(stockConfigFileName) > 0 {
go func() {
for {
var sLoadData portfolioConfigStruct
ifile, ierr := os.Open(stockConfigFileName)
if ierr != nil {
log.Println(ierr)
}
tdec := toml.NewDecoder(ifile)
err := tdec.Decode(&sLoadData)
if err != nil {
log.Println(err)
}
ifile.Close()
portfolioConfigData = sLoadData
time.Sleep(dur)
}
}()
}
}