func checkSearchExists(searchName string, groupId int) (*SearchObject, error) {
	var search *SearchObject
	getAllSearchesResp, err := apiOperation("GET", papertrailApiSearchesEndpoint, nil)
	if err != nil {
		return search, err
	}
	if getAllSearchesResp.StatusCode == 200 {
		var searches []SearchObject
		json.Unmarshal([]byte(getAllSearchesResp.Body), &searches)
		for _, item := range searches {
			if item.Name == searchName && item.Group.ID == groupId {
				search = NewSearchObject(item.ID, item.Name, item.Query, item.Group, item.Links)
				break
			}
		}
	}
	return search, nil
}
checkSearchExists checks if a search exists in papertrail specific group, returning the information
of this one in case it exists
package papertrail
import (
	"bytes"
	"encoding/json"
	"errors"
	"log"
	"strconv"
	"strings"
)
const papertrailApiSearchesEndpoint = papertrailApiBaseUrl + "searches.json"
func doPapertrailSearchNecessaryActions(searchName string, searchQuery string, groupId int,
	actionName string) (*Item, error) {
	var searchItem *Item
	searchObject, err := checkSearchExists(searchName, groupId)
	if err != nil {
		return nil, err
	}
	if searchObject != nil {
		log.Printf("Search with name %s exists with id %d\n", searchName, searchObject.ID)
		if ActionIsObtain(actionName) || ActionIsCreate(actionName) {
			return NewItem(searchObject.ID, "Search", searchName, false, false), nil
		} else if ActionIsDelete(actionName) {
			searchItem, err = deleteSearch(searchName, searchObject.ID)
			if err != nil {
				return nil, err
			}
		}
	} else {
		if ActionIsCreate(actionName) {
			searchItem, err = createSearch(searchName, searchQuery, groupId)
			if err != nil {
				return nil, err
			}
		} else {
			err := errors.New("Error: Search with name " + searchName + " doesn't exist")
			return nil, err
		}
	}
	return searchItem, nil
}
func createSearch(searchName string, searchQuery string, groupId int) (*Item, error) {
	papertrailSearchCreated, err := createPapertrailSearchOperation(searchName, searchQuery, groupId)
	if err != nil {
		return nil, err
	}
	return NewItem(papertrailSearchCreated.ID, "Search", searchName, true, false), nil
}
func deleteSearch(searchName string, searchId int) (*Item, error) {
	papertrailSearchDeleted, err := deletePapertrailSearchOperation(searchName, searchId)
	if err != nil {
		return nil, err
	}
	if *papertrailSearchDeleted {
		return NewItem(searchId, "Search", searchName, false, true), nil
	}
	return nil, errors.New("Error: Search with " + searchName + " doesn't exist")
}