diff --git a/hn.go b/hn.go index e2a2f52..db84907 100644 --- a/hn.go +++ b/hn.go @@ -20,10 +20,20 @@ type Story struct { Url string } +var ( + HackerNewsUrl string + HackerNewsFirebaseUrl string +) + +func init() { + HackerNewsUrl = "https://news.ycombinator.com" + HackerNewsFirebaseUrl = "https://hacker-news.firebaseio.com/v0" +} + func fetchTopStoriesFromHN() []Story { // API docs: https://github.com/HackerNews/API - url := "https://hacker-news.firebaseio.com/v0/topstories.json" + url := fmt.Sprintf("%s/topstories.json", HackerNewsFirebaseUrl) resp, err := http.Get(url) if err != nil { log.Fatal("Error fetching top stories:", err) diff --git a/sn.go b/sn.go index c392fe5..48013a6 100644 --- a/sn.go +++ b/sn.go @@ -29,10 +29,12 @@ type DupesResponse struct { } var ( + SnApiUrl string SnApiToken string ) func init() { + SnApiUrl = "https://stacker.news/api/graphql" err := godotenv.Load() if err != nil { log.Fatal("Error loading .env file") @@ -50,8 +52,7 @@ func makeGraphQLRequest(body GraphQLPayload) *http.Response { log.Fatal("Error during json.Marshal:", err) } - url := "https://stacker.news/api/graphql" - req, err := http.NewRequest("POST", url, bytes.NewBuffer(bodyJSON)) + req, err := http.NewRequest("POST", SnApiUrl, bytes.NewBuffer(bodyJSON)) if err != nil { panic(err) } @@ -64,7 +65,7 @@ func makeGraphQLRequest(body GraphQLPayload) *http.Response { panic(err) } - log.Printf("POST %s %d\n", url, resp.StatusCode) + log.Printf("POST %s %d\n", SnApiUrl, resp.StatusCode) return resp }