Skip to content

Commit

Permalink
refactor: add Domainlist type
Browse files Browse the repository at this point in the history
  • Loading branch information
WIttyJudge committed Dec 12, 2024
1 parent 0eec44a commit 45e988c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
25 changes: 11 additions & 14 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ import (

// Config represents the entire configuration structure.
type Config struct {
Blocklists []Blocklist `yaml:"blocklists"`
Whitelists []Whitelist `yaml:"whitelists"`
// Blocklist is a structure that represents where all these domains that needs
// to be blocked are located.
Blocklists []Domainlist `yaml:"blocklists"`

// Whitelists contains domains that must not be blocked.
// Adding some domains to whitelist may fix many problems like YouTube
// watch history, videos on news sites and so on.
Whitelists []Domainlist `yaml:"whitelists"`
}

// Blocklist is a structure that represents where all these domains that needs
// to be blocked are located.
type Blocklist struct {
Target string `yaml:"target"`
}

// Whitelists contains domains that must not be blocked.
// Adding some domains to whitelist may fix many problems like YouTube
// watch history, videos on news sites and so on.
type Whitelist struct {
type Domainlist struct {
Target string `yaml:"target"`
}

Expand Down Expand Up @@ -190,10 +187,10 @@ func homeDir() string {
// default one will be used.
func defaultConfig() *Config {
return &Config{
Blocklists: []Blocklist{
Blocklists: []Domainlist{
{Target: "https://raw.githubusercontent.com/StevenBlack/hosts/master/data/StevenBlack/hosts"},
},
Whitelists: []Whitelist{
Whitelists: []Domainlist{
{Target: "https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt"},
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/config/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestValidate(t *testing.T) {
t.Run("config is valid", func(t *testing.T) {
config := &Config{
Blocklists: []Blocklist{
Blocklists: []Domainlist{
{Target: "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts"},
},
}
Expand All @@ -26,7 +26,7 @@ func TestValidate(t *testing.T) {

t.Run("config has invalid target", func(t *testing.T) {
config := &Config{
Blocklists: []Blocklist{
Blocklists: []Domainlist{
{Target: "https://example.com/test page?query=value&extra#section+details"},
},
}
Expand Down

0 comments on commit 45e988c

Please sign in to comment.