Skip to content

Commit

Permalink
streamline backend/frontend interface
Browse files Browse the repository at this point in the history
  • Loading branch information
schachmat committed Feb 18, 2016
1 parent 53232e8 commit 20771c3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 36 deletions.
14 changes: 0 additions & 14 deletions backends/backends.go

This file was deleted.

2 changes: 1 addition & 1 deletion backends/worldweatheronline.com.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ func (c *wwoConfig) Fetch(loc string, numdays int) (ret iface.Resp) {
}

func init() {
All["worldweatheronline.com"] = &wwoConfig{}
iface.AllBackends["worldweatheronline.com"] = &wwoConfig{}
}
2 changes: 1 addition & 1 deletion frontends/ascii-art-table.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,5 +466,5 @@ func (c *aatConfig) Render(r iface.Resp) {
}

func init() {
All["ascii-art-table"] = &aatConfig{}
iface.AllFrontends["ascii-art-table"] = &aatConfig{}
}
14 changes: 0 additions & 14 deletions frontends/frontends.go

This file was deleted.

15 changes: 15 additions & 0 deletions iface/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ type Resp struct {
Weather []Weather `json:"weather"`
} `json:"data"`
}

type Backend interface {
Setup()
Fetch(location string, numdays int) Resp
}

type Frontend interface {
Setup()
Render(weather Resp)
}

var (
AllBackends = make(map[string]Backend)
AllFrontends = make(map[string]Frontend)
)
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"strconv"

"github.com/schachmat/ingo"
"github.com/schachmat/wego/backends"
"github.com/schachmat/wego/frontends"
_ "github.com/schachmat/wego/backends"
_ "github.com/schachmat/wego/frontends"
"github.com/schachmat/wego/iface"
)

func main() {
Expand All @@ -24,10 +25,10 @@ func main() {
}

// initialize backends and frontends (flags and default config)
for _, be := range backends.All {
for _, be := range iface.AllBackends {
be.Setup()
}
for _, fe := range frontends.All {
for _, fe := range iface.AllFrontends {
fe.Setup()
}

Expand All @@ -50,14 +51,14 @@ func main() {
}

// get selected backend and fetch the weather data from it
be, ok := backends.All[*selectedBackend]
be, ok := iface.AllBackends[*selectedBackend]
if !ok {
log.Fatalf("Could not find selected backend \"%s\"", *selectedBackend)
}
r := be.Fetch(*location, *numdays)

// get selected frontend and render the weather data with it
fe, ok := frontends.All[*selectedFrontend]
fe, ok := iface.AllFrontends[*selectedFrontend]
if !ok {
log.Fatalf("Could not find selected frontend \"%s\"", *selectedFrontend)
}
Expand Down

0 comments on commit 20771c3

Please sign in to comment.