-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathconfig.go
85 lines (80 loc) · 2.03 KB
/
config.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
package config
import (
"os"
"path/filepath"
"strings"
)
type Config struct {
ServerPort string
StoragePath string
Categories []string
Currency string
}
var defaultCategories = []string{
"Food",
"Groceries",
"Travel",
"Rent",
"Utilities",
"Entertainment",
"Healthcare",
"Shopping",
"Miscellaneous",
}
var currencySymbols = map[string]string{
"usd": "$", // US Dollar
"eur": "€", // Euro
"gbp": "£", // British Pound
"jpy": "¥", // Japanese Yen
"cny": "¥", // Chinese Yuan
"krw": "₩", // Korean Won
"inr": "₹", // Indian Rupee
"rub": "₽", // Russian Ruble
"brl": "R$", // Brazilian Real
"zar": "R", // South African Rand
"aed": "AED", // UAE Dirham
"aud": "A$", // Australian Dollar
"cad": "C$", // Canadian Dollar
"chf": "Fr", // Swiss Franc
"hkd": "HK$", // Hong Kong Dollar
"sgd": "S$", // Singapore Dollar
"thb": "฿", // Thai Baht
"try": "₺", // Turkish Lira
"mxn": "Mex$", // Mexican Peso
"php": "₱", // Philippine Peso
"pln": "zł", // Polish Złoty
"sek": "kr", // Swedish Krona
"nzd": "NZ$", // New Zealand Dollar
"dkk": "kr.", // Danish Krone
"idr": "Rp", // Indonesian Rupiah
"ils": "₪", // Israeli New Shekel
"vnd": "₫", // Vietnamese Dong
"myr": "RM", // Malaysian Ringgit
}
func NewConfig(dataPath string) *Config {
categories := defaultCategories
if envCategories := os.Getenv("EXPENSE_CATEGORIES"); envCategories != "" {
categories = strings.Split(envCategories, ",")
for i := range categories {
categories[i] = strings.TrimSpace(categories[i])
}
}
currency := "$" // Default to USD
if envCurrency := strings.ToLower(os.Getenv("CURRENCY")); envCurrency != "" {
if symbol, exists := currencySymbols[envCurrency]; exists {
currency = symbol
}
}
finalPath := ""
if dataPath == "data" {
finalPath = filepath.Join(".", "data")
} else {
finalPath = filepath.Clean(dataPath)
}
return &Config{
ServerPort: "8080",
StoragePath: finalPath,
Categories: categories,
Currency: currency,
}
}