models

package
v0.0.0-...-1e04ee6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrAccessDenied

func ErrAccessDenied(err error) render.Renderer

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrNotFound

func ErrNotFound(err error) render.Renderer

func ErrUnathorized

func ErrUnathorized(err error) render.Renderer

func NewContactsResponse

func NewContactsResponse(contact *ent.Contact) render.Renderer

func NewContactsResponseList

func NewContactsResponseList(contactList []*ent.Contact) []render.Renderer

Types

type ContactPayload

type ContactPayload struct {
	Name    string `json:"name,omitempty"`
	Phone   string `json:"phone,omitempty"`
	Address string `json:"address,omitempty"`
}

func (*ContactPayload) Bind

func (c *ContactPayload) Bind(r *http.Request) error

type ContactResponsePayload

type ContactResponsePayload struct {
	ID      int    `json:"id"`
	Name    string `json:"name"`
	Phone   string `json:"phone"`
	Address string `json:"address"`
}

func (*ContactResponsePayload) Render

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

ErrResponse renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

type TokenPayloadResponse

type TokenPayloadResponse struct {
	Token string `json:"token"`
}

func (*TokenPayloadResponse) Render

type User

type User struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

func (*User) Bind

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

Bind on UserPayload will run after the unmarshalling is complete, its a good time to focus some post-processing after a decoding.

type UserPayload

type UserPayload struct {
	ID       int    `json:"id"`
	Username string `json:"username"`
}

func NewUserPayloadResponse

func NewUserPayloadResponse(user *ent.User) *UserPayload

func (*UserPayload) Render

func (u *UserPayload) 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