set token earlier

This commit is contained in:
Aaron Bieber 2023-06-07 11:58:14 -06:00
parent d6c59aef3a
commit dbcf63674c
No known key found for this signature in database
2 changed files with 17 additions and 10 deletions

24
main.go
View File

@ -113,6 +113,20 @@ func main() {
r.Use(middleware.Logger)
r.Use(OwnerCtx)
ghToken := os.Getenv("GH_AUTH_TOKEN")
if *tokenFile != "" && ghToken == "" {
tfBytes, err := os.ReadFile(*tokenFile)
if err != nil {
log.Fatal("can't read token file: ", err)
}
ghToken = string(tfBytes)
}
if ghToken == "" {
log.Fatal("can't operate without GH_AUTH_TOKEN")
}
var liveServer http.Handler
if *dev {
liveServer = http.FileServer(http.Dir("./assets"))
@ -149,16 +163,6 @@ func main() {
r.Get("/{linkID:[0-9]+}", iconGET)
})
ghToken := os.Getenv("GH_AUTH_TOKEN")
if *tokenFile != "" && ghToken == "" {
tfBytes, err := os.ReadFile(*tokenFile)
if err != nil {
log.Fatal("can't read token file: ", err)
}
ghToken = string(tfBytes)
}
go func() {
for {
if dbExists && ghToken != "" {

View File

@ -115,6 +115,9 @@ func (w WatchResults) GetLimits() *RateLimit {
}
func UpdateWatches(ghToken string) (*WatchResults, error) {
if ghToken == "" {
return nil, fmt.Errorf("invalid github token")
}
ctx := context.Background()
w := WatchResults{}