-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (64 loc) · 1.58 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
68
69
70
71
package main
import (
"context"
"os"
"github.com/coder/flog"
"github.com/go-redis/redis/v8"
"github.com/samber/lo"
"github.com/spf13/cobra"
)
func main() {
var enrichers []string
cmd := &cobra.Command{
Use: "github-enricher",
Short: "Enrich GitHub data (https://github.com/ammario/github-enricher)",
Example: "github-enricher < input.csv > output.csv",
Run: func(cmd *cobra.Command, args []string) {
const (
RedisAddrEnv = "REDIS_ADDR"
RedisPasswordEnv = "REDIS_PASSWORD"
)
redisAddr, ok := os.LookupEnv(RedisAddrEnv)
if !ok {
flog.Fatal("%q must be provided", RedisAddrEnv)
}
redisPassword := os.Getenv(RedisPasswordEnv)
rd := redis.NewClient(&redis.Options{
Addr: redisAddr,
Password: redisPassword,
})
err := rd.Ping(context.Background()).Err()
if err != nil {
flog.Fatal("redis ping: %+v", err)
}
allEnrichers, err := setupEnrichers()
if err != nil {
flog.Fatal("setup enrichers: %+v", err)
}
e := engine{
Log: flog.New(),
Enrichers: lo.Map(enrichers, func(name string, _ int) enricher {
enricher, _ := lo.Find(allEnrichers, func(e enricher) bool {
return e.FieldName == name
})
return cachedEnricher(flog.New().WithPrefix("cache: "), rd, enricher)
}),
}
err = e.Run(os.Stdout, os.Stdin)
if err != nil {
flog.Fatal("%+v", err)
}
},
}
cmd.Flags().StringSliceVarP(
&enrichers,
"enrichers",
"e",
[]string{"email", "name", "gender"},
"The list of enabled enrichers",
)
err := cmd.Execute()
if err != nil {
flog.Fatal(err.Error())
}
}