/
proxy.go
98 lines (89 loc) · 2.3 KB
/
proxy.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/m-mizutani/minerva/pkg/api"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
type proxyArguments struct {
addr string
port int
}
func proxyCommand(args *arguments) *cli.Command {
var proxyArgs proxyArguments
var apiArgs api.MinervaHandler
return &cli.Command{
Name: "proxy",
Usage: "minerva API proxy server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "addr",
Aliases: []string{"a"},
Value: "127.0.0.1",
Usage: "Bind address",
Destination: &proxyArgs.addr,
},
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Value: 10080,
Usage: "Bind port number",
Destination: &proxyArgs.port,
},
&cli.StringFlag{
Name: "dbname",
Aliases: []string{"d"},
Usage: "Athena DB name",
Destination: &apiArgs.DatabaseName,
EnvVars: []string{"DB_NAME"},
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Output S3 path such as s3://my-bucket/out",
Destination: &apiArgs.OutputPath,
EnvVars: []string{"S3_OUTPUT"},
},
&cli.StringFlag{
Name: "region",
Aliases: []string{"r"},
Usage: "AWS region",
Destination: &apiArgs.Region,
EnvVars: []string{"REGION"},
},
&cli.StringFlag{
Name: "search-table",
Aliases: []string{"s"},
Usage: "Search DynamoDB table name",
Destination: &apiArgs.MetaTableName,
EnvVars: []string{"SEARCH_TABLE_NAME"},
},
// Optional parameters
&cli.StringFlag{
Name: "index-table",
Usage: "Index table name",
Value: "indices",
Destination: &apiArgs.IndexTableName,
},
&cli.StringFlag{
Name: "message-table",
Usage: "message table name",
Value: "messages",
Destination: &apiArgs.MessageTableName,
},
},
Action: func(c *cli.Context) error {
logger.WithFields(logrus.Fields{
"args": args,
"proxyArgs": proxyArgs,
"apiArgs": apiArgs,
}).Info("Start API server")
r := gin.Default()
v1 := r.Group("/api/v1")
api.SetupRoute(v1, &apiArgs)
bindAddr := fmt.Sprintf("%s:%d", proxyArgs.addr, proxyArgs.port)
return r.Run(bindAddr)
},
}
}