本文整理汇总了Golang中github.com/benbearchen/asuran/profile.Profile类的典型用法代码示例。如果您正苦于以下问题:Golang Profile类的具体用法?Golang Profile怎么用?Golang Profile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Profile类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 "domain":
f.CommandDomain(rest)
case "url":
f.CommandUrl(rest)
case "host":
c, rest = cmd.TakeFirstArg(rest)
if ip, domain, ok := parseIPDomain(c, rest); ok {
f.CommandDomain(domain + " " + ip)
}
default:
if ip, domain, ok := parseIPDomain(c, rest); ok {
f.CommandDomain(domain + " " + ip)
}
}
}
}
开发者ID:clarelin,项目名称:asuran,代码行数:32,代码来源:cmd.go
示例2: 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
示例3: writeStores
func (p *Proxy) writeStores(w http.ResponseWriter, profileIP string, prof *profile.Profile) {
t, err := template.ParseFiles("template/stores.tmpl")
list := formatStoreListData(prof.ListStored(), profileIP)
err = t.Execute(w, storeListData{profileIP, list})
if err != nil {
fmt.Fprintln(w, "内部错误:", err)
}
}
开发者ID:clarelin,项目名称:asuran,代码行数:8,代码来源:html.go
示例4: 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
示例5: storeHistory
func (p *Proxy) storeHistory(profileIP, id string, prof *profile.Profile) (string, string) {
f := p.lives.OpenExists(profileIP)
if f == nil {
return "", ""
}
hID, err := strconv.ParseUint(id, 10, 32)
if err != nil {
return "", ""
}
h := f.LookHistoryByID(uint32(hID))
if h.Error == nil && len(h.Bytes) > 0 {
saveID := prof.StoreID(h.Bytes)
return h.Url, saveID
}
return "", ""
}
开发者ID:BillSun,项目名称:asuran,代码行数:19,代码来源:proxy.go
示例6: storeHistory
func (p *Proxy) storeHistory(profileIP, id string, prof *profile.Profile) (string, string) {
f := p.lives.OpenExists(profileIP)
if f == nil {
return "", ""
}
hID, err := strconv.ParseUint(id, 10, 32)
if err != nil {
return "", ""
}
h := f.LookHistoryByID(uint32(hID))
if h == nil {
return "", ""
}
content, err := h.Content()
if err == nil {
saveID := prof.StoreID(content)
return h.Url, saveID
}
return "", ""
}
开发者ID:clarelin,项目名称:asuran,代码行数:24,代码来源:proxy.go
示例7: 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
示例8: remoteProxyUrl
func (p *Proxy) remoteProxyUrl(remoteIP, target string, w http.ResponseWriter, r *http.Request) {
needCache := false
fullUrl := target
if len(r.URL.RawQuery) > 0 {
fullUrl += "?" + r.URL.RawQuery
}
requestUrl := fullUrl
requestR := r
contentSource := ""
var prof *profile.Profile
if !p.isSelfAddr(remoteIP) {
prof = p.profileOp.Open(remoteIP)
}
rangeInfo := cache.CheckRange(r)
f := p.lives.Open(remoteIP)
var u *life.UrlState
if f != nil {
u = f.OpenUrl(fullUrl)
}
var writeWrap io.Writer = nil
if p.urlOp != nil {
delay := p.urlOp.Delay(remoteIP, fullUrl)
//fmt.Println("url delay: " + delay.String())
switch delay.Act {
case profile.DelayActDelayEach:
if delay.Time > 0 {
// TODO: create request before sleep, more effective
d := delay.RandDuration(p.r)
time.Sleep(d)
f.Log("proxy " + fullUrl + " delay " + d.String())
}
break
case profile.DelayActDropUntil:
d := delay.RandDuration(p.r)
if u != nil && u.DropUntil(d) {
f.Log("proxy " + fullUrl + " drop " + d.String())
net.ResetResponse(w)
return
}
break
case profile.DelayActTimeout:
if delay.Time > 0 {
d := delay.RandDuration(p.r)
time.Sleep(d)
f.Log("proxy " + fullUrl + " timeout " + d.String())
} else {
f.Log("proxy " + fullUrl + " timeout")
}
net.ResetResponse(w)
return
break
}
act := p.urlOp.Action(remoteIP, fullUrl)
//fmt.Println("url act: " + act.String())
speed := p.urlOp.Speed(remoteIP, fullUrl)
bodyDelay := p.urlOp.BodyDelay(remoteIP, fullUrl)
switch act.Act {
case profile.UrlActCache:
needCache = true
case profile.UrlActStatus:
status := 502
if c, err := strconv.Atoi(act.ContentValue); err == nil {
status = c
}
w.WriteHeader(status)
f.Log("proxy " + fullUrl + " status " + strconv.Itoa(status))
return
case profile.UrlActMap:
requestUrl = act.ContentValue
requestR = nil
contentSource = "map " + act.ContentValue
case profile.UrlActRedirect:
http.Redirect(w, r, act.ContentValue, 302)
f.Log("proxy " + fullUrl + " redirect " + act.ContentValue)
return
case profile.UrlActRewritten:
fallthrough
case profile.UrlActRestore:
fallthrough
case profile.UrlActTcpWritten:
if p.rewriteUrl(fullUrl, w, r, rangeInfo, prof, f, act, speed, bodyDelay) {
return
}
}
switch bodyDelay.Act {
case profile.DelayActDelayEach:
fallthrough
case profile.DelayActTimeout:
if writeWrap == nil {
writeWrap = w
//.........这里部分代码省略.........
开发者ID:clarelin,项目名称:asuran,代码行数:101,代码来源:proxy.go
注:本文中的github.com/benbearchen/asuran/profile.Profile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论