Move SnApiToken check into sn.go
This commit is contained in:
parent
e69128b822
commit
2f7214e9a0
23
main.go
23
main.go
|
@ -1,28 +1,5 @@
|
||||||
package main
|
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() {
|
func main() {
|
||||||
stories := fetchTopStoriesFromHN()
|
stories := fetchTopStoriesFromHN()
|
||||||
filtered := filterByRelevanceForSN(&stories)
|
filtered := filterByRelevanceForSN(&stories)
|
||||||
|
|
19
sn.go
19
sn.go
|
@ -6,6 +6,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
"github.com/namsral/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GraphQLPayload struct {
|
type GraphQLPayload struct {
|
||||||
|
@ -25,6 +28,22 @@ type DupesResponse struct {
|
||||||
} `json:"data"`
|
} `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 {
|
func makeGraphQLRequest(body GraphQLPayload) *http.Response {
|
||||||
bodyJSON, err := json.Marshal(body)
|
bodyJSON, err := json.Marshal(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue