-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (46 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"net/url"
"time"
"github.com/yanzay/autohome/modules/arduino"
"github.com/yanzay/autohome/modules/habra"
"github.com/yanzay/autohome/modules/weather"
)
type Application struct {
scheduler *Scheduler
db storage
modules map[string]Module
}
type Module interface {
Initialize(map[string]string, interface{})
Functions() []string
Settings() []string
Send(string)
Handle(string, string, url.Values) (string, map[string]string)
Menus() []string
}
func (a *Application) registerModules() {
a.modules = make(map[string]Module)
a.registerModule("arduino", new(arduino.ArduinoModule))
a.registerModule("weather", new(weather.WeatherModule))
a.registerModule("habra", new(habra.HabraModule))
}
func (a *Application) registerModule(name string, module Module) {
opts := a.db.getSettings()
module.Initialize(opts[name], a.db)
a.modules[name] = module
}
func main() {
app := new(Application)
app.db = NewSqliteStorage()
app.registerModules()
app.db.prepareSettings(app.modules)
app.scheduler = NewScheduler(app)
go startWebServer(app)
mainLoop()
}
func mainLoop() {
for {
time.Sleep(5 * time.Second)
}
}