本文整理汇总了Golang中github.com/phuslu/glog.V函数的典型用法代码示例。如果您正苦于以下问题:Golang V函数的具体用法?Golang V怎么用?Golang V使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了V函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Request
func (f *Filter) Request(ctx context.Context, req *http.Request) (context.Context, *http.Request, error) {
if req.Method != http.MethodGet || strings.Contains(req.URL.RawQuery, "range=") {
return ctx, req, nil
}
if r := req.Header.Get("Range"); r == "" {
switch {
case f.SiteMatcher.Match(req.Host):
req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", 0, f.MaxSize))
glog.V(2).Infof("AUTORANGE Sites rule matched, add %s for\"%s\"", req.Header.Get("Range"), req.URL.String())
ctx = filters.WithBool(ctx, "autorange.site", true)
default:
glog.V(3).Infof("AUTORANGE ignore preserved empty range for %#v", req.URL)
}
} else {
ctx = filters.WithBool(ctx, "autorange.default", true)
parts := strings.Split(r, "=")
switch parts[0] {
case "bytes":
parts1 := strings.Split(parts[1], "-")
if start, err := strconv.Atoi(parts1[0]); err == nil {
if end, err := strconv.Atoi(parts1[1]); err != nil || end-start > f.MaxSize {
req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", start, start+f.MaxSize))
glog.V(2).Infof("AUTORANGE Default rule matched, change %s to %s for\"%s\"", r, req.Header.Get("Range"), req.URL.String())
}
}
default:
glog.Warningf("AUTORANGE Default rule matched, but cannot support %#v range for \"%s\"", r, req.URL.String())
}
}
return ctx, req, nil
}
示例2: RoundTrip
func (f *Filter) RoundTrip(ctx context.Context, req *http.Request) (context.Context, *http.Response, error) {
if f.SiteFiltersEnabled {
if f1, ok := f.SiteFiltersRules.Lookup(req.Host); ok {
glog.V(2).Infof("%s \"AUTOPROXY SiteFilters %s %s %s\" with %T", req.RemoteAddr, req.Method, req.URL.String(), req.Proto, f1)
return f1.(filters.RoundTripFilter).RoundTrip(ctx, req)
}
}
if f.RegionFiltersEnabled {
//TODO
}
if req.URL.Host == "" && req.RequestURI[0] == '/' && f.IndexFilesEnabled {
if _, ok := f.IndexFiles[req.URL.Path[1:]]; ok || req.URL.Path == "/" {
if f.GFWListEnabled && strings.HasSuffix(req.URL.Path, ".pac") {
glog.V(2).Infof("%s \"AUTOPROXY ProxyPac %s %s %s\" - -", req.RemoteAddr, req.Method, req.RequestURI, req.Proto)
return f.ProxyPacRoundTrip(ctx, req)
} else {
glog.V(2).Infof("%s \"AUTOPROXY IndexFiles %s %s %s\" - -", req.RemoteAddr, req.Method, req.RequestURI, req.Proto)
return f.IndexFilesRoundTrip(ctx, req)
}
}
}
return ctx, nil, nil
}
示例3: RoundTrip
func (f *Filter) RoundTrip(ctx context.Context, req *http.Request) (context.Context, *http.Response, error) {
switch req.Method {
case "CONNECT":
glog.V(2).Infof("%s \"DIRECT %s %s %s\" - -", req.RemoteAddr, req.Method, req.Host, req.Proto)
rconn, err := f.transport.Dial("tcp", req.Host)
if err != nil {
return ctx, nil, err
}
rw := filters.GetResponseWriter(ctx)
hijacker, ok := rw.(http.Hijacker)
if !ok {
return ctx, nil, fmt.Errorf("http.ResponseWriter(%#v) does not implments http.Hijacker", rw)
}
flusher, ok := rw.(http.Flusher)
if !ok {
return ctx, nil, fmt.Errorf("http.ResponseWriter(%#v) does not implments http.Flusher", rw)
}
rw.WriteHeader(http.StatusOK)
flusher.Flush()
lconn, _, err := hijacker.Hijack()
if err != nil {
return ctx, nil, fmt.Errorf("%#v.Hijack() error: %v", hijacker, err)
}
defer lconn.Close()
go helpers.IoCopy(rconn, lconn)
helpers.IoCopy(lconn, rconn)
filters.SetHijacked(ctx, true)
return ctx, nil, nil
default:
helpers.FixRequestURL(req)
resp, err := f.transport.RoundTrip(req)
if err != nil {
glog.Errorf("%s \"DIRECT %s %s %s\" error: %s", req.RemoteAddr, req.Method, req.URL.String(), req.Proto, err)
data := err.Error()
resp = &http.Response{
StatusCode: http.StatusBadGateway,
Header: http.Header{},
Request: req,
Close: true,
ContentLength: int64(len(data)),
Body: ioutil.NopCloser(bytes.NewReader([]byte(data))),
}
err = nil
} else {
if req.RemoteAddr != "" {
glog.V(2).Infof("%s \"DIRECT %s %s %s\" %d %s", req.RemoteAddr, req.Method, req.URL.String(), req.Proto, resp.StatusCode, resp.Header.Get("Content-Length"))
}
}
return ctx, resp, err
}
}
示例4: RoundTrip
func (f *Filter) RoundTrip(ctx context.Context, req *http.Request) (context.Context, *http.Response, error) {
if ip, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
if _, ok := f.WhiteList[ip]; ok {
return ctx, nil, nil
}
}
if auth := filters.String(ctx, authHeader); auth != "" {
if _, ok := f.ByPassHeaders.Get(auth); ok {
glog.V(3).Infof("auth filter hit bypass cache %#v", auth)
return ctx, nil, nil
}
parts := strings.SplitN(auth, " ", 2)
if len(parts) == 2 {
switch parts[0] {
case "Basic":
if userpass, err := base64.StdEncoding.DecodeString(parts[1]); err == nil {
parts := strings.Split(string(userpass), ":")
user := parts[0]
pass := parts[1]
pass1, ok := f.Basic[user]
if ok && pass == pass1 {
f.ByPassHeaders.Set(auth, struct{}{}, time.Now().Add(time.Hour))
return ctx, nil, nil
}
}
default:
glog.Errorf("Unrecognized auth type: %#v", parts[0])
break
}
}
}
glog.V(1).Infof("UnAuthenticated URL %v from %#v", req.URL.String(), req.RemoteAddr)
noAuthResponse := &http.Response{
Status: "407 Proxy Authentication Required",
StatusCode: http.StatusProxyAuthRequired,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: http.Header{},
Request: req,
Close: true,
ContentLength: -1,
}
return ctx, noAuthResponse, nil
}
示例5: RoundTrip
func (f *Filter) RoundTrip(ctx context.Context, req *http.Request) (context.Context, *http.Response, error) {
switch req.Method {
case "CONNECT":
glog.V(2).Infof("%s \"DIRECT %s %s %s\" - -", req.RemoteAddr, req.Method, req.Host, req.Proto)
rconn, err := f.transport.Dial("tcp", req.Host)
if err != nil {
return ctx, nil, err
}
rw := filters.GetResponseWriter(ctx)
hijacker, ok := rw.(http.Hijacker)
if !ok {
return ctx, nil, fmt.Errorf("http.ResponseWriter(%#v) does not implments http.Hijacker", rw)
}
flusher, ok := rw.(http.Flusher)
if !ok {
return ctx, nil, fmt.Errorf("http.ResponseWriter(%#v) does not implments http.Flusher", rw)
}
rw.WriteHeader(http.StatusOK)
flusher.Flush()
lconn, _, err := hijacker.Hijack()
if err != nil {
return ctx, nil, fmt.Errorf("%#v.Hijack() error: %v", hijacker, err)
}
defer lconn.Close()
go helpers.IOCopy(rconn, lconn)
helpers.IOCopy(lconn, rconn)
return ctx, filters.DummyResponse, nil
default:
helpers.FixRequestURL(req)
helpers.FixRequestHeader(req)
resp, err := f.transport.RoundTrip(req)
if err != nil {
return ctx, nil, err
}
if req.RemoteAddr != "" {
glog.V(2).Infof("%s \"DIRECT %s %s %s\" %d %s", req.RemoteAddr, req.Method, req.URL.String(), req.Proto, resp.StatusCode, resp.Header.Get("Content-Length"))
}
return ctx, resp, err
}
}
示例6: Issue
func (c *RootCA) Issue(commonName string, vaildFor time.Duration, rsaBits int) (*tls.Certificate, error) {
certFile := c.toFilename(commonName, ".crt")
if storage.NotExist(c.store, certFile) {
glog.V(2).Infof("Issue %s certificate for %#v...", c.name, commonName)
c.mu.Lock()
defer c.mu.Unlock()
if storage.NotExist(c.store, certFile) {
if err := c.issue(commonName, vaildFor, rsaBits); err != nil {
return nil, err
}
}
}
resp, err := c.store.Get(certFile)
if err != nil {
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
tlsCert, err := tls.X509KeyPair(data, data)
if err != nil {
return nil, err
}
return &tlsCert, nil
}
示例7: Request
func (f *Filter) Request(ctx context.Context, req *http.Request) (context.Context, *http.Request, error) {
if f.UserAgentEnabled {
glog.V(3).Infof("REWRITE %#v User-Agent=%#v", req.URL.String(), f.UserAgentValue)
req.Header.Set("User-Agent", f.UserAgentValue)
}
if f.HostEnabled {
if host := req.Header.Get(f.HostRewriteBy); host != "" {
glog.V(3).Infof("REWRITE %#v Host=%#v", req.URL.String(), host)
req.Host = host
req.Header.Set("Host", req.Host)
req.Header.Del(f.HostRewriteBy)
}
}
return ctx, req, nil
}
示例8: Request
func (f *Filter) Request(ctx context.Context, req *http.Request) (context.Context, *http.Request, error) {
if f.UserAgentEnabled {
glog.V(3).Infof("REWRITE %#v User-Agent=%#v", req.URL.String(), f.UserAgentValue)
req.Header.Set("User-Agent", f.UserAgentValue)
}
return ctx, req, nil
}
示例9: ExpandAlias
func (d *MultiDialer) ExpandAlias(alias string) error {
names, ok := d.HostMap[alias]
if !ok {
return fmt.Errorf("alias %#v not exists", alias)
}
expire := time.Now().Add(24 * time.Hour)
for _, name := range names {
seen := make(map[string]struct{}, 0)
for _, dnsserver := range d.DNSServers {
var addrs []string
var err error
if net.ParseIP(name) != nil {
addrs = []string{name}
expire = time.Time{}
} else if addrs, err = d.lookupHost2(name, dnsserver); err != nil {
glog.V(2).Infof("lookupHost2(%#v) error: %s", name, err)
continue
}
glog.V(2).Infof("ExpandList(%#v) %#v return %v", name, dnsserver, addrs)
for _, addr := range addrs {
seen[addr] = struct{}{}
}
}
if len(seen) == 0 {
continue
}
if addrs, ok := d.DNSCache.Get(name); ok {
addrs1 := addrs.([]string)
for _, addr := range addrs1 {
seen[addr] = struct{}{}
}
}
addrs := make([]string, 0)
for addr, _ := range seen {
addrs = append(addrs, addr)
}
d.DNSCache.Set(name, addrs, expire)
}
return nil
}
示例10: Request
func (f *Filter) Request(ctx context.Context, req *http.Request) (context.Context, *http.Request, error) {
if strings.HasPrefix(req.RequestURI, "/") {
return ctx, req, nil
}
host := req.Host
if h, _, err := net.SplitHostPort(req.Host); err == nil {
host = h
}
if f.SiteFiltersEnabled {
if f1, ok := f.SiteFiltersRules.Lookup(host); ok {
glog.V(2).Infof("%s \"AUTOPROXY SiteFilters %s %s %s\" with %T", req.RemoteAddr, req.Method, req.URL.String(), req.Proto, f1)
filters.SetRoundTripFilter(ctx, f1.(filters.RoundTripFilter))
return ctx, req, nil
}
}
if f.RegionFiltersEnabled {
if f1, ok := f.RegionFilterCache.Get(host); ok {
filters.SetRoundTripFilter(ctx, f1.(filters.RoundTripFilter))
} else if ips, err := net.LookupHost(host); err == nil {
ip := ips[0]
if strings.Contains(ip, ":") {
if f1, ok := f.RegionFiltersRules["ipv6"]; ok {
glog.V(2).Infof("%s \"AUTOPROXY RegionFilters IPv6 %s %s %s\" with %T", req.RemoteAddr, req.Method, req.URL.String(), req.Proto, f1)
f.RegionFilterCache.Set(host, f1, time.Now().Add(time.Hour))
filters.SetRoundTripFilter(ctx, f1)
}
} else if country, err := f.FindCountryByIP(ip); err == nil {
if f1, ok := f.RegionFiltersRules[country]; ok {
glog.V(2).Infof("%s \"AUTOPROXY RegionFilters %s %s %s %s\" with %T", req.RemoteAddr, country, req.Method, req.URL.String(), req.Proto, f1)
f.RegionFilterCache.Set(host, f1, time.Now().Add(time.Hour))
filters.SetRoundTripFilter(ctx, f1)
} else if f1, ok := f.RegionFiltersRules["default"]; ok {
glog.V(2).Infof("%s \"AUTOPROXY RegionFilters Default %s %s %s\" with %T", req.RemoteAddr, req.Method, req.URL.String(), req.Proto, f1)
f.RegionFilterCache.Set(host, f1, time.Now().Add(time.Hour))
filters.SetRoundTripFilter(ctx, f1)
}
}
}
}
return ctx, req, nil
}
示例11: RoundTrip
func (f *Filter) RoundTrip(ctx context.Context, req *http.Request) (context.Context, *http.Response, error) {
resp, err := f.Transport.RoundTrip(req)
if err != nil {
return ctx, nil, err
} else {
glog.V(2).Infof("%s \"PHP %s %s %s\" %d %s", req.RemoteAddr, req.Method, req.URL.String(), req.Proto, resp.StatusCode, resp.Header.Get("Content-Length"))
}
return ctx, resp, nil
}
示例12: Response
func (f *Filter) Response(ctx context.Context, resp *http.Response) (context.Context, *http.Response, error) {
if f.Rate > 0 && resp.ContentLength > f.Threshold {
glog.V(2).Infof("RateLimit %#v rate to %#v", resp.Request.URL.String(), f.Rate)
resp.Body = NewRateLimitReader(resp.Body, f.Rate, f.Capacity)
}
return ctx, resp, nil
}
示例13: LookupAlias
func (d *MultiDialer) LookupAlias(alias string) (addrs []string, err error) {
names, ok := d.HostMap[alias]
if !ok {
return nil, fmt.Errorf("alias %#v not exists", alias)
}
seen := make(map[string]struct{}, 0)
expiry := time.Now().Add(d.DNSCacheExpiry)
for _, name := range names {
var addrs0 []string
if net.ParseIP(name) != nil {
addrs0 = []string{name}
expiry = time.Time{}
} else if addrs1, ok := d.DNSCache.Get(name); ok {
addrs0 = addrs1.([]string)
} else {
if d.ForceIPv6 {
addrs0, err = d.LookupHost2(name, d.DNSServers[0])
if err != nil {
glog.Warningf("LookupHost2(%#v, %#v) error: %s", name, d.DNSServers[0], err)
addrs0 = []string{}
}
} else {
addrs0, err = d.LookupHost(name)
if err != nil {
glog.Warningf("LookupHost(%#v) error: %s", name, err)
addrs0 = []string{}
}
}
glog.V(2).Infof("LookupHost(%#v) return %v", name, addrs0)
d.DNSCache.Set(name, addrs0, expiry)
}
for _, addr := range addrs0 {
seen[addr] = struct{}{}
}
}
if len(seen) == 0 {
return nil, err
}
addrs = make([]string, 0)
for addr, _ := range seen {
if _, ok := d.IPBlackList.GetQuiet(addr); ok {
continue
}
addrs = append(addrs, addr)
}
if len(addrs) == 0 {
glog.Errorf("MULTIDIALER: LookupAlias(%#v) have no good ip addrs", alias)
return nil, fmt.Errorf("MULTIDIALER: LookupAlias(%#v) have no good ip addrs", alias)
}
return addrs, nil
}
示例14: RoundTrip
func (f *Filter) RoundTrip(ctx context.Context, req *http.Request) (context.Context, *http.Response, error) {
if f := filters.GetRoundTripFilter(ctx); f != nil {
return f.RoundTrip(ctx, req)
}
if req.URL.Host == "" && req.RequestURI[0] == '/' && f.IndexFilesEnabled {
if _, ok := f.IndexFiles[req.URL.Path[1:]]; ok || req.URL.Path == "/" {
if f.GFWListEnabled && strings.HasSuffix(req.URL.Path, ".pac") {
glog.V(2).Infof("%s \"AUTOPROXY ProxyPac %s %s %s\" - -", req.RemoteAddr, req.Method, req.RequestURI, req.Proto)
return f.ProxyPacRoundTrip(ctx, req)
} else {
glog.V(2).Infof("%s \"AUTOPROXY IndexFiles %s %s %s\" - -", req.RemoteAddr, req.Method, req.RequestURI, req.Proto)
return f.IndexFilesRoundTrip(ctx, req)
}
}
}
return ctx, nil, nil
}
示例15: dialMulti
func (d *MultiDialer) dialMulti(network string, addrs []string) (net.Conn, error) {
glog.V(3).Infof("dialMulti(%v, %v)", network, addrs)
type racer struct {
c net.Conn
e error
}
length := len(addrs)
if d.Level < length {
length = d.Level
}
addrs = pickupAddrs(addrs, length, d.TCPConnDuration, d.TCPConnError)
lane := make(chan racer, length)
for _, addr := range addrs {
go func(addr string, c chan<- racer) {
start := time.Now()
conn, err := d.Dialer.Dial(network, addr)
end := time.Now()
if err == nil {
if d.TCPConnReadBuffer > 0 {
if tc, ok := conn.(*net.TCPConn); ok {
tc.SetReadBuffer(d.TCPConnReadBuffer)
}
}
d.TCPConnDuration.Set(addr, end.Sub(start), end.Add(d.ConnExpiry))
} else {
d.TCPConnDuration.Del(addr)
d.TCPConnError.Set(addr, err, end.Add(d.ConnExpiry))
}
lane <- racer{conn, err}
}(addr, lane)
}
var r racer
for i := 0; i < length; i++ {
r = <-lane
if r.e == nil {
go func(count int) {
var r1 racer
for ; count > 0; count-- {
r1 = <-lane
if r1.c != nil {
r1.c.Close()
}
}
}(length - 1 - i)
return r.c, nil
}
}
return nil, r.e
}