package main

import (
	"fmt"
	"go.uber.org/zap"
	"jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
	"net/http"
	"sort"
	"time"
)

func convertToTime(value interface{}) (time.Time, error) {
	switch v := value.(type) {
	case int64:
		return time.Unix(v, 0), nil
	case float64:
		return time.Unix(int64(v), 0), nil
	default:
		return time.Time{}, fmt.Errorf("unsupported type: %T", v)
	}
}

//IsInStringArray 判断数组中是否存在字符串
func IsInStringArray(str string, arr []string) bool {
	// 先对字符串数组进行排序
	sort.Strings(arr)
	// 使用二分查找算法查找字符串
	pos := sort.SearchStrings(arr, str)
	// 如果找到了则返回 true，否则返回 false
	return pos < len(arr) && arr[pos] == str
}

//SendMail 发送邮件
func SendMail(title, content string) {
	url := fmt.Sprintf("%s?to=%s&title=%s&body=%s", GF.Email.Api, GF.Email.To, title, content)
	fmt.Println("url=>", url)
	res, err := http.Get(url)
	if err != nil {
		log.Info("SendMail", zap.Any("err", err))
	} else {
		log.Info("SendMail", zap.Any("res", res))
	}
}
