Documentation ¶
Overview ¶
Package helpers provides various helper functions
Index ¶
- func BadRequestResponse(res http.ResponseWriter, message string)
- func CheckPasswordHash(password, hash string) bool
- func CreatePostWithoutAuthor(content types.AuthorPosts) interface{}
- func CreateToken(authorId string) (string, error)
- func ForbiddenResponse(res http.ResponseWriter)
- func GetAuthorIdFromHeader(req *http.Request) string
- func HashPassword(password string) (string, error)
- func InternalServerErrorResponse(res http.ResponseWriter, message string)
- func MethodNotAllowedResponse(res http.ResponseWriter)
- func NotFoundResponse(res http.ResponseWriter)
- func RangeIn(low, hi int) int
- func ShiftPath(p string) (head, tail string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequestResponse ¶
func BadRequestResponse(res http.ResponseWriter, message string)
BadRequestResponse returns a JSON response indicating that some unexpected error occurred
func CheckPasswordHash ¶
CheckPasswordHash checks whether hash can be decrypted as password
func CreatePostWithoutAuthor ¶
func CreatePostWithoutAuthor(content types.AuthorPosts) interface{}
CreatePostWithoutAuthor removes the Author field from the array of Post
func CreateToken ¶
CreateToken creates a JSON web token storing authorId that expires after 24 hours
func ForbiddenResponse ¶
func ForbiddenResponse(res http.ResponseWriter)
ForbiddenResponse returns a JSON response indicating token provided was invalid or authorId in the token didn't match with the postId provided.
Example - Session expired or post's author and logged in author mismatch
func GetAuthorIdFromHeader ¶
GetAuthorIdFromHeader returns the value of key "token" in the request's header
func HashPassword ¶
HashPassword encrypts a string
func InternalServerErrorResponse ¶
func InternalServerErrorResponse(res http.ResponseWriter, message string)
InternalServerError returns a JSON response indicating that some unexpected error occurred
func MethodNotAllowedResponse ¶
func MethodNotAllowedResponse(res http.ResponseWriter)
MethodNotAllowedResponse returns a JSON response indicating requested URL cannot be queried with the given method type
Example - Doing a POST on a GET only URL
func NotFoundResponse ¶
func NotFoundResponse(res http.ResponseWriter)
NotFoundResponse returns a JSON response indicating requested URL could not be found
Types ¶
This section is empty.