phew
This commit is contained in:
parent
d575ec8beb
commit
ba2293149e
|
@ -45,7 +45,7 @@ type Config struct {
|
||||||
MaxClients uint32 `toml:"max_clients"`
|
MaxClients uint32 `toml:"max_clients"`
|
||||||
FallbackResolver string `toml:"fallback_resolver"`
|
FallbackResolver string `toml:"fallback_resolver"`
|
||||||
IgnoreSystemDNS bool `toml:"ignore_system_dns"`
|
IgnoreSystemDNS bool `toml:"ignore_system_dns"`
|
||||||
TimeRanges map[string][]TimeRangeStr `toml:"time_ranges"`
|
AllWeeklyRanges map[string]WeeklyRangesStr `toml:"time_ranges"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfig() Config {
|
func newConfig() Config {
|
||||||
|
@ -222,7 +222,9 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
|
||||||
|
|
||||||
proxy.forwardFile = config.ForwardFile
|
proxy.forwardFile = config.ForwardFile
|
||||||
|
|
||||||
parseWeeklyRanges(config.TimeRanges)
|
if err := parseAllWeeklyRanges(config.AllWeeklyRanges); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := config.loadSources(proxy); err != nil {
|
if err := config.loadSources(proxy); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -320,12 +320,11 @@ format = 'tsv'
|
||||||
|
|
||||||
[time_ranges]
|
[time_ranges]
|
||||||
|
|
||||||
[time_ranges.'time-to-sleep']
|
[time_ranges.'timetosleep']
|
||||||
mon = [{after="22:00", before="07:00"}]
|
mon = [{after="22:00", before="07:00"}]
|
||||||
# mon = [{after="22:00", before="07:00"}]
|
tue = [{after="22:00", before="07:00"}]
|
||||||
# tue = [{after="22:00", before="07:00"}]
|
wed = [{after="22:00", before="07:00"}]
|
||||||
# wed = [{after="22:00", before="07:00"}]
|
thu = [{after="22:00", before="07:00"}]
|
||||||
# thu = [{after="22:00", before="07:00"}]
|
fri = [{after="22:00", before="07:00"}]
|
||||||
# fri = [{after="22:00", before="07:00"}]
|
sat = [{after="22:00", before="07:00"}]
|
||||||
# sat = [{after="22:00", before="07:00"}]
|
sun = [{after="22:00", before="07:00"}]
|
||||||
# sun = [{after="26:00", before="07:00"}]
|
|
||||||
|
|
|
@ -40,8 +40,8 @@ type PluginBlockName struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TimeRange struct {
|
type TimeRange struct {
|
||||||
start int
|
after int
|
||||||
end int
|
before int
|
||||||
}
|
}
|
||||||
|
|
||||||
type WeeklyRanges struct {
|
type WeeklyRanges struct {
|
||||||
|
@ -53,6 +53,10 @@ type TimeRangeStr struct {
|
||||||
Before string
|
Before string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WeeklyRangesStr struct {
|
||||||
|
Sun, Mon, Tue, Wed, Thu, Fri, Sat []TimeRangeStr
|
||||||
|
}
|
||||||
|
|
||||||
func daySecsFromStr(str string) (int, error) {
|
func daySecsFromStr(str string) (int, error) {
|
||||||
parts := strings.Split(str, ":")
|
parts := strings.Split(str, ":")
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
|
@ -83,19 +87,16 @@ func parseTimeRanges(timeRangesStr []TimeRangeStr) ([]TimeRange, error) {
|
||||||
if after == before {
|
if after == before {
|
||||||
after, before = -1, 86402
|
after, before = -1, 86402
|
||||||
}
|
}
|
||||||
|
timeRanges = append(timeRanges, TimeRange{after: after, before: before})
|
||||||
}
|
}
|
||||||
return timeRanges, nil
|
return timeRanges, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseWeeklyRanges(weeklyRangeStr map[string][]TimeRangeStr) (WeeklyRanges, error) {
|
func parseWeeklyRanges(weeklyRangesStr WeeklyRangesStr) (WeeklyRanges, error) {
|
||||||
weeklyRanges := WeeklyRanges{}
|
weeklyRanges := WeeklyRanges{}
|
||||||
daysStr := []string{"sun", "mon", "tue", "wed", "thu", "fri", "sat"}
|
weeklyRangesStrX := [7][]TimeRangeStr{weeklyRangesStr.Sun, weeklyRangesStr.Mon, weeklyRangesStr.Tue, weeklyRangesStr.Wed, weeklyRangesStr.Thu, weeklyRangesStr.Fri, weeklyRangesStr.Sat}
|
||||||
for day, dayStr := range daysStr {
|
for day, weeklyRangeStrX := range weeklyRangesStrX {
|
||||||
timeRangesStr, ok := weeklyRangeStr[dayStr]
|
timeRanges, err := parseTimeRanges(weeklyRangeStrX)
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
timeRanges, err := parseTimeRanges(timeRangesStr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return weeklyRanges, err
|
return weeklyRanges, err
|
||||||
}
|
}
|
||||||
|
@ -104,6 +105,18 @@ func parseWeeklyRanges(weeklyRangeStr map[string][]TimeRangeStr) (WeeklyRanges,
|
||||||
return weeklyRanges, nil
|
return weeklyRanges, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseAllWeeklyRanges(allWeeklyRangesStr map[string]WeeklyRangesStr) error {
|
||||||
|
allWeeklyRanges := make(map[string]WeeklyRanges)
|
||||||
|
for weeklyRangesName, weeklyRangesStr := range allWeeklyRangesStr {
|
||||||
|
weeklyRanges, err := parseWeeklyRanges(weeklyRangesStr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
allWeeklyRanges[weeklyRangesName] = weeklyRanges
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (plugin *PluginBlockName) Name() string {
|
func (plugin *PluginBlockName) Name() string {
|
||||||
return "block_name"
|
return "block_name"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue