removed wrong stuff

This commit is contained in:
Hazel Noack
2025-07-10 13:05:38 +02:00
parent 46cc8b7989
commit 2e1d7d5564
7 changed files with 21 additions and 132 deletions

View File

@@ -2,8 +2,7 @@ package diyhrt
import (
"encoding/json"
"fmt"
"io"
"errors"
"net/http"
"os"
"time"
@@ -14,7 +13,7 @@ const endpoint = "https://diyhrt.market/api/listings"
func GetListings() ([]Listing, error) {
apiKey := os.Getenv("API_KEY")
if apiKey == "" {
return nil, fmt.Errorf("API_KEY environment variable not set")
return nil, errors.New("API_KEY environment variable not set")
}
// Create HTTP client
@@ -23,26 +22,25 @@ func GetListings() ([]Listing, error) {
// Create request
req, err := http.NewRequest("GET", endpoint+"?api_token="+apiKey, nil)
if err != nil {
return nil, fmt.Errorf("creating request failed: %w", err)
return nil, err
}
// Send request
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
return nil, err
}
defer resp.Body.Close()
// Check status code
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("unexpected status code %d: %s", resp.StatusCode, string(body))
return nil, errors.New("unexpected status code")
}
// Decode response
var listings []Listing
if err := json.NewDecoder(resp.Body).Decode(&listings); err != nil {
return nil, fmt.Errorf("decoding failed: %w", err)
return nil, err
}
return listings, nil

View File

@@ -1,6 +1,9 @@
package diyhrt
import "slices"
import (
"fmt"
"slices"
)
type StoreFilter struct{
Limit int
@@ -34,5 +37,6 @@ func (f StoreFilter) Filter (stores []Store) []Store {
result = append(result, s)
}
fmt.Println(len(result))
return result
}