From 85fa5997dd851075703140e5cc7ccd113f32c8b2 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 25 Apr 2023 02:30:04 +0200 Subject: [PATCH] Set static vars outside of init --- hn.go | 12 +++--------- sn.go | 6 ++---- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/hn.go b/hn.go index 2259b01..3e2f961 100644 --- a/hn.go +++ b/hn.go @@ -22,16 +22,10 @@ type Story struct { } var ( - HackerNewsUrl string - HackerNewsFirebaseUrl string - HackerNewsLinkRegexp *regexp.Regexp -) - -func init() { - HackerNewsUrl = "https://news.ycombinator.com" + HackerNewsUrl = "https://news.ycombinator.com" HackerNewsFirebaseUrl = "https://hacker-news.firebaseio.com/v0" - HackerNewsLinkRegexp = regexp.MustCompile(`(?:https?:\/\/)?news\.ycombinator\.com\/item\?id=([0-9]+)`) -} + HackerNewsLinkRegexp = regexp.MustCompile(`(?:https?:\/\/)?news\.ycombinator\.com\/item\?id=([0-9]+)`) +) func FetchHackerNewsTopStories() []Story { // API docs: https://github.com/HackerNews/API diff --git a/sn.go b/sn.go index d360a3a..d485c1f 100644 --- a/sn.go +++ b/sn.go @@ -80,14 +80,12 @@ type ItemsResponse struct { } var ( - StackerNewsUrl string - SnApiUrl string + StackerNewsUrl = "https://stacker.news" + SnApiUrl = "https://stacker.news/api/graphql" SnAuthCookie string ) func init() { - StackerNewsUrl = "https://stacker.news" - SnApiUrl = "https://stacker.news/api/graphql" err := godotenv.Load() if err != nil { log.Fatal("Error loading .env file")