Compare commits
	
		
			3 Commits
		
	
	
		
			7a3c3dd2c0
			...
			b0b4cc4eb3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					b0b4cc4eb3 | ||
| 
						 | 
					a1e06ee718 | ||
| 
						 | 
					5461bded96 | 
							
								
								
									
										30
									
								
								backend/diyhrt_fetch.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								backend/diyhrt_fetch.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
package backend
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const endpoint = "https://diyhrt.market/api/listings"
 | 
			
		||||
 | 
			
		||||
func GetListings() ([]Listing, error) {
 | 
			
		||||
	apiKey := os.Getenv("API_KEY")
 | 
			
		||||
	fmt.Println(apiKey)
 | 
			
		||||
 | 
			
		||||
	// why put api key in url parameter
 | 
			
		||||
	resp, err := http.NewRequest("GET", endpoint+"?api_token="+apiKey, nil)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Print(err.Error())
 | 
			
		||||
		return []Listing{}, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var listings []Listing
 | 
			
		||||
	if err := json.NewDecoder(resp.Body).Decode(&listings); err != nil {
 | 
			
		||||
		return []Listing{}, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return listings, nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										41
									
								
								backend/diyhrt_models.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								backend/diyhrt_models.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
package backend
 | 
			
		||||
 | 
			
		||||
type ActiveIngredient struct {
 | 
			
		||||
	Name        string `json:"name"`
 | 
			
		||||
	Ester       string `json:"ester"`
 | 
			
		||||
	DisplayName string `json:"display_name"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Product struct {
 | 
			
		||||
	Id               int              `json:"id"`
 | 
			
		||||
	Name             string           `json:"name"`
 | 
			
		||||
	Image            string           `json:"image"`
 | 
			
		||||
	ActiveIngredient ActiveIngredient `json:"active_ingredient"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Store struct {
 | 
			
		||||
	Id                 int    `json:"id"`
 | 
			
		||||
	Name               string `json:"name"`
 | 
			
		||||
	Url                string `json:"url"`
 | 
			
		||||
	Description        string `json:"description"`
 | 
			
		||||
	ShipsFromCountry   string `json:"ships_from_country"`
 | 
			
		||||
	ShipsToCountry     string `json:"ships_to_country"`
 | 
			
		||||
	ServiceStatus      string `json:"service_status"`
 | 
			
		||||
	ServiceStatusNotes string `json:"service_status_notes"`
 | 
			
		||||
	PaymentMethods     string `json:"payment_methods"`
 | 
			
		||||
	CategoryName       string `json:"category_name"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Listing struct {
 | 
			
		||||
	Id             int     `json:"id"`
 | 
			
		||||
	ProductName    string  `json:"product_name"`
 | 
			
		||||
	StoreName      string  `json:"store_name"`
 | 
			
		||||
	Price          string  `json:"price"`
 | 
			
		||||
	PriceCurrency  string  `json:"price_currency"`
 | 
			
		||||
	State          string  `json:"state"`
 | 
			
		||||
	InStock        bool    `json:"in_stock"`
 | 
			
		||||
	Url            string  `json:"url"`
 | 
			
		||||
	PricingPerUnit string  `json:"pricing_per_unit"`
 | 
			
		||||
	Product        Product `json:"product"`
 | 
			
		||||
	Store          Store   `json:"store"`
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user