Example #1
0
func NewLbClient(hosts []string) (lbclient *lb.Client, err error) {

	var t http.RoundTripper
	tc := &rpc.TransportConfig{
		DialTimeout:           DefaultDialTimeout,
		ResponseHeaderTimeout: DefaultRespTimeout,
	}
	t = rpc.NewTransport(tc)

	si := &proto.SudoerInfo{}
	t = authstub.NewTransport(si, t)

	lbConfig := &lb.Config{
		Http:              &http.Client{Transport: t},
		FailRetryInterval: 0,
		TryTimes:          1,
	}

	lbclient, err = lb.New(hosts, lbConfig)
	if err != nil {
		return nil, err
	}

	return
}
Example #2
0
func newLbClient(hosts []string) (lbclient *lb.Client, err error) {

	dialTimeout, err := time.ParseDuration("30s")
	if err != nil {
		return nil, errors.New("invalid portal dial_timeout")
	}
	respTimeout, err := time.ParseDuration("30s")
	if err != nil {
		return nil, errors.New("invalid portal resp_timeout")
	}

	var t http.RoundTripper
	tc := &rpc.TransportConfig{
		DialTimeout:           dialTimeout,
		ResponseHeaderTimeout: respTimeout,
	}
	t = rpc.NewTransport(tc)

	si := &proto.SudoerInfo{
		UserInfo: proto.UserInfo{
			Uid:   1,
			Utype: 4,
		},
	}
	t = authstub.NewTransport(si, t)

	lbConfig := &lb.Config{
		Http:              &http.Client{Transport: t},
		FailRetryInterval: 0,
		TryTimes:          1,
	}

	lbclient, err = lb.New(hosts, lbConfig)
	if err != nil {
		return nil, err
	}

	return
}