funcWithRetry(req*http.Request)(*http.Response,error){res,err:=http.DefaultClient.Do(req)// or pass a client hereiferr!=nil{ifIsRetryable(err){// retry}else{// bail}}returnres,nil}funcmain(){req,err:=http.NewRequest("GET","https://example.com",nil)iferr!=nil{fmt.Fprintln(os.Stderr,err.Error())os.Exit(1)}res,err:=WithRetry(req)...}
I spend a lot of time thinking about code, how it should be written and why. Have worked on big things and small things. For every book I read, I buy 5 more.
That looks perfectly reasonable. I was mostly avoiding Go's actual "net/http" package. Not for any particular reason, it's a nice API, just wanted a slightly different approach. :)
I spend a lot of time thinking about code, how it should be written and why. Have worked on big things and small things. For every book I read, I buy 5 more.
What about?
That looks perfectly reasonable. I was mostly avoiding Go's actual "net/http" package. Not for any particular reason, it's a nice API, just wanted a slightly different approach. :)
I think retries and traffic management flow should be left on the service mesh level.
There is a good read here
istio.io/docs/concepts/traffic-man...
I would also love to see something like that in Go
thepollyproject.org/
Definitely good arguments to be made in favour of that, but somewhat outside of the scope of this post. 😀