rest

package
v0.0.0-...-a03fb21 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewUserListResponse

func NewUserListResponse(users []*model.User) []render.Renderer

func SessionRouter

func SessionRouter(env *env.Env) chi.Router

Session endpoint router

func UserRouter

func UserRouter(env *env.Env) chi.Router

User endpoint router

Types

type EmailLoginRequest

type EmailLoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

func (*EmailLoginRequest) Bind

func (er *EmailLoginRequest) Bind(r *http.Request) error

type LoginResponse

type LoginResponse struct {
	Token string `json:"token,omitempty"`
}

func (*LoginResponse) Render

func (lr *LoginResponse) Render(w http.ResponseWriter, r *http.Request) error

type RESTSessionHandler

type RESTSessionHandler struct {
	SService service.SessionService
	UService service.UserService
	Env      *env.Env
}

func (*RESTSessionHandler) Delete

func (handler *RESTSessionHandler) Delete(w http.ResponseWriter, r *http.Request)

func (*RESTSessionHandler) Store

func (handler *RESTSessionHandler) Store(w http.ResponseWriter, r *http.Request)

TODO: Move login and token issuing logic out of controller

type RESTUserHandler

type RESTUserHandler struct {
	UService service.UserService
	Env      *env.Env
}

func (*RESTUserHandler) Delete

func (handler *RESTUserHandler) Delete(w http.ResponseWriter, r *http.Request)

func (*RESTUserHandler) GetAll

func (handler *RESTUserHandler) GetAll(w http.ResponseWriter, r *http.Request)

func (*RESTUserHandler) GetByID

func (handler *RESTUserHandler) GetByID(w http.ResponseWriter, r *http.Request)

func (*RESTUserHandler) Store

func (handler *RESTUserHandler) Store(w http.ResponseWriter, r *http.Request)

func (*RESTUserHandler) Update

func (handler *RESTUserHandler) Update(w http.ResponseWriter, r *http.Request)

type UserListResponse

type UserListResponse []*UserResponse

type UserRequest

type UserRequest struct {
	*model.User
}

UserRequest is the request payload for User data model.

NOTE: It's good practice to have well defined request and response payloads so you can manage the specific inputs and outputs for clients, and also gives you the opportunity to transform data on input or output, for example on request, we'd like to protect certain fields and on output perhaps we'd like to include a computed field based on other values that aren't in the data model. Also, check out this awesome blog post on struct composition: http://attilaolah.eu/2014/09/10/json-and-struct-composition-in-go/

func (*UserRequest) Bind

func (u *UserRequest) Bind(r *http.Request) error

type UserResponse

type UserResponse struct {
	*model.User

	// Lets omit password in the response
	Password omit `json:"password,omitempty"`

	// We add an additional field to the response here.. such as this
	// elapsed computed property
	Elapsed int64 `json:"elapsed"`
}

UserResponse is the response payload for the User data model. See NOTE above in UserRequest as well.

In the UserResponse object, first a Render() is called on itself, then the next field, and so on, all the way down the tree. Render is called in top-down order, like a http handler middleware chain.

func NewUserResponse

func NewUserResponse(user *model.User) *UserResponse

func (*UserResponse) Render

func (ur *UserResponse) Render(w http.ResponseWriter, r *http.Request) error

Jump to

Keyboard shortcuts

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