Documentation ¶
Index ¶
- Variables
- func AdminRouter(ctx context.Context) chi.Router
- func ErrInternalServer(err error) render.Renderer
- func ErrInvalidRequest(err error) render.Renderer
- func ErrRender(err error) render.Renderer
- func GenerateDocs(r chi.Router, docs string)
- func IsAlphaNumeric(s string) bool
- func IsLower(s string) bool
- func LoginRouter(ctx context.Context) http.Handler
- func PirgsRouter(ctx context.Context) http.Handler
- func StartsWithLetter(s string) bool
- func UsersRouter(ctx context.Context) http.Handler
- func ValidatePirgName(name string) error
- type ApiResponse
- type ErrResponse
- type PirgHandler
- func (h *PirgHandler) CreatePirg(w http.ResponseWriter, r *http.Request)
- func (h *PirgHandler) DeletePirg(w http.ResponseWriter, r *http.Request)
- func (h *PirgHandler) GetAllPirgs(w http.ResponseWriter, r *http.Request)
- func (h *PirgHandler) GetPirg(w http.ResponseWriter, r *http.Request)
- func (h *PirgHandler) PirgCtx(next http.Handler) http.Handler
- func (h *PirgHandler) UpdatePirg(w http.ResponseWriter, r *http.Request)
- type PirgRequest
- type PirgResponse
- type PirgStub
- type UserHandler
- func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) DeleteUser(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) GetAllUsers(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) GetUser(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) UpdateUser(w http.ResponseWriter, r *http.Request)
- func (h *UserHandler) UserCtx(next http.Handler) http.Handler
- type UserRequest
- type UserResponse
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}
Functions ¶
func AdminRouter ¶
A completely separate router for administrator routes
func ErrInternalServer ¶
func ErrInvalidRequest ¶
func GenerateDocs ¶
func GenerateDocs(r chi.Router, docs string)
func StartsWithLetter ¶
func ValidatePirgName ¶
Types ¶
type ApiResponse ¶
func (*ApiResponse) Render ¶
func (u *ApiResponse) Render(w http.ResponseWriter, r *http.Request) error
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 PirgHandler ¶
type PirgHandler struct {
// contains filtered or unexported fields
}
func (*PirgHandler) CreatePirg ¶
func (h *PirgHandler) CreatePirg(w http.ResponseWriter, r *http.Request)
CreatePirg creates a new Pirg
func (*PirgHandler) DeletePirg ¶
func (h *PirgHandler) DeletePirg(w http.ResponseWriter, r *http.Request)
DeletePirg deletes a Pirg
func (*PirgHandler) GetAllPirgs ¶
func (h *PirgHandler) GetAllPirgs(w http.ResponseWriter, r *http.Request)
GetAllPirgs returns all existing Pirgs
func (*PirgHandler) GetPirg ¶
func (h *PirgHandler) GetPirg(w http.ResponseWriter, r *http.Request)
GetPirg returns the Pirg by the ID in the URL
func (*PirgHandler) PirgCtx ¶
func (h *PirgHandler) PirgCtx(next http.Handler) http.Handler
PirgCtx middleware is used to load a Pirg object from /Pirgs/{Pirgname} requests and then attach it to the request context. In case of failure the request is aborted and a 404 error response is sent to the client.
func (*PirgHandler) UpdatePirg ¶
func (h *PirgHandler) UpdatePirg(w http.ResponseWriter, r *http.Request)
UpdatePirg updates a Pirg
type PirgRequest ¶
type PirgResponse ¶
type PirgResponse struct { Id int `json:"id"` Name string `json:"name"` OwnerId int `json:"owner_id"` AdminIds []int `json:"admin_ids"` UserIds []int `json:"user_ids"` CreatedAt time.Time `json:"created_at"` ModifiedAt time.Time `json:"modified_at"` }
func (*PirgResponse) Render ¶
func (u *PirgResponse) Render(w http.ResponseWriter, r *http.Request) error
type UserHandler ¶
type UserHandler struct {
// contains filtered or unexported fields
}
func (*UserHandler) CreateUser ¶
func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request)
CreateUser creates a new user
func (*UserHandler) DeleteUser ¶
func (h *UserHandler) DeleteUser(w http.ResponseWriter, r *http.Request)
DeleteUser deletes a user
func (*UserHandler) GetAllUsers ¶
func (h *UserHandler) GetAllUsers(w http.ResponseWriter, r *http.Request)
GetAllUsers returns all existing users
func (*UserHandler) GetUser ¶
func (h *UserHandler) GetUser(w http.ResponseWriter, r *http.Request)
GetUser returns the user in the request context
func (*UserHandler) UpdateUser ¶
func (h *UserHandler) UpdateUser(w http.ResponseWriter, r *http.Request)
UpdateUser updates a user
func (*UserHandler) UserCtx ¶
func (h *UserHandler) UserCtx(next http.Handler) http.Handler
UserCtx middleware is used to load a User object from /users/{username} requests and then attach it to the request context. In case of failure the request is aborted and a 404 error response is sent to the client.
type UserRequest ¶
type UserResponse ¶
type UserResponse struct { Id int `json:"id"` Username string `json:"username"` Email string `json:"email"` FirstName string `json:"firstname"` LastName string `json:"lastname"` CreatedAt time.Time `json:"created_at"` ModifiedAt time.Time `json:"modified_at"` }
func (*UserResponse) Render ¶
func (u *UserResponse) Render(w http.ResponseWriter, r *http.Request) error