-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (46 loc) · 1.09 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
package main
import (
"go-ip-proxy/config"
"go-ip-proxy/logger"
"go-ip-proxy/parser"
"go-ip-proxy/server"
"go-ip-proxy/storage"
"go-ip-proxy/verifier"
"go.uber.org/zap"
"sync"
"time"
)
func main() {
logger.Config(config.Config().Log.Path, config.Config().Log.Level, true)
configs := parser.NewConfig("./proxyWebsiteConfig.json")
// Load database.
database, err := storage.NewStorage()
defer database.Close()
if err != nil {
logger.Error("db error", zap.Error(err))
panic(err)
}
// Start server
go server.NewServer(database)
// Verify storage every 5min.
verifyTicker := time.NewTicker(time.Minute * 5)
go func() {
for range verifyTicker.C {
verifier.VerifyAndDelete(database)
logger.Debug("verify database.")
}
}()
run(database, configs)
}
func run(storage storage.Storage, configs *parser.Configs) {
for {
var wg sync.WaitGroup
for _, configuration := range configs.Configs {
items := parser.NewSelector(configuration)
verifier.VerifyAndSave(items, storage)
}
wg.Wait()
logger.Debug("finish once, sleep 10 Second.")
time.Sleep(time.Second * 10)
}
}