utils

package
v0.0.0-...-252d32f Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func GetAPIKey

func GetAPIKey(headers http.Header) (string, error)

func GetAccessToken

func GetAccessToken(headers http.Header) (string, error)

func HashPassword

func HashPassword(password string) (string, error)

func ParseDate

func ParseDate(dateStr string) (time.Time, error)

func RSSFeedScrapper

func RSSFeedScrapper(
	db *database.Queries,
	concurrency int,
	timeBetweenRequest time.Duration,
)

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.

Types

type RSSFeed

type RSSFeed struct {
	Channel struct {
		Title       string    `xml:"title"`
		Link        string    `xml:"link"`
		Description string    `xml:"description"`
		Language    string    `xml:"language"`
		Item        []RSSItem `xml:"item"`
	} `xml:"channel"`
}

type RSSItem

type RSSItem struct {
	Title       string `xml:"title"`
	Link        string `xml:"link"`
	Description string `xml:"description"`
	PubDate     string `xml:"pubDate"`
}

Jump to

Keyboard shortcuts

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