Documentation ¶
Index ¶
- func NewUserListResponse(users []*model.User) []render.Renderer
- func SessionRouter(env *env.Env) chi.Router
- func UserRouter(env *env.Env) chi.Router
- type EmailLoginRequest
- type LoginResponse
- type RESTSessionHandler
- type RESTUserHandler
- func (handler *RESTUserHandler) Delete(w http.ResponseWriter, r *http.Request)
- func (handler *RESTUserHandler) GetAll(w http.ResponseWriter, r *http.Request)
- func (handler *RESTUserHandler) GetByID(w http.ResponseWriter, r *http.Request)
- func (handler *RESTUserHandler) Store(w http.ResponseWriter, r *http.Request)
- func (handler *RESTUserHandler) Update(w http.ResponseWriter, r *http.Request)
- type UserListResponse
- type UserRequest
- type UserResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EmailLoginRequest ¶
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 ¶
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/
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