Documentation ¶
Index ¶
- Constants
- func BoolPtr(b bool) *bool
- func BytesLenSplit(s []byte, n int) [][]byte
- func CIDRIsSubset(na *net.IPNet, nb *net.IPNet) bool
- func CamelToSnakeCase(s string) string
- func CoalesceCIDRs(cidrs []*net.IPNet, coalesceNumber int, coalesceMaskLen int) []*net.IPNet
- func CoalesceIPs(ips []net.IP, coalesceNumber int, coalesceMaskLen int) []*net.IPNet
- func ContainsStr(a []string, x string) bool
- func ErrsToStrs(errs []error) []string
- func FirstIP(ipn *net.IPNet) net.IP
- func FloatPtr(f float64) *float64
- func HashInts(ints []int, sortIntsBeforeHashing bool) []byte
- func IP4InRange(ip, ipRange string) (bool, error)
- func IP4ToNum(ip string) (uint32, error)
- func IPToCIDR(ip net.IP) *net.IPNet
- func Int64Ptr(i int64) *int64
- func IntPtr(i int) *int
- func IntSliceToMap(s []int) map[int]struct{}
- func InterfacePtr(i interface{}) *interface{}
- func JoinErrs(errs []error) error
- func JoinErrsSep(errs []error, separator string) error
- func JoinErrsStr(errs []error) string
- func LastIP(ipn *net.IPNet) net.IP
- func RangeStr(ipn *net.IPNet) string
- func RemoveStrDuplicates(inputStrings []string, seenStrings map[string]struct{}) ([]string, map[string]struct{})
- func Stacktrace() []byte
- func StrInArray(strs []string, s string) bool
- func StrPtr(str string) *string
- func StripAllWhitespace(s string) string
- func ToNumeric(v interface{}) (float64, bool)
- func UInt64Ptr(u uint64) *uint64
- func UIntPtr(u uint) *uint
- func Uint64Ptr(u uint64) *uint64
- type Backoff
- type BodyInterceptor
- type Interceptor
- type JSONIntStr
- type JSONNameOrIDStr
Examples ¶
Constants ¶
const BitsPerByte = 8
const ConstantBackoffDuration = 30 * time.Second
ConstantBackoffDuration is a fallback duration that may be used by an application along with NewConstantBackoff()
const DefaultFactor = 2.0
DefaultFactor may be used by applications for the factor argument.
const MSPerNS = int64(1000000)
Variables ¶
This section is empty.
Functions ¶
func BytesLenSplit ¶
BytesLenSplit splits the given byte array into an n-length arrays. If n > len(s), returns a slice with a single []byte containing all of s. If n <= 0, returns an empty slice.
func CIDRIsSubset ¶
CIDRIsSubset returns whether na is a subset (possibly improper) of nb.
func CamelToSnakeCase ¶
func CoalesceCIDRs ¶
CoalesceCIDRs coalesces cidrs into a smaller set of CIDRs, by combining overlapping networks into networks of size coalesceMaskLen, if there are at least coalesceNumber cidrs in the larger mask.
func CoalesceIPs ¶
CoalesceIPs combines ips into CIDRs, by combining overlapping networks into networks of size coalesceMaskLen, if there are at least coalesceNumber IPs in the larger mask.
func ContainsStr ¶
func ErrsToStrs ¶
func FirstIP ¶
FirstIP returns the first IP in the CIDR. For example, The CIDR 192.0.2.0/24 returns 192.0.2.0.
func HashInts ¶
HashInts returns a SHA512 hash of ints. If sortIntsBeforeHashing, the ints are sorted before before hashing. Sorting is done in a copy, the input ints slice is not modified.
func IP4InRange ¶
func IPToCIDR ¶
IPToCIDR returns the CIDR containing just the given IP. For IPv6, this means /128, for IPv4, /32.
func IntSliceToMap ¶
IntSliceToMap creates an int set from an array.
func InterfacePtr ¶
func InterfacePtr(i interface{}) *interface{}
func JoinErrsSep ¶
Example ¶
errs := []error{ errors.New("test"), errors.New("quest"), } fmt.Println(JoinErrsSep(errs, "\n"))
Output: test quest
func JoinErrsStr ¶
func LastIP ¶
LastIP returns the last IP in the CIDR. For example, The CIDR 192.0.2.0/24 returns 192.0.2.255.
func RangeStr ¶
RangeStr returns the hyphenated range of IPs. For example, The CIDR 192.0.2.0/24 returns "192.0.2.0-192.0.2.255".
func RemoveStrDuplicates ¶
func RemoveStrDuplicates(inputStrings []string, seenStrings map[string]struct{}) ([]string, map[string]struct{})
RemoveStrDuplicates removes duplicates from strings, considering a map of already-seen duplicates. Returns the strings which are unique, and not already present in seen; and a map of the unique strings in inputStrings and seenStrings.
This can be used, for example, to remove duplicates from multiple lists of strings, in order, using a shared map of seen strings.
func Stacktrace ¶
func Stacktrace() []byte
Stacktrace is a helper function which returns the current stacktrace. It wraps runtime.Stack, which requires a sufficiently long buffer.
func StrInArray ¶
StrInArray returns whether s is one of the strings in strs.
func StripAllWhitespace ¶
StripAllWhitespace returns s with all whitespace removed, as defined by unicode.IsSpace.
Types ¶
type BodyInterceptor ¶
type BodyInterceptor struct { W http.ResponseWriter BodyBytes []byte }
BodyInterceptor fulfills the Writer interface, but records the body and doesn't actually write. This allows performing operations on the entire body written by a handler, for example, compressing or hashing. To actually write, call `RealWrite()`. Note this means `len(b)` and `nil` are always returned by `Write()`, any real write errors will be returned by `RealWrite()`.
func (*BodyInterceptor) Body ¶
func (i *BodyInterceptor) Body() []byte
Body returns the internal bytes stored by calls to Write.
func (*BodyInterceptor) Header ¶
func (i *BodyInterceptor) Header() http.Header
Header implements http.ResponseWriter. It returns BodyInterceptor's internal ResponseWriter.Header, without modification or tracking.
func (*BodyInterceptor) RealWrite ¶
func (i *BodyInterceptor) RealWrite(b []byte) (int, error)
RealWrite writes BodyInterceptor's internal bytes, which were stored by calls to Write.
func (*BodyInterceptor) Write ¶
func (i *BodyInterceptor) Write(b []byte) (int, error)
Write implements http.ResponseWriter. It writes the given bytes to BodyInterceptor's internal tracking bytes, and does not write them to the internal ResponseWriter. To write the internal bytes, call BodyInterceptor.RealWrite.
func (*BodyInterceptor) WriteHeader ¶
func (i *BodyInterceptor) WriteHeader(rc int)
WriteHeader implements http.ResponseWriter. It does the real write to Interceptor's internal ResponseWriter, without modification or tracking.
type Interceptor ¶
type Interceptor struct { W http.ResponseWriter Code int ByteCount int }
Interceptor implements http.ResponseWriter. It intercepts writes to w, and tracks the HTTP code and the count of bytes written, while still writing to w.
func (*Interceptor) Header ¶
func (i *Interceptor) Header() http.Header
Header implements http.ResponseWriter. It returns Interceptor's internal ResponseWriter.Header, without modification or tracking.
func (*Interceptor) Write ¶
func (i *Interceptor) Write(b []byte) (int, error)
Write implements http.ResponseWriter. It does the real write to Interceptor's internal ResponseWriter, while keeping track of the count of bytes written. It also sets Interceptor's tracked code to 200 if WriteHeader wasn't called (which is what the real http.ResponseWriter will write to the client).
func (*Interceptor) WriteHeader ¶
func (i *Interceptor) WriteHeader(rc int)
WriteHeader implements http.ResponseWriter. It does the real write to Interceptor's internal ResponseWriter, while keeping track of the code.
type JSONIntStr ¶
type JSONIntStr int64
JSONIntStr unmarshals JSON strings or numbers into an int. This is designed to handle backwards-compatibility for old Perl endpoints which accept both. Please do not use this for new endpoints or new APIs, APIs should be well-typed.
func (JSONIntStr) String ¶
func (i JSONIntStr) String() string
func (JSONIntStr) ToInt64 ¶
func (i JSONIntStr) ToInt64() int64
func (*JSONIntStr) UnmarshalJSON ¶
func (i *JSONIntStr) UnmarshalJSON(d []byte) error
type JSONNameOrIDStr ¶
JSONNameOrIDStr is designed to handle backwards-compatibility for old Perl endpoints which accept both. Please do not use this for new endpoints or new APIs, APIs should be well-typed. NOTE: this differs from JSONIntStr in that this field could be 1 of 3 options:
- string representing an integer
- string representing a unique name
- integer
func (JSONNameOrIDStr) MarshalJSON ¶
func (i JSONNameOrIDStr) MarshalJSON() ([]byte, error)
func (*JSONNameOrIDStr) UnmarshalJSON ¶
func (i *JSONNameOrIDStr) UnmarshalJSON(d []byte) error