File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 22
22
Action : startAPI ,
23
23
Flags : []cli.Flag {
24
24
& apiDBFlag ,
25
+ & apiListenAddrFlag ,
25
26
& autovacuumFlag ,
26
27
& busyTimeoutFlag ,
27
28
& crawlerDBFlag ,
@@ -70,7 +71,8 @@ func startAPI(ctx *cli.Context) error {
70
71
go dropDeamon (& wg , nodeDB , ctx .Duration (dropNodesTimeFlag .Name ))
71
72
72
73
// Start the API deamon
73
- apiDeamon := api .New (nodeDB )
74
+ apiAddress := ctx .String (apiListenAddrFlag .Name )
75
+ apiDeamon := api .New (apiAddress , nodeDB )
74
76
go apiDeamon .HandleRequests (& wg )
75
77
wg .Wait ()
76
78
Original file line number Diff line number Diff line change @@ -14,17 +14,24 @@ import (
14
14
)
15
15
16
16
type Api struct {
17
- db * sql.DB
18
- cache * lru.Cache
17
+ address string
18
+ cache * lru.Cache
19
+ db * sql.DB
19
20
}
20
21
21
- func New (sdb * sql.DB ) * Api {
22
+ func New (address string , sdb * sql.DB ) * Api {
22
23
cache , err := lru .New (256 )
23
24
if err != nil {
24
25
return nil
25
26
}
26
- api := & Api {db : sdb , cache : cache }
27
+
28
+ api := & Api {
29
+ address : address ,
30
+ cache : cache ,
31
+ db : sdb ,
32
+ }
27
33
go api .dropCacheLoop ()
34
+
28
35
return api
29
36
}
30
37
@@ -47,8 +54,8 @@ func (a *Api) HandleRequests(wg *sync.WaitGroup) {
47
54
router .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) { w .Write ([]byte ("Hello" )) })
48
55
router .HandleFunc ("/v1/dashboard" , a .handleDashboard ).Queries ("filter" , "{filter}" )
49
56
router .HandleFunc ("/v1/dashboard" , a .handleDashboard )
50
- fmt .Println ("Start serving on port 10000" )
51
- http .ListenAndServe (":10000" , router )
57
+ fmt .Println ("Starting API on:" , a . address )
58
+ http .ListenAndServe (a . address , router )
52
59
}
53
60
54
61
type client struct {
You can’t perform that action at this time.
0 commit comments