-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (39 loc) · 1.24 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
package main
import (
"log"
"github.com/cosiner/flag"
)
// Arguments defines the available app arguments
type Arguments struct {
Listen string `names:"--listen" env:"SCRAPER_Listen" usage:"Service listen address." default:":8080"`
Workers uint8 `names:"--workers" env:"SCRAPER_Workers" usage:"Number of serving workers." default:"2"`
Timeout uint64 `names:"--timeout" env:"SCRAPER_Timeout" usage:"Maximum time (in milliseconds) to wait for a worker." default:"1000"`
MetricsListen string `names:"--metrics" env:"SCRAPER_MetricsListen" usage:"Metrics listen address." default:":9095"`
}
// Service contains the Metrics logic and the Scraper logic
type Service struct {
metrics *Metrics
scraper *Scraper
}
// StartService generates and start a Service
func StartService(args Arguments) (*Service) {
m, err := NewMetrics("/metrics", args.MetricsListen)
if err != nil {
log.Fatal(err)
}
s, err := m.NewScraper("/", args.Listen, args.Workers, args.Timeout)
if err != nil {
log.Fatal(err)
}
svc := new(Service)
svc.metrics = m
svc.scraper = s
return svc
}
func main() {
var args Arguments
flag.Commandline.ParseStruct(&args)
service := StartService(args)
defer service.metrics.Close()
log.Fatal(service.scraper.Wait())
}