Skip to content

Commit a5beaf9

Browse files
committed
small refactor
1 parent 552a76d commit a5beaf9

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

internal/conf/conf.go

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package conf
22

3+
import "encoding/json"
4+
35
const (
46
// Available themes
57
ThemeDefault = ThemeCxd
@@ -14,34 +16,45 @@ const (
1416
LocaleEnUS = "en-US"
1517
)
1618

17-
type Theme = option
18-
19-
type Local = option
20-
21-
type option struct {
19+
type Theme struct {
2220
Value string `json:"value"`
2321
Label string `json:"label"`
24-
Dict any `json:"-"`
22+
}
23+
24+
type Local struct {
25+
Value string `json:"value"`
26+
Label string `json:"label"`
27+
Dict json.RawMessage `json:"-"`
2528
}
2629

2730
func RegularThemes(themes []Theme) {
2831
for i := range themes {
29-
themes[i] = themes[i].regular(ThemeDefault)
32+
themes[i] = themes[i].regular()
3033
}
3134
}
3235

3336
func RegularLocales(langs []Local) {
3437
for i := range langs {
35-
langs[i] = langs[i].regular(LocaleDefault)
38+
langs[i] = langs[i].regular()
39+
}
40+
}
41+
42+
func (t Theme) regular() Theme {
43+
if t.Value == "" {
44+
t.Value = ThemeDefault
45+
}
46+
if t.Label == "" {
47+
t.Label = t.Value
3648
}
49+
return t
3750
}
3851

39-
func (o option) regular(placeholder string) option {
40-
if o.Value == "" {
41-
o.Value = placeholder
52+
func (l Local) regular() Local {
53+
if l.Value == "" {
54+
l.Value = LocaleDefault
4255
}
43-
if o.Label == "" {
44-
o.Label = o.Value
56+
if l.Label == "" {
57+
l.Label = l.Value
4558
}
46-
return o
59+
return l
4760
}

0 commit comments

Comments
 (0)