()
| 34 | } |
| 35 | |
| 36 | func (nq *NetQuery) prepare() error { |
| 37 | var err error |
| 38 | |
| 39 | nq.db = database.NewInterface(&database.Options{ |
| 40 | Local: true, |
| 41 | Internal: true, |
| 42 | }) |
| 43 | |
| 44 | // TODO: Open database in start() phase. |
| 45 | nq.Store, err = NewInMemory() |
| 46 | if err != nil { |
| 47 | return fmt.Errorf("failed to create in-memory database: %w", err) |
| 48 | } |
| 49 | |
| 50 | nq.mng, err = NewManager(nq.Store, "netquery/data/", runtime.DefaultRegistry) |
| 51 | if err != nil { |
| 52 | return fmt.Errorf("failed to create manager: %w", err) |
| 53 | } |
| 54 | |
| 55 | nq.feed = make(chan *network.Connection, 1000) |
| 56 | |
| 57 | queryHander := &QueryHandler{ |
| 58 | Database: nq.Store, |
| 59 | IsDevMode: config.Concurrent.GetAsBool(config.CfgDevModeKey, false), |
| 60 | } |
| 61 | |
| 62 | batchHander := &BatchQueryHandler{ |
| 63 | Database: nq.Store, |
| 64 | IsDevMode: config.Concurrent.GetAsBool(config.CfgDevModeKey, false), |
| 65 | } |
| 66 | |
| 67 | chartHandler := &ActiveChartHandler{ |
| 68 | Database: nq.Store, |
| 69 | } |
| 70 | |
| 71 | bwChartHandler := &BandwidthChartHandler{ |
| 72 | Database: nq.Store, |
| 73 | } |
| 74 | |
| 75 | if err := api.RegisterEndpoint(api.Endpoint{ |
| 76 | Name: "Query Connections", |
| 77 | Description: "Query the in-memory sqlite connection database.", |
| 78 | Path: "netquery/query", |
| 79 | MimeType: "application/json", |
| 80 | Read: api.PermitUser, // Needs read+write as the query is sent using POST data. |
| 81 | Write: api.PermitUser, // Needs read+write as the query is sent using POST data. |
| 82 | HandlerFunc: servertiming.Middleware(queryHander, nil).ServeHTTP, |
| 83 | }); err != nil { |
| 84 | return fmt.Errorf("failed to register API endpoint: %w", err) |
| 85 | } |
| 86 | |
| 87 | if err := api.RegisterEndpoint(api.Endpoint{ |
| 88 | Name: "Batch Query Connections", |
| 89 | Description: "Batch query the in-memory sqlite connection database.", |
| 90 | Path: "netquery/query/batch", |
| 91 | MimeType: "application/json", |
| 92 | Read: api.PermitUser, // Needs read+write as the query is sent using POST data. |
| 93 | Write: api.PermitUser, // Needs read+write as the query is sent using POST data. |
no test coverage detected