Documentation ¶
Index ¶
- func CheckPasswordHash(password, hash string) bool
- func GetAPIKey(headers http.Header) (string, error)
- func GetAccessToken(headers http.Header) (string, error)
- func HashPassword(password string) (string, error)
- func ParseDate(dateStr string) (time.Time, error)
- func RSSFeedScrapper(db *database.Queries, concurrency int, timeBetweenRequest time.Duration)
- func RespondWithError(w http.ResponseWriter, status int, msg string)
- func RespondWithJSON(w http.ResponseWriter, status int, payload interface{})
- type RSSFeed
- type RSSItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckPasswordHash ¶
func HashPassword ¶
func RSSFeedScrapper ¶
func RespondWithError ¶
func RespondWithError(w http.ResponseWriter, status int, msg string)
RespondWithError sends a JSON response with an error message and the specified status code.
Parameters:
- w: The http.ResponseWriter to send the response to.
- status: The HTTP status code to set in the response. If the status code is 500 or higher, the error message will be logged as a server error.
- msg: The error message to include in the response body.
The function creates a JSON payload containing the error message and sends it using the RespondWithJSON function. If the status code indicates a server error (status >= 499), the error message is logged.
func RespondWithJSON ¶
func RespondWithJSON(w http.ResponseWriter, status int, payload interface{})
RespondWithJSON sends a JSON response with the specified status code and payload.
Parameters:
- w: The http.ResponseWriter to send the response to.
- status: The HTTP status code to set in the response.
- payload: The data to be marshaled into JSON and sent in the response body.
The function attempts to marshal the provided payload into a JSON format. If successful, it sets the "Content-Type" header to "application/json", writes the status code, and sends the JSON response. If JSON marshalling fails, an error is logged, and an HTTP 500 (Internal Server Error) response is sent back to the client.