app

package
v0.0.0-...-d25348d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2018 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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 CloseDB

func CloseDB()

CloseDB close the global DB connection.

func Count

func Count(name string) int64

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

func EnvOrElse(name, value string) string

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

func Exists(name, id string) bool

Exists returns true if there is a row in the given table that matches the given id. It returns false otherwise.

func InitDB

func InitDB()

InitDB initializes the global DB connection.

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 Logout

func Logout(res http.ResponseWriter, req *http.Request)

Logout the current user.

func RootIndex

func RootIndex(res http.ResponseWriter, req *http.Request)

RootIndex renders the root page. It has three different options:

  1. If there's no user, it renders the "Create user" page.
  2. If the current user is not logged in, it render the "Login" page.
  3. 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.

type TopicData

type TopicData struct {
	lib.ViewData

	Current *Topic

	Topics []Topic
}

TopicData is the data that will be assed to the renderShow function in order to render the main page.

type User

type User struct {
	ID           string    `json:"token"`
	Name         string    `json:"-"`
	PasswordHash string    `json:"-" db:"password_hash"`
	CreatedAt    time.Time `json:"-" db:"created_at"`
}

User contains a user in this application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL