repositorypackage
0.0.0-20180112121917-1f67a73e268c
Repository: https://github.com/shevaxu/web-utils.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
web-utils
[DEPRECATED] New features will be implemented in https://github.com/ShevaXu/golang.
web-utils provides useful web-dev features following some best practices for production, including:
HTTP Utils
A SafeClient with
timeout
setting for underlying http.Client;- request retries (can be timeout only);
- exponential backoff.
Just utils.StdClient()
to get a preset-client or cl := utils.SafeClient{...}
for a custom one.
Semaphore
s := NewSemaphore(10)
go func() {
ctx := context.Background() // for cancellation
if s.Obtain(ctx) {
defer s.Release()
// do whatever
}
}()
For weighted semaphore, see []this implementation](https://github.com/golang/sync/blob/master/semaphore/semaphore.go).
Asserting
Tiny functions for testing.
a := assert.NewAssert()
a.True(...)
a.Equal(...)
a.NotEqual(...)
a.Nil(...)
a.NotNil(...)
a.NoError(...)
Install
go get github.com/ShevaXu/web-utils
TODO
context
support for client;- rate-limit (leaky bucket);
- circuit-breaker.