forked from slogsdon/b
/
b.go
57 lines (47 loc) · 1.27 KB
/
b.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
55
56
57
// B is a static-ish blog application. Can be run
// as a standalone application/server or be used
// to locally manage and deploy posts to a remote
// server.
package b
import (
"github.com/go-martini/martini"
// "github.com/martini-contrib/gzip"
"github.com/martini-contrib/render"
"github.com/slogsdon/b/handlers"
"github.com/slogsdon/b/util"
)
const (
// Current application version.
VERSION = "0.0.1"
)
// Entry point for running the application.
// It defines all routes and middleware used
// and starts the underlying server.
func Start() {
// Set up our Martini instance
m := martini.Classic()
// Middleware
// m.Use(gzip.All())
m.Use(render.Renderer())
// Routes
m.Group("/admin", func(r martini.Router) {
a := handlers.Admin{}
r.Get("", a.Index)
r.Get("/posts", a.Posts.Index)
r.Get("/posts/new", a.Posts.New)
r.Get("/posts/:id/edit", a.Posts.Edit)
}, render.Renderer(render.Options{
Layout: "admin/layout",
}))
m.Group("/api", func(r martini.Router) {
a := handlers.Api{}
r.Get("", a.Index)
r.Get("/posts", a.Posts.Index)
r.Post("/posts", a.Posts.Create)
r.Get("/posts/:id", a.Posts.Show)
r.Get("/render/markdown", a.Render.Markdown)
})
// Serve from static if possible
m.Use(martini.Static(util.Config().App.SiteDir))
m.Run()
}