added json keys to structs
This commit is contained in:
parent
5461bded96
commit
a1e06ee718
@ -0,0 +1,26 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
const endpoint = "https://diyhrt.market/api/listings"
|
||||||
|
|
||||||
|
func GetListings() []Listing {
|
||||||
|
apiKey := os.Getenv("API_KEY")
|
||||||
|
fmt.Println(apiKey)
|
||||||
|
|
||||||
|
// why put api key in url parameter
|
||||||
|
req, err := http.NewRequest("GET", endpoint+"?api_token="+apiKey, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(err.Error())
|
||||||
|
return []Listing{}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(req.Body.Read())
|
||||||
|
|
||||||
|
return []Listing{}
|
||||||
|
}
|
@ -1,41 +1,41 @@
|
|||||||
package backend
|
package backend
|
||||||
|
|
||||||
type ActiveIngredient struct {
|
type ActiveIngredient struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Ester string
|
Ester string `json:"ester"`
|
||||||
DisplayName string
|
DisplayName string `json:"display_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Product struct {
|
type Product struct {
|
||||||
Id int
|
Id int `json:"id"`
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Image string
|
Image string `json:"image"`
|
||||||
ActiveIngredient ActiveIngredient
|
ActiveIngredient ActiveIngredient `json:"active_ingredient"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Store struct {
|
type Store struct {
|
||||||
Id int
|
Id int `json:"id"`
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Url string
|
Url string `json:"url"`
|
||||||
Description string
|
Description string `json:"description"`
|
||||||
ShipsFromCountry string
|
ShipsFromCountry string `json:"ships_from_country"`
|
||||||
ShipsToCountry string
|
ShipsToCountry string `json:"ships_to_country"`
|
||||||
ServiceStatus string
|
ServiceStatus string `json:"service_status"`
|
||||||
ServiceStatusNotes string
|
ServiceStatusNotes string `json:"service_status_notes"`
|
||||||
PaymentMethods string
|
PaymentMethods string `json:"payment_methods"`
|
||||||
CategoryName string
|
CategoryName string `json:"category_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Listing struct {
|
type Listing struct {
|
||||||
Id int
|
Id int `json:"id"`
|
||||||
ProductName string
|
ProductName string `json:"product_name"`
|
||||||
StoreName string
|
StoreName string `json:"store_name"`
|
||||||
Price string
|
Price string `json:"price"`
|
||||||
PriceCurrency string
|
PriceCurrency string `json:"price_currency"`
|
||||||
State string
|
State string `json:"state"`
|
||||||
InStock bool
|
InStock bool `json:"in_stock"`
|
||||||
Url string
|
Url string `json:"url"`
|
||||||
PricingPerUnit string
|
PricingPerUnit string `json:"pricing_per_unit"`
|
||||||
Product Product
|
Product Product `json:"product"`
|
||||||
Store Store
|
Store Store `json:"store"`
|
||||||
}
|
}
|
||||||
|
10
main.go
10
main.go
@ -1,7 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"gitea.elara.ws/Hazel/transfem-startpage/backend"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("running transfem startpage")
|
fmt.Println("running transfem startpage")
|
||||||
|
|
||||||
|
for _, l := range backend.GetListings() {
|
||||||
|
fmt.Println(l)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user