Use more vars
This commit is contained in:
parent
2f7214e9a0
commit
02a9e4e32f
12
hn.go
12
hn.go
|
@ -20,10 +20,20 @@ type Story struct {
|
||||||
Url string
|
Url string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
HackerNewsUrl string
|
||||||
|
HackerNewsFirebaseUrl string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
HackerNewsUrl = "https://news.ycombinator.com"
|
||||||
|
HackerNewsFirebaseUrl = "https://hacker-news.firebaseio.com/v0"
|
||||||
|
}
|
||||||
|
|
||||||
func fetchTopStoriesFromHN() []Story {
|
func fetchTopStoriesFromHN() []Story {
|
||||||
// API docs: https://github.com/HackerNews/API
|
// 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)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error fetching top stories:", err)
|
log.Fatal("Error fetching top stories:", err)
|
||||||
|
|
7
sn.go
7
sn.go
|
@ -29,10 +29,12 @@ type DupesResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
SnApiUrl string
|
||||||
SnApiToken string
|
SnApiToken string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
SnApiUrl = "https://stacker.news/api/graphql"
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error loading .env file")
|
log.Fatal("Error loading .env file")
|
||||||
|
@ -50,8 +52,7 @@ func makeGraphQLRequest(body GraphQLPayload) *http.Response {
|
||||||
log.Fatal("Error during json.Marshal:", err)
|
log.Fatal("Error during json.Marshal:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
url := "https://stacker.news/api/graphql"
|
req, err := http.NewRequest("POST", SnApiUrl, bytes.NewBuffer(bodyJSON))
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(bodyJSON))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -64,7 +65,7 @@ func makeGraphQLRequest(body GraphQLPayload) *http.Response {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("POST %s %d\n", url, resp.StatusCode)
|
log.Printf("POST %s %d\n", SnApiUrl, resp.StatusCode)
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue