Hi,
I’m new to Go and currently writing a web service (using gingonic framework) that handles Vulnerability scans for network devices. This is the basic flow I intend to develop:
- POST sent to /api/v1/devicescan with payload {“device”: “ROUTER1”}
- Goroutine is created to launch a scan job and reports the scan result when finished
What I would like to achieve is to prevent API consumers from sending scans requests for a device that is already being scanned.
I’m thinking of 3 different potential solutions but would like some hints on which one would the most optimal:
-
Assign the devices being scanned in channel and before launching a scan job, read channel values. If the device requested to be scanned is read from channel, then abort the operation. I understand that reading from a channel is a blocking operation but using select with default clause allows non-blocking channel operations. https://gobyexample.com/non-blocking-channel-operations.
-
Use Postgres with a Temporary Table to hold current devices being scanned. Before launching a scan job, read the Temporary table rows to find out if the requested device is already being scanned. This would involve the overhead of having to launch DB queries before each scan job which may not be the best.
-
Using gingonic API to list the ongoing requests and their values. I haven’t found out yet whether gingonic has an API for this.
Thanks in advance.