| |
| package websocket |
|
|
| import ( |
| "net/http" |
|
|
| "github.com/gin-gonic/gin" |
| ) |
|
|
| const ( |
| |
| WSMsgTypeLog = "log" |
| |
| WSMsgTypeScanResult = "result" |
| |
| WSMsgTypeProcessInfo = "processing" |
| |
| WSMsgTypeReportInfo = "report" |
| |
| WSMsgTypeScanRet = "scan_ret" |
| ) |
|
|
| const ( |
| WSLogLevelInfo = "info" |
| WSLogLevelDebug = "debug" |
| WSLogLevelError = "error" |
| ) |
|
|
| |
| type ScanRequest struct { |
| ScanType string `json:"scan_type"` |
| Target []string `json:"target,omitempty"` |
| Headers map[string]string `json:"headers,omitempty"` |
| Lang string `json:"lang,omitempty"` |
| } |
|
|
| |
| type Response struct { |
| Status int `json:"status"` |
| Message string `json:"message"` |
| Data interface{} `json:"data"` |
| } |
|
|
| |
| type WSMessage struct { |
| Type string `json:"type"` |
| Content interface{} `json:"content"` |
| } |
|
|
| |
| type ReportInfo struct { |
| SecScore int `json:"sec_score"` |
| HighRisk int `json:"high_risk"` |
| MiddleRisk int `json:"middle_risk"` |
| LowRisk int `json:"low_risk"` |
| } |
|
|
| |
| type ScanRet struct { |
| Status int `json:"status"` |
| Msg string `json:"msg"` |
| } |
|
|
| |
| type Log struct { |
| Message string `json:"message"` |
| Level string `json:"level"` |
| } |
|
|
| func SuccessResponse(c *gin.Context, message interface{}) { |
| c.JSON(http.StatusOK, gin.H{"status": 0, "message": message}) |
| } |
|
|
| func ErrorResponse(c *gin.Context, message interface{}) { |
| c.JSON(http.StatusOK, gin.H{"status": 1, "message": message}) |
| } |
|
|
| func ErrorResponseWithStatus(c *gin.Context, message interface{}, status int) { |
| c.JSON(http.StatusOK, gin.H{"status": status, "message": message}) |
| } |
|
|