handler.go 698 B

1234567891011121314151617181920212223242526272829303132333435
  1. package feed
  2. import (
  3. "net/http"
  4. "strconv"
  5. "github.com/gorilla/mux"
  6. "gopkg.in/errgo.v1"
  7. )
  8. type Post struct {
  9. Name, Text string
  10. }
  11. var db = []Post{
  12. Post{"Hello", "lot's of stuff"},
  13. Post{"Testing", "yeeeeaaaahhhh..."},
  14. Post{"WAT", "i have only a partial idea of what i'm doing"},
  15. }
  16. func showOverview(w http.ResponseWriter, req *http.Request) (interface{}, error) {
  17. return db, nil
  18. }
  19. func showPost(w http.ResponseWriter, req *http.Request) (interface{}, error) {
  20. i, err := strconv.Atoi(mux.Vars(req)["PostID"])
  21. if err != nil {
  22. return nil, errgo.Notef(err, "argument parsing failed")
  23. }
  24. if i < 0 || i >= len(db) {
  25. return nil, errgo.Newf("db limit exceeded")
  26. }
  27. return db[i], nil
  28. }