Exemplo n.º 1
0
func InsertPost(w http.ResponseWriter, req *http.Request) {
	input := &repository.Post{
		Content:  req.FormValue("content"),
		Title:    req.FormValue("title"),
		Tags:     strings.Split(req.FormValue("tags"), ";"),
		DateTime: time.Now(),
	}
	repository.PostRepository().Add(input)
	http.Redirect(w, req, "/", 302)
}
Exemplo n.º 2
0
func GetPost(w http.ResponseWriter, r *http.Request) {
	variables := mux.Vars(r)
	permalink := variables["permalink"]
	result := repository.PostRepository().FindByPermalink(permalink)
	generatedTemplate, err := template.ParseFiles("templates/post.html")
	if err != nil {
		log.Fatal("Cant process index template")
	}
	generatedTemplate.Execute(w, result)
}
Exemplo n.º 3
0
//Route handlers
func Index(w http.ResponseWriter, r *http.Request) {
	generatedTemplate, err := template.ParseFiles("templates/index.html")
	if err != nil {
		log.Fatal("Cant process index template")
	}
	log.Print("Accessing Index page")
	collection := repository.PostRepository().FindAllSortByDate(3)
	page := Page{collection}
	generatedTemplate.Execute(w, page)
}
Exemplo n.º 4
0
func Init() {
	config := LoadConfiguration("application.conf")
	repository.SetupMongo(config.Host, config.Port)
	repository.PostRepository()
	repository.UserRepository()
}