used api key from config file with fallback to env
This commit is contained in:
parent
1e7bbc6e16
commit
e627d02d08
@ -4,16 +4,14 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const endpoint = "https://diyhrt.market/api/listings"
|
const endpoint = "https://diyhrt.market/api/listings"
|
||||||
|
|
||||||
func GetListings() ([]Listing, error) {
|
func GetListings(apiKey string) ([]Listing, error) {
|
||||||
apiKey := os.Getenv("API_KEY")
|
|
||||||
if apiKey == "" {
|
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
|
// Create HTTP client
|
||||||
|
2
main.go
2
main.go
@ -21,7 +21,7 @@ var CurrentConfig = rendering.NewConfig()
|
|||||||
func FetchDiyHrt() error {
|
func FetchDiyHrt() error {
|
||||||
fmt.Println("Fetch DiyHrt Marketplaces...")
|
fmt.Println("Fetch DiyHrt Marketplaces...")
|
||||||
|
|
||||||
l, err := diyhrt.GetListings()
|
l, err := diyhrt.GetListings(CurrentConfig.DiyHrt.ApiKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
exit status 1
|
exit status 1exit status 1
|
Loading…
x
Reference in New Issue
Block a user