-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.12 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
package main
import (
l4g "code.google.com/p/log4go"
"flag"
"github.com/jasocox/goblog/blog"
"github.com/jasocox/goblog/reader"
"github.com/jasocox/goblog/router"
"github.com/jasocox/goblog/view"
"net/http"
"os"
"time"
)
var (
blog_dir = flag.String("b", "", "directory where blogs a stored")
protocol = flag.String("p", "2001", "protocal to run on")
log = l4g.NewDefaultLogger(l4g.WARNING)
)
func main() {
log.Trace("Starting")
flag.Parse()
if *blog_dir == "" {
log.Error("Must specify a directory where blogs are stored")
time.Sleep(1000)
os.Exit(1)
}
blogs := blog.New()
blogReader := reader.New(blogs, *blog_dir, log)
v := view.New(blogs, log)
router := router.New(v, log)
err := blogReader.ReadBlogs()
if err != nil {
log.Error("Error creating blog reader: %s", err)
time.Sleep(1000)
os.Exit(1)
}
http.Handle("/", router)
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("./public"))))
err = http.ListenAndServe(":"+*protocol, nil)
if err != nil {
log.Error("Problem with http server: %s", err)
time.Sleep(1000)
os.Exit(1)
}
log.Trace("Stopping")
}