package main import ( "net/http" "github.com/gin-gonic/gin" ) type status_response struct { Scanning_engine string `json:"scanning_engine"` Signature_count int `json:"signature_count"` Sanity_check bool `json:"sanity_check"` } type scan_response struct { Malware_detected bool `json:"malware_detected"` Malware_name string `json:"malware_name"` Engine status_response `json:"engine"` } func scan_api(c *gin.Context) { data, err := c.GetRawData() if err != nil { c.IndentedJSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } malware_type, err, sigCount := scan_data(data) malware_detected := true if malware_type == "" { malware_detected = false } response := scan_response{ Malware_detected: malware_detected, Malware_name: malware_type, Engine: status_response{ Signature_count: sigCount, Sanity_check: true, Scanning_engine: "clamav", }, } c.IndentedJSON(http.StatusOK, response) } func status_api(c *gin.Context) { scannerIsSane, sigCount := sanity_check() responseData := status_response{ Sanity_check: scannerIsSane, Signature_count: sigCount, Scanning_engine: "clamav", } c.IndentedJSON(http.StatusOK, responseData) } func start_api() { gin.SetMode(gin.ReleaseMode) router := gin.Default() router.POST("/scan", scan_api) router.GET("/status", status_api) router.Run(":8080") }