Documentation
¶
Index ¶
- Variables
- func AESDecrypt(b64Data, sep, passphrase string, keySize uint8) (parts []string, err error)
- func AESEncrypt(parts []string, sep string, passphrase string, keySize uint8) (_ string, err error)
- func AppendToTar(tw *tar.Writer, fullPath, tarPath string) (err error)
- func BoolPtr(b bool) *bool
- func BoolVal(b *bool) bool
- func Caller(skip int, trim bool) (function, file string, line int)
- func CopyOnWriteFile(fp string, fn func(w io.Writer) error) (err error)
- func CopyOnWriteFileHash(fp string, fn func(bw *bufio.Writer) error, h hash.Hash, mode os.FileMode) (sum []byte, err error)
- func CopyOnWriteFilePerms(fp string, fn func(bw *bufio.Writer) error, mode os.FileMode) (err error)
- func DecodeImageConfig(rd io.Reader) (safeReader io.Reader, cfg image.Config, format string, err error)
- func FindKeywords(s string, sepChar rune, fn func(kw, val string))
- func ImageFromDataURL(dataURL string, fn func(ext string) (io.WriteCloser, error)) error
- func MergeErrors(sep string, errs ...error) error
- func ModNextDay(start, now time.Time, days int) time.Duration
- func MultiWriter(writers ...io.Writer) (io.Writer, func() []error)
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func PipeRd(writeFn func(io.Writer) error) io.ReadCloser
- func PipeWr(readerFn func(io.Reader) error) io.WriteCloser
- func RandomString(sz int) (string, error)
- func ReadFileWithDecoder(fp string, dec func(r io.Reader) FileDecoder, out interface{}) error
- func ReadJSONFile(fp string, out interface{}) error
- func ReplaceAllStringSubmatchFunc(re *regexp.Regexp, src string, repl func([]string) []string, n int) string
- func ReplaceAllStringSubmatchReaderFunc(re *regexp.Regexp, r io.Reader, fn func(in []string) []string) io.Reader
- func Request(method, ct, url string, reqData, respData interface{}) error
- func RequestCtx(ctx context.Context, method, ct, url string, reqData, respData interface{}) error
- func RequestHeadersCtx(ctx context.Context, method, url string, header http.Header, ...) 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 SaveImageFromDataURL(dataURL, output string) (fp string, err error)
- func TarFolder(folder, fp string, topts *TarOptions) (err error)
- func TimeUntil(t time.Time, hour, min, sec int, nextDay bool) time.Duration
- func TryParseTime(ts string, layouts []string, tz *time.Location) time.Time
- func UniqueSlice(in []string) (out []string)
- func UnsafeBytes(s string) (out []byte)
- func UnsafeString(p []byte) string
- func Unzip(rt io.ReaderAt, dst string, filter func(path string, f *zip.File) bool) (err error)
- func ValidEmail(email string) bool
- func WriteFileWithEncoder(fp string, enc func(w io.Writer) FileEncoder, in interface{}) error
- func WriteJSONFile(fp string, in interface{}, indent bool) error
- type Buffer
- func (b *Buffer) ReadAt(p []byte, off int64) (n int, err error)
- func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)
- func (b *Buffer) UnsafeString() string
- func (b *Buffer) Write(p []byte) (n int, err error)
- func (b *Buffer) WriteByte(c byte) (err error)
- func (b *Buffer) WriteRune(r rune) (n int, err error)
- func (b *Buffer) WriteString(s string) (n int, err error)
- type BufferPool
- type CachedReader
- type Closer
- type ErrorList
- type FileDecoder
- type FileEncoder
- 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, contentType, uri string, ...) (err error)
- func (c *HTTPClient) RequestHeadersCtx(ctx context.Context, method, uri string, header http.Header, ...) (err error)
- type KeyVal
- type M
- type MultiSet
- type SafeErrorList
- type SafeSet
- type Scheduler
- type Sem
- type Set
- type TarOptions
- type TaskFunc
- type Workers
- type XorShiftRNG
Constants ¶
This section is empty.
Variables ¶
Tribools
var ( ErrClosedPool = errors.New("the pool is closed, go swim somewhere else") ErrPoolIsFull = errors.New("the pool is full") )
var ErrInvalidImageDataURL = xerrors.New("invalid dataURL, must be in format `data:image/{png,jpeg,jpg,gif,webp};base64,`")
var (
ErrOffsetOOB = xerrors.New("offset out of bounds")
)
var ErrStopTask = errors.New("STOP")
ErrStopTask can be returned to stop the run loop
Functions ¶
func AESDecrypt ¶
func AESEncrypt ¶
AESEncrypt joins parts using sep, encrypts and seals it and returns b64 string. valid sizes are 16, 24 and 32 for AES-128, 192 and 256 respectively, defaults to 16.
func AppendToTar ¶
AppendToTar is a helper function for add a physical file to tar
func CopyOnWriteFileHash ¶
func CopyOnWriteFilePerms ¶
func DecodeImageConfig ¶
func DecodeImageConfig(rd io.Reader) (safeReader io.Reader, cfg image.Config, format string, err error)
DecodeImageConfig accepts a reader and returns a CachedReader and the results of image.DecodeConfig
func FindKeywords ¶
func ImageFromDataURL ¶
func MergeErrors ¶
MergeErrors merges a slice of errors, but they will lose any context. returns nil if all errors are nil
func ModNextDay ¶
ModNextDay returns the next duration until X days since start. for example: - ModNextDay(2020-06-13, 2020-07-14, 15) => 14 days (2020-07-28) - ModNextDay(2020-06-29, 2020-07-14, 15) => 0 - ModNextDay(2020-07-14, 2020-07-14, 15) => 0 - ModNextDay(2020-07-15, 2020-07-14, 15) => 1 day (2020-07-15)
func MultiWriter ¶
MultiWriter creates a writer that duplicates its writes to all the provided writers, similar to the Unix tee(1) command.
Each write is written to each listed writer, one at a time. If a listed writer returns an error, that writer will be ignored for later writes. returns the multi writer and a func that returns a slice of errors if there were any.
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
func PipeRd ¶
func PipeRd(writeFn func(io.Writer) error) io.ReadCloser
PipeRd is an io.Pipe helper, returns a io.ReadCloser
func PipeWr ¶
func PipeWr(readerFn func(io.Reader) error) io.WriteCloser
PipeWr is an io.Pipe helper, returns a io.WriteCloser
func RandomString ¶
func ReadFileWithDecoder ¶
func ReadFileWithDecoder(fp string, dec func(r io.Reader) FileDecoder, out interface{}) error
func ReadJSONFile ¶
func ReplaceAllStringSubmatchFunc ¶
func ReplaceAllStringSubmatchFunc(re *regexp.Regexp, src string, repl func([]string) []string, n int) string
ReplaceAllStringSubmatchFunc is a helper function to replace regexp sub matches. based on https://gist.github.com/slimsag/14c66b88633bd52b7fa710349e4c6749 (MIT) Note: slice `in` is reused internally, make a copy if you need to keep it, ex:
cp := append([]string(nil), in...)
example:
re := regexp.MustCompile(`([:*].*?)(?:/|$)`) ReplaceAllStringSubmatchFunc(re, "/path/:id/:name", func(in []string) []string { for i, s := range in { in[i] = "my-" + s[1:] } return in }, -1) === "/path/my-id/my-name"
func RequestCtx ¶
func RequestHeadersCtx ¶
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 SaveImageFromDataURL ¶
SaveImageFromDataURL expects output name without the extension returns full path
func TarFolder ¶
func TarFolder(folder, fp string, topts *TarOptions) (err error)
func TimeUntil ¶
TimeUntil is a tiny helper to return the duration until hour:min:sec if the duration is in the past and nextDay is true, it'll add 24 hours.
func TryParseTime ¶
TryParseTime will try to parse input in all provided go time formats. Accepts: U for unix ts, UN for unix nano.
func UniqueSlice ¶
UniqueSlice returns all unique keys in `in` by modifying it in place
func UnsafeBytes ¶
UnsafeBytes can spawn even bigger dragons, summon wisely
func WriteFileWithEncoder ¶
func WriteFileWithEncoder(fp string, enc func(w io.Writer) FileEncoder, in interface{}) error
func WriteJSONFile ¶
Types ¶
type Buffer ¶
Buffer is a drop-in replacement for bytes.Buffer that implements the io.ReaderAt interface.
func NewBufferString ¶
func (*Buffer) UnsafeString ¶
UnsafeString returns the accumulated string, unsafely without a copy.
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
func (*BufferPool) Get ¶
func (bp *BufferPool) Get() *Buffer
func (*BufferPool) Put ¶
func (bp *BufferPool) Put(b *Buffer)
type CachedReader ¶
func (*CachedReader) Rewind ¶
func (cr *CachedReader) Rewind()
type FileDecoder ¶
type FileDecoder interface {
Decode(interface{}) error
}
type FileEncoder ¶
type FileEncoder interface {
Encode(interface{}) error
}
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, contentType, uri string, reqData, respData interface{}) (err 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.
- contentType: 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.
func (*HTTPClient) RequestHeadersCtx ¶
func (c *HTTPClient) RequestHeadersCtx(ctx context.Context, method, uri string, header http.Header, reqData, respData interface{}) (err error)
RequestHeaderCtx 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.
- url: the request's url.
- header: headers to pass to the request, ex User-Agent.
- 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 KeyVal ¶
func KeywordsToSearch ¶
type SafeErrorList ¶
type SafeErrorList struct {
// contains filtered or unexported fields
}
func (*SafeErrorList) Err ¶
func (el *SafeErrorList) Err() error
func (*SafeErrorList) Error ¶
func (el *SafeErrorList) Error() string
func (*SafeErrorList) Len ¶
func (el *SafeErrorList) Len() int
func (*SafeErrorList) Push ¶
func (el *SafeErrorList) Push(errs ...error)
type SafeSet ¶
func NewSafeSet ¶
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
func NewScheduler ¶
type TarOptions ¶
type XorShiftRNG ¶
type XorShiftRNG uint64
XorShiftRNG simple efficient thread-safe lock-free rng, self seeds with time.Now().UnixNano() if 0
func (*XorShiftRNG) Bytes ¶
func (x *XorShiftRNG) Bytes() [8]byte
func (*XorShiftRNG) Int63 ¶
func (x *XorShiftRNG) Int63() int64
func (*XorShiftRNG) Seed ¶
func (x *XorShiftRNG) Seed(n int64)
func (*XorShiftRNG) Uint64 ¶
func (x *XorShiftRNG) Uint64() (rv uint64)