Compare commits
No commits in common. "b0b4cc4eb35400523d72686615d37c3c0aa3d282" and "7a3c3dd2c0c82a5790490daaca2d2a73898eb223" have entirely different histories.
b0b4cc4eb3
...
7a3c3dd2c0
@ -1,30 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
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"`
|
|
||||||
}
|
|
11
main.go
11
main.go
@ -1,16 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"gitea.elara.ws/Hazel/transfem-startpage/backend"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("running transfem startpage")
|
fmt.Println("running transfem startpage")
|
||||||
|
|
||||||
listings, _ := backend.GetListings()
|
|
||||||
for _, l := range listings {
|
|
||||||
fmt.Println(l)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user