Read API key from environment

This commit is contained in:
ekzyis 2024-04-07 03:28:05 +02:00
parent 5ba3c56b75
commit ffc5baa79c
1 changed files with 4 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"os"
) )
type ClientOptions struct { type ClientOptions struct {
@ -23,6 +24,9 @@ func NewClient(options *ClientOptions) *Client {
if options.BaseUrl == "" { if options.BaseUrl == "" {
options.BaseUrl = "https://stacker.news" options.BaseUrl = "https://stacker.news"
} }
if options.ApiKey == "" {
options.ApiKey = os.Getenv("SN_API_KEY")
}
return &Client{ return &Client{
BaseUrl: options.BaseUrl, BaseUrl: options.BaseUrl,