diff --git a/config/config.go b/config/config.go index 49b139d..9e6a858 100644 --- a/config/config.go +++ b/config/config.go @@ -2,37 +2,34 @@ package config import ( "flag" + "fmt" "os" "strings" ) const cdbpath = "DBPath" const port = "port" -const mport = "mport" -const fport = "fport" type Config struct { - DBPath string - Port string - MonitorPort string - FetchPort string + DBPath string + Port string } func New() *Config { lookups := make(map[string]*string) add(cdbpath, "./db", lookups) add(port, ":9101", lookups) - add(mport, ":9102", lookups) - add(fport, ":9103", lookups) flag.Parse() return &Config{ - DBPath: *lookups[cdbpath], - Port: *lookups[port], - MonitorPort: *lookups[mport], - FetchPort: *lookups[fport], + DBPath: *lookups[cdbpath], + Port: *lookups[port], } } +func (c *Config) String() string { + return fmt.Sprintf("Port:%q", c.Port) +} + func add(key string, value string, lookups map[string]*string) { env := os.Getenv(strings.ToUpper(key)) if env != "" { diff --git a/main.go b/main.go index 5c0374f..56aa55f 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ const nsForFeeds = "FEEDS" func main() { config := config.New() + logger.Log("Starting with", config) var sclient store.Client var err error @@ -23,7 +24,7 @@ func main() { defer sclient.Close() allFeeds := make(map[string]*rss.Feed) - mon, err := monitor.New(config.MonitorPort, func(url string) { + mon, err := monitor.New(func(url string) { feed, ok := allFeeds[url] if !ok { f, err := rss.New(url, "", "") diff --git a/monitor/monitor.go b/monitor/monitor.go index 726845c..1f8f383 100644 --- a/monitor/monitor.go +++ b/monitor/monitor.go @@ -11,15 +11,13 @@ import ( type Monitor struct { newItems chan Item trigger func(string) - port string } -func New(port string, trigger func(string)) (*Monitor, error) { +func New(trigger func(string)) (*Monitor, error) { newItems := make(chan Item) return &Monitor{ newItems: newItems, trigger: trigger, - port: port, }, nil } diff --git a/monitor/monitor_test.go b/monitor/monitor_test.go index 8b9d956..ac506a3 100644 --- a/monitor/monitor_test.go +++ b/monitor/monitor_test.go @@ -8,12 +8,10 @@ import ( "github.com/golang-collections/go-datastructures/queue" ) -const testmport = ":13152" - func Test_Monitor(t *testing.T) { numItems := 2 completed := make(chan struct{}, numItems) - m, err := New(testmport, func(string) { completed <- struct{}{} }) + m, err := New(func(string) { completed <- struct{}{} }) if err != nil { t.Fatalf("cannot create new monitor: %v", err) }