Documentation ¶
Index ¶
- Variables
- func CloseDB()
- func Count(name string) int64
- func EnvOrElse(name, value string) string
- func Exists(name, id string) bool
- func InitDB()
- func Login(res http.ResponseWriter, req *http.Request)
- func Logout(res http.ResponseWriter, req *http.Request)
- func RootIndex(res http.ResponseWriter, req *http.Request)
- func TopicsCreate(res http.ResponseWriter, req *http.Request)
- func TopicsCreateJSON(res http.ResponseWriter, req *http.Request)
- func TopicsDestroy(res http.ResponseWriter, req *http.Request)
- func TopicsDestroyJSON(res http.ResponseWriter, req *http.Request)
- func TopicsIndex(res http.ResponseWriter, req *http.Request)
- func TopicsIndexJSON(res http.ResponseWriter, req *http.Request)
- func TopicsShow(res http.ResponseWriter, req *http.Request)
- func TopicsShowJSON(res http.ResponseWriter, req *http.Request)
- func TopicsUpdate(res http.ResponseWriter, req *http.Request)
- func TopicsUpdateJSON(res http.ResponseWriter, req *http.Request)
- func UsersCreate(res http.ResponseWriter, req *http.Request)
- type Topic
- type TopicData
- type User
Constants ¶
This section is empty.
Variables ¶
var Db gorp.DbMap
Db is a global instance that holds a connection to the DB. It gets initialized after calling the InitDB function. You have to call CloseDB in order to close the connection.
Functions ¶
func Count ¶
Count the number of rows for the given table. Returns a 0 on error. I know that this is not idiomatic, but it comes in handy in this case.
func EnvOrElse ¶
EnvOrElse returns the value of the given environment variable. If this environment variable is not set, then it returns the provided alternative value.
func Exists ¶
Exists returns true if there is a row in the given table that matches the given id. It returns false otherwise.
func Login ¶
func Login(res http.ResponseWriter, req *http.Request)
Login a user. It expects the "name" and "password" form values. Regardless if it was successful or not, it will redirect the user to the root path.
func RootIndex ¶
func RootIndex(res http.ResponseWriter, req *http.Request)
RootIndex renders the root page. It has three different options:
- If there's no user, it renders the "Create user" page.
- If the current user is not logged in, it render the "Login" page.
- If the current user is logged in, then it redirects the user to the /topics page.
func TopicsCreate ¶
func TopicsCreate(res http.ResponseWriter, req *http.Request)
TopicsCreate responds to: POST /topics
func TopicsCreateJSON ¶
func TopicsCreateJSON(res http.ResponseWriter, req *http.Request)
TopicsCreateJSON responds to: POST /topics. This will only be called when the user requested a JSON response.
func TopicsDestroy ¶
func TopicsDestroy(res http.ResponseWriter, req *http.Request)
TopicsDestroy responds to: DELETE /posts/:id
func TopicsDestroyJSON ¶
func TopicsDestroyJSON(res http.ResponseWriter, req *http.Request)
TopicsDestroyJSON responds to: PUT/PATCH /topics/:id. This will only be called when the user requested a JSON response.
func TopicsIndex ¶
func TopicsIndex(res http.ResponseWriter, req *http.Request)
TopicsIndex responds to: GET /topics
func TopicsIndexJSON ¶
func TopicsIndexJSON(res http.ResponseWriter, req *http.Request)
TopicsIndexJSON responds to: GET /topics. This will only be called when the user requested a JSON response.
func TopicsShow ¶
func TopicsShow(res http.ResponseWriter, req *http.Request)
TopicsShow responds to: GET /topics/:id
func TopicsShowJSON ¶
func TopicsShowJSON(res http.ResponseWriter, req *http.Request)
TopicsShowJSON responds to: GET /topics/:id. This will only be called when the user requested a JSON response.
func TopicsUpdate ¶
func TopicsUpdate(res http.ResponseWriter, req *http.Request)
TopicsUpdate responds to: PUT/PATCH /posts/:id
func TopicsUpdateJSON ¶
func TopicsUpdateJSON(res http.ResponseWriter, req *http.Request)
TopicsUpdateJSON responds to: PUT/PATCH /topics/:id. This will only be called when the user requested a JSON response.
func UsersCreate ¶
func UsersCreate(res http.ResponseWriter, req *http.Request)
UsersCreate responds to: POST /users. It expects the "name" and the "password" form values to be present. Moreover, only one user is allowed in this application.
Types ¶
type Topic ¶
type Topic struct { ID string `json:"id"` Name string `json:"name"` Contents string `json:"contents"` CreatedAt time.Time `db:"created_at" json:"created_at"` Markdown string `db:"-" json:"markdown"` }
Topic is my way to divide different "contexts" inside my To Do list. Moreover this type also has the "Markdown" attribute. This attribute does not match any column from the database, but it comes handy in the API layer.
func (*Topic) RenderMarkdown ¶
func (t *Topic) RenderMarkdown()
RenderMarkdown generates the Markdown code for the current contents of this topic.