-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
38 lines (32 loc) · 964 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"context"
"github.com/Golang-Coach/Scheduler/scheduler"
"github.com/Golang-Coach/Scheduler/services"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
"os"
"github.com/aws/aws-lambda-go/lambda"
"github.com/Golang-Coach/Scheduler/db"
)
func HandleRequest() {
backgroundContext := context.Background()
tokenService := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("github_token")},
)
tokenClient := oauth2.NewClient(backgroundContext, tokenService)
client := *github.NewClient(tokenClient)
githubApi := services.NewGithub(&client, client.Repositories, backgroundContext)
dataStore := db.Connect()
defer dataStore.Session.Close()
repositoriesStore := services.NewRepositoryStore(dataStore)
scheduler.Schedule(repositoriesStore, githubApi)
}
func main() {
environment := os.Getenv("environment")
if environment != "production" {
HandleRequest()
} else {
lambda.Start(HandleRequest)
}
}