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


Golang backends.Backends類代碼示例

本文整理匯總了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;未經允許,請勿轉載。