-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (40 loc) · 1.18 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
package main
import (
"gofr.dev/pkg/gofr"
"test-service/githubmetrics"
)
func main() {
app := gofr.New()
// Push gofr repo-related metrics to see its progress over time.
_ = app.NewGauge("gofr_repo_stargazers", "number of stargazers of gofr repo")
_ = app.NewGauge("gofr_repo_subscribers", "number of subscribers of gofr repo")
_ = app.NewGauge("gofr_repo_forks", "number of forks of gofr repo")
app.GET("", func(ctx *gofr.Context) (interface{}, error) {
return "Hello GoFr!", nil
})
app.GET("/test", func(ctx *gofr.Context) (interface{}, error) {
var resp string
err := ctx.Redis.Get(ctx, "test").Scan(&resp)
if err != nil {
return nil, err
}
return resp, nil
})
app.GET("/count", func(ctx *gofr.Context) (interface{}, error) {
var count int
row := ctx.DB().QueryRowContext(ctx, "SELECT count(*) FROM user")
if err := row.Scan(&count); err != nil {
return nil, err
}
return count, nil
})
gCron := gofr.NewCron()
svc := githubmetrics.New(app)
go func() {
err := gCron.AddJob("*/5 * * * *", svc.Process)
if err != nil {
app.Logger.Errorf("error while creating cron job for github stargazers. Error: %v", err.Error())
}
}()
app.Start()
}