Skip to content

Commit

Permalink
refactor: separate code
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotuna committed Sep 1, 2023
1 parent 8e94e0a commit 42819c9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions internal/cache/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cache

import "sync"

// URLCache is a struct to hold the visited URLs
type URLCache struct {
mu sync.Mutex
URLs map[string]bool
}

// Add adds a URL to the cache
func (c *URLCache) Add(url string) {
c.mu.Lock()
defer c.mu.Unlock()
c.URLs[url] = true
}

// Get checks if a URL is in the cache
func (c *URLCache) Get(url string) bool {
c.mu.Lock()
defer c.mu.Unlock()
_, ok := c.URLs[url]
return ok
}
24 changes: 24 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package config

type Config struct {
Scrape ScrapeConfig `mapstructure:"scrape"`
Sitemap SitemapConfig `mapstructure:"sitemap"`
}

type SitemapConfig struct {
Dir string `mapstructure:"dir"`
URL string `mapstructure:"url"`
ReplaceURL string `mapstructure:"replace-url"`
File string `mapstructure:"file"`
}

type ScrapeConfig struct {
Dir string `mapstructure:"dir"`
URL string `mapstructure:"url"`
Cache string `mapstructure:"cache"`
ReplaceURL string `mapstructure:"replace-url"`
Replace bool `mapstructure:"replace"`
Parallel bool `mapstructure:"parallel"`
Images bool `mapstructure:"images"`
CheckHead bool `mapstructure:"check-head"`
}

0 comments on commit 42819c9

Please sign in to comment.