helpers

package
v0.0.0-...-3cccc09 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package helpers provides various helper functions

Index

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

func CheckPasswordHash(password, hash string) bool

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

func CreateToken(authorId string) (string, error)

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

func GetAuthorIdFromHeader(req *http.Request) string

GetAuthorIdFromHeader returns the value of key "token" in the request's header

func HashPassword

func HashPassword(password string) (string, error)

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

func RangeIn

func RangeIn(low, hi int) int

RangeIn returns a random number between low and hi

func ShiftPath

func ShiftPath(p string) (head, tail string)

ShiftPath splits the URL path component into two segments where first segment is the portion before first slash and rest is second

Parameter: /this/is/a/url/

Result: this /is/a/url

Types

This section is empty.

Jump to

Keyboard shortcuts

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