Documentation ¶
Overview ¶
Package routes contains HTTP routing logic for the whole application (feeds, posts, settings and users). If you need to implement a new feature or change something, you probably need to visit this package.
Index ¶
- func CreatePost(w http.ResponseWriter, r *http.Request)
- func CreateUser(w http.ResponseWriter, r *http.Request)
- func DeletePost(w http.ResponseWriter, r *http.Request)
- func EditPost(w http.ResponseWriter, r *http.Request)
- func GetPost(r *http.Request) (Post, error)
- func GetSettings(r *http.Request) (Vertigo, error)
- func GetUser(r *http.Request) (User, error)
- func Homepage(w http.ResponseWriter, r *http.Request)
- func LoginUser(w http.ResponseWriter, r *http.Request)
- func LogoutUser(w http.ResponseWriter, r *http.Request)
- func PublishPost(w http.ResponseWriter, r *http.Request)
- func ReadFeed(w http.ResponseWriter, r *http.Request)
- func ReadPost(w http.ResponseWriter, r *http.Request)
- func ReadPosts(w http.ResponseWriter, r *http.Request)
- func ReadSettings(w http.ResponseWriter, r *http.Request)
- func ReadUser(w http.ResponseWriter, r *http.Request)
- func ReadUsers(w http.ResponseWriter, r *http.Request)
- func RecoverUser(w http.ResponseWriter, r *http.Request)
- func ResetUserPassword(w http.ResponseWriter, r *http.Request)
- func SearchPost(w http.ResponseWriter, r *http.Request)
- func UnpublishPost(w http.ResponseWriter, r *http.Request)
- func UpdatePost(w http.ResponseWriter, r *http.Request)
- func UpdateSettings(w http.ResponseWriter, r *http.Request)
- type Search
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreatePost ¶
func CreatePost(w http.ResponseWriter, r *http.Request)
CreatePost is a route which creates a new post according to the posted data. API renderponse contains the created post object and normal request redirects to "/user" page. Does not publish the post automatically. See PublishPost for more.
func CreateUser ¶
func CreateUser(w http.ResponseWriter, r *http.Request)
CreateUser is a route which creates a new user struct according to posted parameters. Requires session cookie. Returns created user struct for API requests and redirects to "/user" on frontend ones.
func DeletePost ¶
func DeletePost(w http.ResponseWriter, r *http.Request)
DeletePost is a route which deletes a post according to martini parameter "title". JSON request returns `HTTP 200 {"success": "Post deleted"}` on success. Frontend call will redirect to "/user" page on successful request. Requirender active session cookie.
func EditPost ¶
func EditPost(w http.ResponseWriter, r *http.Request)
EditPost is a route which returns a post object to be displayed and edited on frontend. Not available for JSON API. Analogous to ReadPost. Could be replaced at some point.
func GetSettings ¶
func Homepage ¶
func Homepage(w http.ResponseWriter, r *http.Request)
Homepage route fetches all posts from database and renders them according to "home.tmpl". Normally you'd use this function as your "/" route.
func LoginUser ¶
func LoginUser(w http.ResponseWriter, r *http.Request)
LoginUser is a route which compares plaintext password sent with POST request with hash stored in database. On successful request returns session cookie named "user", which contains user's ID encrypted, which is the primary key used in database table. When called by API it responds with user struct. On frontend call it redirects the client to "/user" page.
func LogoutUser ¶
func LogoutUser(w http.ResponseWriter, r *http.Request)
LogoutUser is a route which deletes session cookie "user", from the given client. On API call responds with HTTP 200 body and on frontend the client is redirected to homepage "/".
func PublishPost ¶
func PublishPost(w http.ResponseWriter, r *http.Request)
PublishPost is a route which publishes a post and therefore making it appear on frontpage and search. JSON request returns `HTTP 200 {"success": "Post published"}` on success. Frontend call will redirect to published page. Requirender active session cookie.
func ReadFeed ¶
func ReadFeed(w http.ResponseWriter, r *http.Request)
ReadFeed renders RSS or Atom feed of latest published posts. It determines the feed type with strings.Split(r.URL.Path[1:], "/")[1].
func ReadPost ¶
func ReadPost(w http.ResponseWriter, r *http.Request)
ReadPost is a route which returns post with given post.Slug. Returns post data on JSON call and displays a formatted page on frontend.
func ReadPosts ¶
func ReadPosts(w http.ResponseWriter, r *http.Request)
ReadPosts is a route which returns all posts without merged owner data (although the object does include author field) Not available on frontend, so therefore it only returns a JSON renderponse, hence the post iteration in Go.
func ReadSettings ¶
func ReadSettings(w http.ResponseWriter, r *http.Request)
ReadSettings is a route which reads the local settings.json file.
func ReadUser ¶
func ReadUser(w http.ResponseWriter, r *http.Request)
ReadUser is a route which fetches user according to parameter "id" on API side and according to retrieved session cookie on frontend side. Returns user struct with all posts merged to object on API call. Frontend call will render user "home" page, "user/index.tmpl".
func ReadUsers ¶
func ReadUsers(w http.ResponseWriter, r *http.Request)
ReadUsers is a route only available on API side, which fetches all users with post data merged. Returns complete list of users on success.
func RecoverUser ¶
func RecoverUser(w http.ResponseWriter, r *http.Request)
RecoverUser is a route of the first step of account recovery, which sends out the recovery email etc. associated function calls.
func ResetUserPassword ¶
func ResetUserPassword(w http.ResponseWriter, r *http.Request)
ResetUserPassword is a route which is called when accessing the page generated dispatched with account recovery emails.
func SearchPost ¶
func SearchPost(w http.ResponseWriter, r *http.Request)
SearchPost is a route which returns all posts and aggregates the ones which contain the POSTed search query in either Title or Content field.
func UnpublishPost ¶
func UnpublishPost(w http.ResponseWriter, r *http.Request)
UnpublishPost is a route which unpublishes a post and therefore making it disappear from frontpage and search. JSON request returns `HTTP 200 {"success": "Post unpublished"}` on success. Frontend call will redirect to user control panel. Requirender active session cookie. The route is anecdotal to route PublishPost().
func UpdatePost ¶
func UpdatePost(w http.ResponseWriter, r *http.Request)
UpdatePost is a route which updates a post defined by martini parameter "title" with posted data. Requirender session cookie. JSON request returns the updated post object, frontend call will redirect to "/user".
func UpdateSettings ¶
func UpdateSettings(w http.ResponseWriter, r *http.Request)
UpdateSettings is a route which updates the local .json settings file.
Types ¶
type Search ¶
type Search struct { Query string `json:"query" form:"query" binding:"required"` Score float64 Posts []Post }
Search struct is basically just a type check to make sure people don't add anything nasty to on-site search queries.