From 2f7214e9a08adfef9fd0b5403695dae0011d7e38 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sun, 16 Apr 2023 19:43:48 +0200 Subject: [PATCH] Move SnApiToken check into sn.go --- main.go | 23 ----------------------- sn.go | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index 22c6460..365ccca 100644 --- a/main.go +++ b/main.go @@ -1,28 +1,5 @@ package main -import ( - "log" - - "github.com/joho/godotenv" - "github.com/namsral/flag" -) - -var ( - SnApiToken string -) - -func init() { - err := godotenv.Load() - if err != nil { - log.Fatal("Error loading .env file") - } - flag.StringVar(&SnApiToken, "NEXT_AUTH_CSRF_TOKEN", "", "Token required for authorizing requests to stacker.news/api/graphql") - flag.Parse() - if SnApiToken == "" { - log.Fatal("NEXT_AUTH_CSRF_TOKEN not set") - } -} - func main() { stories := fetchTopStoriesFromHN() filtered := filterByRelevanceForSN(&stories) diff --git a/sn.go b/sn.go index 6498dcc..c392fe5 100644 --- a/sn.go +++ b/sn.go @@ -6,6 +6,9 @@ import ( "fmt" "log" "net/http" + + "github.com/joho/godotenv" + "github.com/namsral/flag" ) type GraphQLPayload struct { @@ -25,6 +28,22 @@ type DupesResponse struct { } `json:"data"` } +var ( + SnApiToken string +) + +func init() { + err := godotenv.Load() + if err != nil { + log.Fatal("Error loading .env file") + } + flag.StringVar(&SnApiToken, "NEXT_AUTH_CSRF_TOKEN", "", "Token required for authorizing requests to stacker.news/api/graphql") + flag.Parse() + if SnApiToken == "" { + log.Fatal("NEXT_AUTH_CSRF_TOKEN not set") + } +} + func makeGraphQLRequest(body GraphQLPayload) *http.Response { bodyJSON, err := json.Marshal(body) if err != nil {