示例#1
0
func NewLocationWithOptions(id string, loadBalancer loadbalance.LoadBalancer, o Options) (*HttpLocation, error) {
	if loadBalancer == nil {
		return nil, fmt.Errorf("Provide load balancer")
	}
	o, err := parseOptions(o)
	if err != nil {
		return nil, err
	}

	observerChain := middleware.NewObserverChain()
	observerChain.Add(BalancerId, loadBalancer)

	middlewareChain := middleware.NewMiddlewareChain()
	middlewareChain.Add(RewriterId, -2, &Rewriter{TrustForwardHeader: o.TrustForwardHeader, Hostname: o.Hostname})
	middlewareChain.Add(BalancerId, -1, loadBalancer)

	return &HttpLocation{
		id:              id,
		loadBalancer:    loadBalancer,
		options:         o,
		transport:       newTransport(o),
		middlewareChain: middlewareChain,
		observerChain:   observerChain,
		mutex:           &sync.RWMutex{},
	}, nil
}
示例#2
0
func NewLocationWithOptions(id string, loadBalancer loadbalance.LoadBalancer, o Options) (*HttpLocation, error) {
	if loadBalancer == nil {
		return nil, fmt.Errorf("Provide load balancer")
	}
	o, err := setDefaults(o)
	if err != nil {
		return nil, err
	}

	observerChain := middleware.NewObserverChain()
	observerChain.Add(BalancerId, loadBalancer)

	middlewareChain := middleware.NewMiddlewareChain()
	middlewareChain.Add(RewriterId, -2, &Rewriter{TrustForwardHeader: o.TrustForwardHeader, Hostname: o.Hostname})
	middlewareChain.Add(BalancerId, -1, loadBalancer)

	t := o.Transport
	if t == nil {
		t = NewTransport(TransportOptions{KeepAlive: o.KeepAlive, Timeouts: o.Timeouts})
	}

	return &HttpLocation{
		id:              id,
		loadBalancer:    loadBalancer,
		options:         o,
		transport:       t,
		middlewareChain: middlewareChain,
		observerChain:   observerChain,
		mutex:           &sync.RWMutex{},
	}, nil
}