-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
86 lines (73 loc) 路 2.25 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
86
package webindexer
import (
"fmt"
)
type Config struct {
BaseURL string `yaml:"base_url" mapstructure:"base_url"`
DateFormat string `yaml:"date_format" mapstructure:"date_format"`
DirsFirst bool `yaml:"dirs_first" mapstructure:"dirs_first"`
IndexFile string `yaml:"index_file" mapstructure:"index_file"`
LinkToIndexes bool `yaml:"link_to_index" mapstructure:"link_to_index"`
LogLevel string `yaml:"log_level" mapstructure:"log_level"`
LogFile string `yaml:"log_file" mapstructure:"log_file"`
Minify bool `yaml:"minify" mapstructure:"minify"`
Order string `yaml:"order" mapstructure:"order"`
Quiet bool `yaml:"quiet" mapstructure:"quiet"`
Recursive bool `yaml:"recursive" mapstructure:"recursive"`
Skips []string `yaml:"skips" mapstructure:"skips"`
SortBy string `yaml:"sort_by" mapstructure:"sort_by"`
Source string `yaml:"source" mapstructure:"source"`
Target string `yaml:"target" mapstructure:"target"`
Template string `yaml:"template" mapstructure:"template"`
Title string `yaml:"title" mapstructure:"title"`
CfgFile string `yaml:"-"`
BasePath string `yaml:"-"`
}
type SortBy string
const (
SortByDate SortBy = "date"
SortByName SortBy = "name"
SortByNaturalName SortBy = "natural_name"
)
type Order string
const (
OrderAsc Order = "asc"
OrderDesc Order = "desc"
)
func (c Config) SortByValue() SortBy {
switch c.SortBy {
case "last_modified":
return SortByDate
case "name":
return SortByName
case "natural_name":
return SortByNaturalName
default:
return ""
}
}
func (c Config) OrderByValue() Order {
switch c.Order {
case "asc":
return OrderAsc
case "desc":
return OrderDesc
default:
return ""
}
}
func (c Config) Validate() error {
if c.Source == "" {
return fmt.Errorf("source is required")
}
if c.Target == "" {
return fmt.Errorf("target is required")
}
if c.SortByValue() == "" {
return fmt.Errorf("sort_by must be one of: last_modified, name, natural_name")
}
if c.OrderByValue() == "" {
return fmt.Errorf("order must be one of: asc, desc")
}
return nil
}