当前位置: 首页>>代码示例>>Golang>>正文


Golang life.Life类代码示例

本文整理汇总了Golang中github.com/benbearchen/asuran/web/proxy/life.Life的典型用法代码示例。如果您正苦于以下问题:Golang Life类的具体用法?Golang Life怎么用?Golang Life使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Life类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Command

func (p *Proxy) Command(commands string, f *profile.Profile, v *life.Life) {
	commandLines := strings.Split(commands, "\n")
	for _, line := range commandLines {
		line = strings.TrimSpace(line)
		if len(line) <= 0 || line[0] == '#' {
			continue
		}

		c, rest := cmd.TakeFirstArg(line)
		switch c {
		case "restart":
			if v != nil {
				v.Restart()
			}
		case "clear":
			f.Clear()
		case "delay":
			f.CommandDelay(rest)
		case "proxy":
			f.CommandProxy(rest)
		case "delete":
			f.CommandDelete(rest)
		case "domain":
			f.CommandDomain(rest)
		case "url":
			f.CommandUrl(rest)
		default:
			if ip, domain, ok := parseIPDomain(c, rest); ok {
				f.CommandDomain("redirect " + domain + " " + ip)
				break
			}
		}
	}
}
开发者ID:BillSun,项目名称:asuran,代码行数:34,代码来源:cmd.go

示例2: writeHistory

func (p *Proxy) writeHistory(w http.ResponseWriter, profileIP string, f *life.Life) {
	t, err := template.ParseFiles("template/history.tmpl")
	list := formatHistoryEventDataList(f.HistoryEvents(), profileIP, f)
	err = t.Execute(w, historyData{profileIP, list})
	if err != nil {
		fmt.Fprintln(w, "内部错误:", err)
	}
}
开发者ID:clarelin,项目名称:asuran,代码行数:8,代码来源:html.go

示例3: formatHistoryEventDataList

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
}
开发者ID:BillSun,项目名称:asuran,代码行数:58,代码来源:html.go

示例4: saveContentToCache

func (p *Proxy) saveContentToCache(fullUrl string, f *life.Life, c *cache.UrlCache, needCache bool) {
	id := f.SaveContentToCache(c, needCache)

	info := "proxy " + fullUrl + " " + strconv.FormatUint(uint64(id), 10)
	if len(c.RangeInfo) > 0 {
		info += " " + c.RangeInfo
	}

	f.Log(info)
}
开发者ID:clarelin,项目名称:asuran,代码行数:10,代码来源:proxy.go

示例5: writeDNSHistory

func (p *Proxy) writeDNSHistory(w http.ResponseWriter, f *life.Life, targetIP string) {
	t, err := template.ParseFiles("template/dnshistory.tmpl")
	list := formatDNSHistoryEventDataList(f.HistoryEvents(), f, targetIP)
	targetInfo := ""
	if len(targetIP) == 0 {
		targetInfo = "DNS 服务"
	} else {
		targetInfo = targetIP + " DNS"
	}

	err = t.Execute(w, dnsHistoryData{targetInfo, list})
	if err != nil {
		fmt.Fprintln(w, "内部错误:", err)
	}
}
开发者ID:clarelin,项目名称:asuran,代码行数:15,代码来源:html.go


注:本文中的github.com/benbearchen/asuran/web/proxy/life.Life类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。