Example #1
0
func formatHistoryEventDataList(events []*life.HistoryEvent, client string, f *life.Life) []historyEventData {
	list := make([]historyEventData, 0, len(events))
	even := true
	for _, e := range events {
		d := historyEventData{}
		d.OPs = make([]opData, 0)
		d.Client = client

		even = !even
		d.Even = even
		d.Time = e.Time.Format("2006-01-02 15:04:05")

		s := strings.Split(e.String, " ")
		if len(s) >= 3 && s[0] == "domain" {
			domain := s[2]
			d.Domain = "域名 " + s[1] + " " + domain
			d.OPs = append(d.OPs, opData{"代理域名", "domain/redirect", domain, client})
			if len(s) >= 4 {
				d.DomainIP = s[3]
			}
		} else if len(s) >= 3 && s[0] == "proxy" {
			url := s[1]
			d.URL = url
			if len(s) >= 4 {
				d.URL += " " + s[3]
			}

			d.URLID = s[2]
			if id, err := strconv.ParseInt(d.URLID, 10, 32); err == nil {
				h := f.LookHistoryByID(uint32(id))
				if h != nil {
					status := h.Method
					if h.ResponseCode >= 0 {
						status += " " + strconv.Itoa(h.ResponseCode)
					} else {
						status += " 出错"
					}

					d.HttpStatus = status
				}
			}

			if strings.HasPrefix(url, "http://") {
				d.URLBody = url[7:]
			} else {
				d.URLBody = url
			}

			d.OPs = append(d.OPs, opData{"缓存", "url/store", d.URLID, client})
		} else {
			d.EventString = e.String
		}

		list = append(list, d)
	}

	return list
}