Documentation
¶
Index ¶
- Constants
- func Base64ToJSON(enc *base64.Encoding, mimeType string, r io.Reader) func(w io.Writer) error
- func CheckPassword(hash string, password string) bool
- func CreateMAC(password, token, salt string) string
- func DecodeBase64(s string) []byte
- func ErrorWithLine(err error) error
- func HashPassword(password string, cost int) (string, error)
- func MarshalJSON(indent bool, v interface{}) (string, error)
- func Pipe(rfn func(io.Reader) error, wfn func(io.Writer) error) error
- func PipeJSONObject(obj M) io.Reader
- func RandomSafeString(ln int) string
- func Request(method, ct, url string, reqData, respData interface{}) error
- func RequestCtx(ctx context.Context, method, ct, url string, reqData, respData interface{}) error
- func Retry(fn func() error, attempts uint, delay time.Duration, backoffMod float64) error
- func RetryCtx(ctx context.Context, fn func() error, attempts uint, delay time.Duration, ...) error
- func RuntimeLine(callerIdx int) string
- func SleepUntil(ctx context.Context, hour, min, sec int) error
- func UniqueSlice(in []string) (out []string)
- func VerifyMac(mac1, password, token, salt string) bool
- func WaitFor(fn func() error) <-chan error
- func WriteJSONObject(w io.Writer, obj M) (err error)
- type Error
- type Errors
- type HTTPClient
- func (c *HTTPClient) AllowInsecureTLS(v bool) (old bool)
- func (c *HTTPClient) Do(req *http.Request) (*http.Response, error)
- func (c *HTTPClient) Request(method, ct, url string, reqData, respData interface{}) error
- func (c *HTTPClient) RequestCtx(ctx context.Context, method, ct, uri string, reqData, respData interface{}) error
- type M
- type MultiSet
- type SafeMultiSet
- func (sms *SafeMultiSet) Delete(key string, subKeys ...string)
- func (sms *SafeMultiSet) Has(key, subKey string) (ok bool)
- func (sms *SafeMultiSet) Keys() (keys []string)
- func (sms *SafeMultiSet) Set(key string, subKeys ...string)
- func (sms *SafeMultiSet) Sub(key string) (ss *SafeSet)
- func (sms *SafeMultiSet) Values(key string) (vals []string)
- type SafeSet
- type Sem
- type Set
- type TimeoutSet
- func (ss *TimeoutSet) Close() error
- func (ss *TimeoutSet) Delete(keys ...string)
- func (ss *TimeoutSet) Has(key string) bool
- func (ss *TimeoutSet) IsClosed() bool
- func (ss *TimeoutSet) Keys() []string
- func (ss *TimeoutSet) Len() int
- func (ss *TimeoutSet) Set(key string, to time.Duration)
- func (ss *TimeoutSet) SetAny(keys ...string)
Constants ¶
const DefaultBcryptRounds = 12
Variables ¶
This section is empty.
Functions ¶
func Base64ToJSON ¶
Base64ToJSON allows converting a reader into a base64 encoded string and streaming it directly without using buffers. if enc is nil, it uses base64.StdEncoding by default. Example: WriteJSONObject(w, M{"image": Base64ToJSON(nil, "image/png", r)})
func CheckPassword ¶
func DecodeBase64 ¶
func ErrorWithLine ¶
func MarshalJSON ¶
func PipeJSONObject ¶
PipeJSONObject uses an io.Pipe to stream an M rather than keeping it in memory. if the type of value is io.Reader, it will be directly streamed (so it must be valid JSON). if the type is func(io.Writer|*bufio.Writer) error, it will pass the underlying writer. otherwise json.Marshal will be called on the value.
func RandomSafeString ¶
func RequestCtx ¶
func RetryCtx ¶
func RetryCtx(ctx context.Context, fn func() error, attempts uint, delay time.Duration, backoffMod float64) error
RetryCtx calls fn every (delay * backoffMod) until it returns nil, the passed ctx is done or attempts are reached.
func RuntimeLine ¶
Types ¶
type HTTPClient ¶
var DefaultClient HTTPClient
func (*HTTPClient) AllowInsecureTLS ¶
func (c *HTTPClient) AllowInsecureTLS(v bool) (old bool)
func (*HTTPClient) Request ¶
func (c *HTTPClient) Request(method, ct, url string, reqData, respData interface{}) error
Request is a wrapper for `RequestCtx(context.Background(), method, ct, url, reqData, respData)`
func (*HTTPClient) RequestCtx ¶
func (c *HTTPClient) RequestCtx(ctx context.Context, method, ct, uri string, reqData, respData interface{}) error
RequestCtx is a smart wrapper to handle http requests.
- ctx: is a context.Context in case you want more control over canceling the request.
- method: http method (GET, PUT, POST, etc..), if empty it defaults to GET.
- ct: request content-type.
- url: the request's url.
- reqData: data to pass to POST/PUT requests, if it's an `io.Reader`, a `[]byte` or a `string`, it will be passed as-is, `url.Values` will be encoded as "application/x-www-form-urlencoded", any other object will be encoded as JSON.
- respData: data object to get the response or `nil`, can be , `io.Writer`, `func(io.Reader) error` to read the body directly, `func(*http.Response) error` to process the actual response, or a pointer to an object to decode a JSON body into.
type SafeMultiSet ¶
type SafeMultiSet struct {
// contains filtered or unexported fields
}
SafeMultiSet is a concurrent-safe MultiSet
func NewSafeMultiSet ¶
func NewSafeMultiSet(keys ...string) *SafeMultiSet
func (*SafeMultiSet) Delete ¶
func (sms *SafeMultiSet) Delete(key string, subKeys ...string)
func (*SafeMultiSet) Has ¶
func (sms *SafeMultiSet) Has(key, subKey string) (ok bool)
func (*SafeMultiSet) Keys ¶
func (sms *SafeMultiSet) Keys() (keys []string)
func (*SafeMultiSet) Set ¶
func (sms *SafeMultiSet) Set(key string, subKeys ...string)
func (*SafeMultiSet) Sub ¶
func (sms *SafeMultiSet) Sub(key string) (ss *SafeSet)
func (*SafeMultiSet) Values ¶
func (sms *SafeMultiSet) Values(key string) (vals []string)
type SafeSet ¶
type SafeSet struct {
// contains filtered or unexported fields
}
func NewSafeSet ¶
func (*SafeSet) MarshalJSON ¶
func (*SafeSet) UnmarshalJSON ¶
type Set ¶
type Set map[string]struct{}
Set is a simple set.
func (Set) MarshalJSON ¶
func (*Set) UnmarshalJSON ¶
type TimeoutSet ¶
type TimeoutSet struct {
// contains filtered or unexported fields
}
func NewTimeoutSet ¶
func NewTimeoutSet(purgeTimeout time.Duration) *TimeoutSet
func (*TimeoutSet) Close ¶
func (ss *TimeoutSet) Close() error
func (*TimeoutSet) Delete ¶
func (ss *TimeoutSet) Delete(keys ...string)
func (*TimeoutSet) Has ¶
func (ss *TimeoutSet) Has(key string) bool
func (*TimeoutSet) IsClosed ¶
func (ss *TimeoutSet) IsClosed() bool
func (*TimeoutSet) Keys ¶
func (ss *TimeoutSet) Keys() []string
func (*TimeoutSet) Len ¶
func (ss *TimeoutSet) Len() int
func (*TimeoutSet) SetAny ¶
func (ss *TimeoutSet) SetAny(keys ...string)