當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Profile.Restore方法代碼示例

本文整理匯總了Golang中github.com/benbearchen/asuran/profile.Profile.Restore方法的典型用法代碼示例。如果您正苦於以下問題:Golang Profile.Restore方法的具體用法?Golang Profile.Restore怎麽用?Golang Profile.Restore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/benbearchen/asuran/profile.Profile的用法示例。


在下文中一共展示了Profile.Restore方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: rewriteUrl

func (p *Proxy) rewriteUrl(target string, w http.ResponseWriter, r *http.Request, rangeInfo string, prof *profile.Profile, f *life.Life, act profile.UrlProxyAction) bool {
	var content []byte = nil
	contentSource := ""
	switch act.Act {
	case profile.UrlActRewritten:
		u, err := url.QueryUnescape(act.ContentValue)
		if err != nil {
			return false
		}

		content = []byte(u)
		contentSource = "rewrite"
	case profile.UrlActRestore:
		content = prof.Restore(act.ContentValue)
		if content == nil {
			return false
		}
	default:
		return false
	}

	start := time.Now()
	w.Write(content)
	c := cache.NewUrlCache(target, r, nil, nil, contentSource, content, rangeInfo, start, time.Now(), nil)
	c.ResponseCode = 200
	if f != nil {
		p.saveContentToCache(target, f, c, false)
	}

	return true
}
開發者ID:BillSun,項目名稱:asuran,代碼行數:31,代碼來源:proxy.go

示例2: formatEditStoreData

func formatEditStoreData(profileIP string, prof *profile.Profile, id string) editStoreData {
	encodedContent := ""
	if len(id) > 0 {
		c := prof.Restore(id)
		if len(c) > 0 {
			encodedContent = strings.Replace(url.QueryEscape(string(c)), "+", "%20", -1)
		}
	}

	return editStoreData{profileIP, id, encodedContent}
}
開發者ID:clarelin,項目名稱:asuran,代碼行數:11,代碼來源:html.go

示例3: rewriteUrl

func (p *Proxy) rewriteUrl(target string, w http.ResponseWriter, r *http.Request, rangeInfo string, prof *profile.Profile, f *life.Life, act profile.UrlProxyAction, speed profile.SpeedAction, bodyDelay profile.DelayAction) bool {
	var content []byte = nil
	contentSource := ""
	switch act.Act {
	case profile.UrlActRewritten:
		fallthrough
	case profile.UrlActTcpWritten:
		u, err := url.QueryUnescape(act.ContentValue)
		if err != nil {
			return false
		}

		content = []byte(u)
		if act.Act == profile.UrlActRewritten {
			contentSource = "rewrite"
		} else if act.Act == profile.UrlActTcpWritten {
			contentSource = "tcpwrite"
		}
	case profile.UrlActRestore:
		content = prof.Restore(act.ContentValue)
		if content == nil {
			return false
		}
	default:
		return false
	}

	if act.Act != profile.UrlActTcpWritten {
		p.procHeader(w.Header(), prof.SettingStringDef(target, "content-type", "default"))
	}

	var writeWrapper func(w io.Writer) io.Writer = nil
	switch bodyDelay.Act {
	case profile.DelayActDelayEach:
		fallthrough
	case profile.DelayActTimeout:
		writeWrapper = func(w io.Writer) io.Writer {
			return newDelayWriter(bodyDelay, w, p.r)
		}
	}

	switch speed.Act {
	case profile.SpeedActConstant:
		if writeWrapper != nil {
			wrap := writeWrapper
			writeWrapper = func(w io.Writer) io.Writer {
				return newSpeedWriter(speed, wrap(w))
			}
		} else {
			writeWrapper = func(w io.Writer) io.Writer {
				return newSpeedWriter(speed, w)
			}
		}
	}

	start := time.Now()
	if act.Act == profile.UrlActTcpWritten {
		net.TcpWriteHttp(w, writeWrapper, content)
	} else {
		if writeWrapper != nil {
			writeWrapper(w).Write(content)
		} else {
			w.Write(content)
		}
	}

	c := cache.NewUrlCache(target, r, nil, nil, contentSource, content, rangeInfo, start, time.Now(), nil)
	if act.Act == profile.UrlActTcpWritten {
		c.ResponseCode = 599
	} else {
		c.ResponseCode = 200
	}
	if f != nil {
		p.saveContentToCache(target, f, c, false)
	}

	return true
}
開發者ID:clarelin,項目名稱:asuran,代碼行數:78,代碼來源:proxy.go


注:本文中的github.com/benbearchen/asuran/profile.Profile.Restore方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。