Documentation
¶
Index ¶
- Constants
- func BasicAuthCheck(r *http.Request) error
- func NewError(errStr string) error
- func ReadRequestBody(r *http.Request, out interface{}) error
- func WriteErrorResp(w http.ResponseWriter, r *http.Request, statusCode int, err error)
- func WriteHTTPResp(w http.ResponseWriter, r *http.Request, responseCode int, response interface{})
- func WriteInfoResp(w http.ResponseWriter, r *http.Request, statusCode int, response string)
- func WriteWarnResp(w http.ResponseWriter, r *http.Request, statusCode int, response string)
- type ErrResponse
- type Error
- type Logger
- type Response
- type StringSlice
Constants ¶
const ( SuccessStatusCode = 200 CreatedStatusCode = 201 FoundStatusCode = 302 BadRequestStatusCode = 400 NotFoundStatusCode = 404 MethodNotAllowedStatusCode = 405 InternalServerErrorStatusCode = 500 SuccessStatus = "200 OK" CreatedStatus = "201 Created" FoundStatus = "302 Found" BadReqStatus = "400 Bad Request" NotFoundStatus = "404 Not Found" MethodNotAllowed = "405 Method Not Allowed" InternalServerErrorStatus = "500 Internal Server Error" JsonMarshalErrorStr = "JSON Marshal Error" JsonUnmarshalErrorStr = "JSON Unmarshal Error" ApiAuthErrorStr = "401 unauthorized. Please pass username and password to the API" )
Variables ¶
This section is empty.
Functions ¶
func BasicAuthCheck ¶
BasicAuthCheck check if basic authentication credentials are provided while making a http request The method return an error if something goes wrong
func ReadRequestBody ¶
ReadRequestBody reads request body in json format, unmarshal's the json writes the data into the address
func WriteErrorResp ¶
WriteErrResp writes an http error response and logs the outcome
func WriteHTTPResp ¶
func WriteHTTPResp(w http.ResponseWriter, r *http.Request, responseCode int, response interface{})
WriteHTTPResp writes an http response
func WriteInfoResp ¶
WriteInfoResp writes an http info response and logs the outcome
func WriteWarnResp ¶
WriteWarnResp writes an http warn response and logs the outcome
Types ¶
type ErrResponse ¶
type ErrResponse struct {
Error string `json:"error"`
}
ErrResponse represents an error response
type Logger ¶
Logger represents the output log message
func (Logger) EnableDebug ¶ added in v1.0.1
EnableDebug checks if the DEBUG_LOGS env variable is set to true
type Response ¶
type Response struct {
Message string `json:"message"`
}
Response represents a http response message
type StringSlice ¶
type StringSlice []string
func (StringSlice) EntryExists ¶
func (s StringSlice) EntryExists(entry string) bool
EntryExists checks if a string exists in a slice of string