-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmain.go
More file actions
70 lines (58 loc) · 1.79 KB
/
main.go
File metadata and controls
70 lines (58 loc) · 1.79 KB
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
package main
import (
"context"
"github.com/src-d/lookout"
"github.com/src-d/lookout/dummy"
"github.com/src-d/lookout/util/cli"
"github.com/src-d/lookout/util/grpchelper"
"google.golang.org/grpc"
"gopkg.in/src-d/go-log.v1"
)
var (
version = "local_build_1"
app = cli.New("dummy")
)
type ServeCommand struct {
cli.CommonOptions
Analyzer string `long:"analyzer" default:"ipv4://localhost:10302" env:"LOOKOUT_ANALYZER" description:"gRPC URL to bind the analyzer to"`
DataServer string `long:"data-server" default:"ipv4://localhost:10301" env:"LOOKOUT_DATA_SERVER" description:"gRPC URL of the data server"`
RequestUAST bool `long:"uast" env:"LOOKOUT_REQUEST_UAST" description:"analyzer will request UAST from the data server"`
RequestFilesPush bool `long:"files" env:"LOOKOUT_REQUEST_FILES" description:"on push events the analyzer will request files from HEAD, and return comments"`
}
func (c *ServeCommand) Execute(args []string) error {
var err error
c.DataServer, err = grpchelper.ToGoGrpcAddress(c.DataServer)
if err != nil {
return err
}
conn, err := grpchelper.DialContext(
context.Background(),
c.DataServer,
grpc.WithInsecure(),
grpc.WithDefaultCallOptions(grpc.FailFast(false)),
)
if err != nil {
return err
}
a := &dummy.Analyzer{
Version: version,
DataClient: lookout.NewDataClient(conn),
RequestUAST: c.RequestUAST,
RequestFilesPush: c.RequestFilesPush,
}
server := grpchelper.NewServer()
lookout.RegisterAnalyzerServer(server, a)
lis, err := grpchelper.Listen(c.Analyzer)
if err != nil {
return err
}
log.Infof("server has started on '%s'", c.Analyzer)
return server.Serve(lis)
}
func main() {
if _, err := app.AddCommand("serve", "", "",
&ServeCommand{}); err != nil {
panic(err)
}
app.RunMain()
}