Set static vars outside of init

This commit is contained in:
ekzyis 2023-04-25 02:30:04 +02:00
parent e0866c8470
commit 85fa5997dd
2 changed files with 5 additions and 13 deletions

12
hn.go
View File

@ -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

6
sn.go
View File

@ -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")