Пример #1
0
func main() {
	newAddr := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 8080}
	originAddr := &net.TCPAddr{IP: net.IPv4(125, 221, 232, 253), Port: 80}
	proxy, err := proxy.NewProxy(newAddr, originAddr)
	if err != nil {
		log.Fatalln(err)
	}
	log.Println("run", originAddr, newAddr)
	proxy.Run()
}
Пример #2
0
func (pr *proxyRegistry) CreateProxy(key string, protocol string, frontend ProxyAddress, backEnds ...ProxyAddress) error {
	pr.Lock()
	defer pr.Unlock()
	if _, found := pr.registry[key]; found {
		return fmt.Errorf("proxy already registered for %v", key)
	}
	proxy, err := pr.proxyFactory(protocol, frontend, backEnds...)
	if err != nil {
		return err
	}
	err = proxy.Run()
	if err != nil {
		return err
	}
	pr.registry[key] = proxy
	return nil
}