Remove unused ports

master
Bel LaPointe 2018-10-09 09:07:48 -06:00
parent 798d451103
commit e4785e6a05
4 changed files with 13 additions and 19 deletions

View File

@ -2,37 +2,34 @@ package config
import ( import (
"flag" "flag"
"fmt"
"os" "os"
"strings" "strings"
) )
const cdbpath = "DBPath" const cdbpath = "DBPath"
const port = "port" const port = "port"
const mport = "mport"
const fport = "fport"
type Config struct { type Config struct {
DBPath string DBPath string
Port string Port string
MonitorPort string
FetchPort string
} }
func New() *Config { func New() *Config {
lookups := make(map[string]*string) lookups := make(map[string]*string)
add(cdbpath, "./db", lookups) add(cdbpath, "./db", lookups)
add(port, ":9101", lookups) add(port, ":9101", lookups)
add(mport, ":9102", lookups)
add(fport, ":9103", lookups)
flag.Parse() flag.Parse()
return &Config{ return &Config{
DBPath: *lookups[cdbpath], DBPath: *lookups[cdbpath],
Port: *lookups[port], Port: *lookups[port],
MonitorPort: *lookups[mport],
FetchPort: *lookups[fport],
} }
} }
func (c *Config) String() string {
return fmt.Sprintf("Port:%q", c.Port)
}
func add(key string, value string, lookups map[string]*string) { func add(key string, value string, lookups map[string]*string) {
env := os.Getenv(strings.ToUpper(key)) env := os.Getenv(strings.ToUpper(key))
if env != "" { if env != "" {

View File

@ -14,6 +14,7 @@ const nsForFeeds = "FEEDS"
func main() { func main() {
config := config.New() config := config.New()
logger.Log("Starting with", config)
var sclient store.Client var sclient store.Client
var err error var err error
@ -23,7 +24,7 @@ func main() {
defer sclient.Close() defer sclient.Close()
allFeeds := make(map[string]*rss.Feed) 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] feed, ok := allFeeds[url]
if !ok { if !ok {
f, err := rss.New(url, "", "") f, err := rss.New(url, "", "")

View File

@ -11,15 +11,13 @@ import (
type Monitor struct { type Monitor struct {
newItems chan Item newItems chan Item
trigger func(string) 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) newItems := make(chan Item)
return &Monitor{ return &Monitor{
newItems: newItems, newItems: newItems,
trigger: trigger, trigger: trigger,
port: port,
}, nil }, nil
} }

View File

@ -8,12 +8,10 @@ import (
"github.com/golang-collections/go-datastructures/queue" "github.com/golang-collections/go-datastructures/queue"
) )
const testmport = ":13152"
func Test_Monitor(t *testing.T) { func Test_Monitor(t *testing.T) {
numItems := 2 numItems := 2
completed := make(chan struct{}, numItems) completed := make(chan struct{}, numItems)
m, err := New(testmport, func(string) { completed <- struct{}{} }) m, err := New(func(string) { completed <- struct{}{} })
if err != nil { if err != nil {
t.Fatalf("cannot create new monitor: %v", err) t.Fatalf("cannot create new monitor: %v", err)
} }