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 (
"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 != "" {

View File

@ -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, "", "")

View File

@ -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
}

View File

@ -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)
}