-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
58 lines (48 loc) · 1.36 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
// Copyright (c) Liam Stanley <[email protected]>. All rights reserved. Use of
// this source code is governed by the MIT license that can be found in
// the LICENSE file.
package main
import (
"context"
"github.com/apex/log"
"github.com/lrstanley/chix"
"github.com/lrstanley/clix"
"github.com/lrstanley/geoip/internal/dns"
"github.com/lrstanley/geoip/internal/lookup"
"github.com/lrstanley/geoip/internal/models"
)
// Should be automatically added by goreleaser.
var (
version = "master"
commit = "master"
date = "unknown"
)
var (
logger log.Interface
cli = &clix.CLI[models.Flags]{
Links: clix.GithubLinks("github.com/lrstanley/geoip", "master", "https://liam.sh"),
VersionInfo: &clix.VersionInfo[models.Flags]{
Version: version,
Commit: commit,
Date: date,
},
}
lookupSvc *lookup.Service
)
func main() {
cli.Parse()
logger = cli.Logger
ctx := log.NewContext(context.Background(), logger)
resolver := dns.NewResolver(cli.Flags.DNS)
lookupSvc = lookup.NewService(ctx, logger, cli.Flags.DB, resolver)
geoIPUpdater := lookup.NewUpdater(cli.Flags.DB, logger, lookupSvc, models.DatabaseGeoIP)
asnUpdater := lookup.NewUpdater(cli.Flags.DB, logger, lookupSvc, models.DatabaseASN)
if err := chix.RunCtx(
ctx,
httpServer(ctx),
geoIPUpdater.Start,
asnUpdater.Start,
); err != nil {
logger.WithError(err).Fatal("shutting down")
}
}