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
|
||||
|
||||
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)
|
||||
|
|
19
sn.go
19
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 {
|
||||
|
|
Loading…
Reference in New Issue