-
Notifications
You must be signed in to change notification settings - Fork 0
/
rem.go
49 lines (43 loc) · 946 Bytes
/
rem.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
package main
import (
"encoding/json"
"flag"
"log"
"net/http"
"os"
)
const (
version = "0.6.0"
)
type App struct {
Notification
Domain string
Path string
Port string
}
func main() {
app := new(App)
app.Notification = *&Notification{}
app.loadConfigurationFile()
mux := http.NewServeMux()
mux.Handle("/", CreateReminder(app))
log.Printf("Serving rem (version: %v) on %v/%v",
version, ":"+app.Port, app.Path)
err := http.ListenAndServe(":"+app.Port, mux)
log.Fatal(err)
}
func (self *App) loadConfigurationFile() {
var config = flag.String("config", "rem.conf",
"configuration file to use")
flag.Parse()
configFile, err := os.Open(*config)
die("error: unable to find configuration file! %v", err)
decoder := json.NewDecoder(configFile)
err = decoder.Decode(&self)
die("error: unable to parse configuration file: %v", err)
}
func die(format string, err error) {
if err != nil {
log.Fatalf(format, err)
}
}