本文整理汇总了Golang中github.com/darkhelmet/balance/backends.Backends类的典型用法代码示例。如果您正苦于以下问题:Golang Backends类的具体用法?Golang Backends怎么用?Golang Backends使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Backends类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: httpsBalance
func httpsBalance(bind string, backends BA.Backends) {
if httpsOptions.certFile == "" || httpsOptions.keyFile == "" {
log.Fatalln("specify both -cert and -key")
}
log.Println("using https balancing")
proxy := &Proxy{
&httputil.ReverseProxy{Director: func(req *http.Request) {
backend := backends.Choose()
if backend == nil {
log.Printf("no backend for client %s", req.RemoteAddr)
panic(NoBackend{})
}
req.URL.Scheme = "http"
req.Header.Add("X-Forwarded-Proto", "https")
req.URL.Host = backend.String()
req.Header.Add(XRealIP, RealIP(req))
}},
}
log.Printf("listening on %s, balancing %d backends", bind, backends.Len())
err := http.ListenAndServeTLS(bind, httpsOptions.certFile, httpsOptions.keyFile, proxy)
if err != nil {
log.Fatalf("failed to bind: %s", err)
}
}
开发者ID:rsrsps,项目名称:balance,代码行数:26,代码来源:https.go
示例2: httpBalance
func httpBalance(bind string, backends BA.Backends) {
log.Println("using http balancing")
proxy := &httputil.ReverseProxy{Director: func(req *http.Request) {
req.URL.Host = backends.Choose()
}}
log.Printf("listening on %s, balancing %d backends", bind, backends.Len())
err := http.ListenAndServe(bind, proxy)
if err != nil {
log.Fatalf("failed to bind: %s", err)
}
}
开发者ID:happyspace,项目名称:balance,代码行数:11,代码来源:http.go
示例3: httpBalance
func httpBalance(bind string, backends BA.Backends) error {
log.Println("using http balancing")
proxy := &Proxy{
&httputil.ReverseProxy{Director: func(req *http.Request) {
backend := backends.Choose()
if backend == nil {
log.Printf("no backend for client %s", req.RemoteAddr)
panic(NoBackend{})
}
req.URL.Scheme = "http"
req.URL.Host = backend.String()
req.Header.Add(XRealIP, RealIP(req))
}},
}
log.Printf("listening on %s, balancing %d backends", bind, backends.Len())
return http.ListenAndServe(bind, proxy)
}
开发者ID:jmptrader,项目名称:balance,代码行数:17,代码来源:http.go
示例4: tcpBalance
func tcpBalance(bind string, backends BA.Backends) {
log.Println("using tcp balancing")
ln, err := net.Listen("tcp", bind)
if err != nil {
log.Fatalf("failed to bind: %s", err)
}
log.Printf("listening on %s, balancing %d backends", bind, backends.Len())
for {
conn, err := ln.Accept()
if err != nil {
log.Printf("failed to accept: %s", err)
continue
}
go handleConnection(conn, backends.Choose())
}
}
开发者ID:rsrsps,项目名称:balance,代码行数:18,代码来源:tcp.go
注:本文中的github.com/darkhelmet/balance/backends.Backends类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论