used api key from config file with fallback to env

This commit is contained in:
Hazel Noack 2025-07-15 11:44:33 +02:00
parent 1e7bbc6e16
commit e627d02d08
3 changed files with 4 additions and 6 deletions

View File

@ -4,16 +4,14 @@ import (
"encoding/json"
"errors"
"net/http"
"os"
"time"
)
const endpoint = "https://diyhrt.market/api/listings"
func GetListings() ([]Listing, error) {
apiKey := os.Getenv("API_KEY")
func GetListings(apiKey string) ([]Listing, error) {
if apiKey == "" {
return nil, errors.New("API_KEY environment variable not set")
return nil, errors.New("API_KEY key not set. Set it as env or in DiyHrt.ApiKey")
}
// Create HTTP client

View File

@ -21,7 +21,7 @@ var CurrentConfig = rendering.NewConfig()
func FetchDiyHrt() error {
fmt.Println("Fetch DiyHrt Marketplaces...")
l, err := diyhrt.GetListings()
l, err := diyhrt.GetListings(CurrentConfig.DiyHrt.ApiKey)
if err != nil {
return err
}

View File

@ -1 +1 @@
exit status 1
exit status 1exit status 1