Ejemplo n.º 1
0
func Index(session sessions.Session, r render.Render, auth core.AuthData) {

	var session_data = struct {
		Username  string
		PostsData Posts
	}{}

	v := session.Get("username")

	if v != nil {
		session_data.Username = v.(string)
	}

	req, _ := http.NewRequest("GET", "http://foojr.com/blog/posts", nil) //XXX handle error
	resp, _ := auth.CheckRequest(req)

	defer resp.Body.Close()
	data, _ := ioutil.ReadAll(resp.Body) //XXX handle error

	var posts Posts
	json.Unmarshal(data, &posts) //XXX handle error
	session_data.PostsData = posts

	r.HTML(200, "index", session_data)
}
Ejemplo n.º 2
0
func PostsHandler(r render.Render, auth core.AuthData) {

	if auth.Check() {
		r.JSON(200, postsdb)
	} else {
		r.JSON(http.StatusUnauthorized, struct{ Error string }{"Not Authorized"})
	}
}