-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
67 lines (55 loc) · 1.62 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"encoding/json"
"fmt"
"net/http"
"time"
spinhttp "github.com/fermyon/spin/sdk/go/http"
"github.com/rajatjindal/goodfirstissue/pkg/cache/kvcache"
"github.com/rajatjindal/goodfirstissue/pkg/creds/kvcreds"
"github.com/rajatjindal/goodfirstissue/pkg/socials/bluesky"
"github.com/rajatjindal/goodfirstissue/pkg/socials/twitter"
"github.com/rajatjindal/goodfirstissue/pkg/webhook"
"github.com/sirupsen/logrus"
)
func init() {
spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) {
stime := time.Now()
stats := map[string]interface{}{}
defer func() {
stats["total"] = time.Since(stime)
stats["guid"] = r.Header.Get("X-GitHub-Delivery")
d, _ := json.Marshal(stats)
fmt.Println(string(d))
}()
fmt.Println("entering spin Handle func")
credsProvider := kvcreds.Provider()
client := spinhttp.NewClient()
twitterTime := time.Now()
twitter, err := twitter.NewClient(client, credsProvider)
if err != nil {
logrus.Fatal(err)
}
stats["creds:twitter"] = time.Since(twitterTime)
bskyTime := time.Now()
bluesky, err := bluesky.NewClient(client, credsProvider)
if err != nil {
logrus.Fatal(err)
}
stats["creds:bluesky"] = time.Since(bskyTime)
cacheProvider := kvcache.Provider(1*time.Minute, 2*time.Minute)
handler := webhook.NewHandler(cacheProvider, twitter, bluesky)
if r.URL.Path == "/cleanup-cache" {
err := cacheProvider.CleanupExpiredCache()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
return
}
handler.Handle(w, r)
})
}
func main() {}