Skip to content
Snippets Groups Projects
Select Git revision
  • a1f4e02380abefb4cbf98a9655a526f259e95d8f
  • master default protected
  • Eilerts_branch
  • Karins_branch
  • Mads_branch
5 results

Constants.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    url-intelligence.go 4.66 KiB
    package api
    
    import (
    	logging "dcsg2900-threattotal/logs"
    	"dcsg2900-threattotal/utils"
    	"encoding/json"
    	"fmt"
    	"net/http"
    	"strings"
    	"sync"
    
    	"github.com/gin-gonic/gin"
    )
    
    func UrlIntelligence(c *gin.Context) {
    	url := c.Query("url")
    
    	var completeInt bool
    	var URLint []byte
    
    	//var URLint utils.APIresponseResult
    	value, err := utils.Conn.Do("GET", "url:"+url)
    	if value == nil {
    		if err != nil {
    			fmt.Println("Error:" + err.Error())
    			logging.Logerror(err, "Error in cache lookup - Url-intelligence")
    
    		}
    		fmt.Println("No Cache hit")
    
    		URLint, err, completeInt = urlSearch(url)
    		if err != nil {
    			http.Error(c.Writer, "Failed retrieving api data.", http.StatusInternalServerError)
    			return
    		}
    
    		// Add the data to the redis backend.
    		if completeInt {
    			response, err := utils.Conn.Do("SETEX", "url:"+url, utils.CacheDurationUrl, URLint)
    			if err != nil {
    				fmt.Println("Error adding data to redis:" + err.Error())
    				logging.Logerror(err, "Error addding data to redis - Url-intelligence:")
    			}
    
    			// Print the response to adding the data (should be "OK")
    			fmt.Println("Bool is true")
    			fmt.Println(response)
    		}
    		//fmt.Println("WHERE IS MY CONTENT 2", responseData2)
    		// Cache hit
    	} else {
    		fmt.Println("Cache hit")
    		responseBytes, err := json.Marshal(value)
    		if err != nil {
    			fmt.Println("Error handling redis response:" + err.Error())
    			logging.Logerror(err, "Error handling redis response - Url-intelligence:")
    			http.Error(c.Writer, "Failed retrieving api data.", http.StatusInternalServerError)
    			return
    			// Maybe do another call to delete the key from the database?
    		}
    		/**
    		//var checkData utils.ResultFrontendResponse
    		err = json.Unmarshal(responseBytes, &checkdata)
    		if err!=nil {
    			fmt.Println(string(checkData))
    		}
    		fmt.Println(string(checkData))
    		*/
    		err = json.Unmarshal(responseBytes, &URLint)
    		if err != nil {