This commit is contained in:
2024-04-12 13:00:28 +03:00
parent ac84e48d8f
commit f1f5e1b712
13 changed files with 303 additions and 291 deletions

27
config/config.go Normal file
View File

@ -0,0 +1,27 @@
package config
type Config struct {
Accounts []ConfigAccount `json:"accounts"`
TransactionTypes []ConfigTransactionTypes `json:"transaction_types"`
}
type ConfigAccount struct {
Firefly3Name string `json:"firefly3_name,omitempty"`
MonobankId string `json:"monobank_id,omitempty"`
}
type ConfigTransactionTypes struct {
Names []string `json:"names,omitempty"`
NamesRefund []string `json:"names_refund,omitempty"`
MccCodes []int `json:"mcc_codes,omitempty"`
Firefly3 ConfigTransactionTypeFirefly3 `json:"firefly3,omitempty"`
SumMax int `json:"sum_max,omitempty"`
}
type ConfigTransactionTypeFirefly3 struct {
Type string `json:"type,omitempty"`
Destination string `json:"destination,omitempty"`
Description string `json:"description,omitempty"`
Category string `json:"category,omitempty"`
IsUseDestinationAsSource bool `json:"is_use_destination_as_source,omitempty"`
}

11
config/helpers.go Normal file
View File

@ -0,0 +1,11 @@
package config
func (c *Config) GetAccountByMonobankId(q string) ConfigAccount {
for _, row := range c.Accounts {
if row.MonobankId == q {
return row
}
}
return ConfigAccount{}
}

31
config/reader.go Normal file
View File

@ -0,0 +1,31 @@
package config
import (
"encoding/json"
"io"
"os"
)
func Read(path string) (Config, error) {
var config Config
// open file
file, err := os.Open(path)
if err != nil {
return config, err
}
defer file.Close()
// read file
bytes, err := io.ReadAll(file)
if err != nil {
return config, err
}
// read file ot config struct
if err := json.Unmarshal(bytes, &config); err != nil {
return config, err
}
return config, nil
}