use custom Getenv with fallback

This commit is contained in:
pluja 2024-02-05 07:39:13 +01:00
parent 038ad49ec7
commit 7e259b7cb4

View File

@ -7,12 +7,13 @@ import (
"math/rand" "math/rand"
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"os"
"regexp" "regexp"
"strings" "strings"
"time" "time"
"golang.org/x/net/html" "golang.org/x/net/html"
"pluja.dev/kycnot.me/utils"
) )
type ScraperResponse struct { type ScraperResponse struct {
@ -24,10 +25,7 @@ type ScraperResponse struct {
func GetBody(url string) (string, error) { func GetBody(url string) (string, error) {
// Send a GET request to os.Getenv("SCRAPER_API_URL")/scrap?url=url // Send a GET request to os.Getenv("SCRAPER_API_URL")/scrap?url=url
// Unmarshal the response and return the HTML content // Unmarshal the response and return the HTML content
scraper_api := os.Getenv("SCRAPER_API_URL") scraper_api := utils.Getenv("SCRAPER_API_URL", "http://localhost:3011")
if scraper_api == "" {
scraper_api = "http://localhost:3011"
}
// Request the HTML content // Request the HTML content
resp, err := http.Get(fmt.Sprintf("%v/scrap?url=%v", scraper_api, url)) resp, err := http.Get(fmt.Sprintf("%v/scrap?url=%v", scraper_api, url))