* only cache routes if told to do so * Use roundrobin selector and retry in proxy * Update lookup to require service * Fix compile * Fix compile * Update * Update * rename query to lookup * Update router.go * Update
		
			
				
	
	
		
			34 lines
		
	
	
		
			573 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			573 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package http
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"net/http"
 | |
| 
 | |
| 	"github.com/micro/go-micro/v3/selector"
 | |
| )
 | |
| 
 | |
| type roundTripper struct {
 | |
| 	rt   http.RoundTripper
 | |
| 	st   selector.Selector
 | |
| 	opts Options
 | |
| }
 | |
| 
 | |
| func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
 | |
| 	routes, err := r.opts.Router.Lookup(req.URL.Host)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	// rudimentary retry 3 times
 | |
| 	for _, route := range routes {
 | |
| 		req.URL.Host = route.Address
 | |
| 		w, err := r.rt.RoundTrip(req)
 | |
| 		if err != nil {
 | |
| 			continue
 | |
| 		}
 | |
| 		return w, nil
 | |
| 	}
 | |
| 
 | |
| 	return nil, errors.New("failed request")
 | |
| }
 |