Skip to content

Commit

Permalink
Rename config, set up storage repository
Browse files Browse the repository at this point in the history
  • Loading branch information
dewey committed Aug 29, 2018
1 parent 030daf5 commit b4b2b8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/dewey/feedbridge/api"
"github.com/dewey/feedbridge/config"
"github.com/dewey/feedbridge/plugin"
"github.com/dewey/feedbridge/plugins/scmp"
"github.com/dewey/feedbridge/runner"

"github.com/dewey/feedbridge/store"
"github.com/go-chi/chi"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
)

func main() {
err := env.Parse(&config.Config)
var cfg config.Config
err := env.Parse(&cfg)
if err != nil {
panic(err)
}

l := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
switch strings.ToLower(config.Environment) {
switch strings.ToLower(cfg.Environment) {
case "develop":
l = level.NewFilter(l, level.AllowInfo())
case "prod":
Expand All @@ -53,7 +57,12 @@ func main() {
pluginRepo := plugin.NewMemRepo()
pluginRepo.Install(scmp.NewPlugin(l, c))

runner := runner.NewRunner(l, pluginRepo, storageRepo, config.RefreshInterval)
storageRepo, err := store.NewStoreBackend(cfg)
if err != nil {
return
}

runner := runner.NewRunner(l, pluginRepo, storageRepo, cfg.RefreshInterval)
go runner.Start()

apiService := api.NewService(l, storageRepo, pluginRepo)
Expand All @@ -73,7 +82,7 @@ func main() {
RefreshInterval int
}{
Feeds: apiService.ListFeeds(),
RefreshInterval: config.RefreshInterval,
RefreshInterval: cfg.RefreshInterval,
}
if err := t.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -91,8 +100,8 @@ func main() {
w.Write([]byte("nothing to see here"))
})

l.Log("msg", fmt.Sprintf("feedbridge listening on http://localhost:%d", config.Port))
err = http.ListenAndServe(fmt.Sprintf(":%d", config.Port), r)
l.Log("msg", fmt.Sprintf("feedbridge listening on http://localhost:%d", cfg.Port))
err = http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), r)
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ type StorageRepository interface {
}

// NewStoreBackend is a factory to return a store implementation based on the config choosen
func NewStoreBackend(cfg config.Config) (*StorageRepository, error) {
var storageRepo *StorageRepository
func NewStoreBackend(cfg config.Config) (StorageRepository, error) {
var storageRepo StorageRepository
switch cfg.StorageBackend {
case "memory":
memory, err := NewMemRepository(config.CacheExpiration, config.CacheExpiredPurge)
memory, err := NewMemRepository(cfg.CacheExpiration, cfg.CacheExpiredPurge)
if err != nil {
return nil, err
}
storageRepo = memory
case "persistent":
disk, err := NewDiskRepository(config.StoragePath)
disk, err := NewDiskRepository(cfg.StoragePath)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit b4b2b8a

Please sign in to comment.