From f31c13d76e5de8ab0420ecaf0f570e52f6218066 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Wed, 21 Sep 2016 13:40:38 -0700 Subject: reorganizing code to resemble a package + command structure. documented the install process --- cmd/cms/server.go | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 cmd/cms/server.go (limited to 'cmd/cms') diff --git a/cmd/cms/server.go b/cmd/cms/server.go new file mode 100644 index 0000000..d8fa224 --- /dev/null +++ b/cmd/cms/server.go @@ -0,0 +1,119 @@ +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/nilslice/cms/content" + "github.com/nilslice/cms/management/editor" + "github.com/nilslice/cms/management/manager" + "github.com/nilslice/cms/system/admin" + "github.com/nilslice/cms/system/db" +) + +func main() { + http.HandleFunc("/admin", func(res http.ResponseWriter, req *http.Request) { + adminView := admin.Admin(nil) + + res.Header().Set("Content-Type", "text/html") + res.Write(adminView) + }) + + http.HandleFunc("/admin/posts", func(res http.ResponseWriter, req *http.Request) { + q := req.URL.Query() + t := q.Get("type") + if t == "" { + res.WriteHeader(http.StatusBadRequest) + } + + posts := db.GetAll(t) + b := &bytes.Buffer{} + p := content.Types[t]().(editor.Editable) + + html := `New ` + t + ` +