Documentation ¶
Index ¶
- Constants
- Variables
- func AbsInt(v int) int
- func AddParamSetToParamSet(a map[string][]string, b map[string][]string) map[string][]string
- func AddParams(a map[string]string, b ...map[string]string) map[string]string
- func AddParamsToParamSet(a map[string][]string, b map[string]string) map[string][]string
- func AnyMatch(re []*regexp.Regexp, s string) bool
- func AtMost(a []string, n int) []string
- func BugsFromCommitMsg(msg string) map[string][]string
- func ChunkIter(length, chunkSize int, fn func(int, int) error) error
- func ChunkIterInt(s []int, chunkSize int, fn func([]int) error) error
- func Close(c io.Closer)
- func ContainsAny(s string, a []string) bool
- func ContainsAnyMap(parent map[string]string, children ...map[string]string) bool
- func ContainsAnyMapInSliceValues(parent map[string][]string, children ...map[string]string) bool
- func ContainsMap(parent, child map[string]string) bool
- func ContainsMapInSliceValues(parent map[string][]string, child map[string]string) bool
- func CookieDomainMatch(domainA, domainB string) bool
- func CopyStringMap(m map[string]string) map[string]string
- func CopyStringSlice(s []string) []string
- func Float64StableSum(s []float64) float64
- func FromDos(s string) string
- func GenerateID() (string, error)
- func GetFormattedByteSize(b float64) string
- func GetStackTrace() string
- func In(s string, a []string) bool
- func Index(s string, a []string) int
- func InsertString(strs []string, idx int, s string) []string
- func InsertStringSorted(strs []string, s string) []string
- func Int64Equal(a, b []int64) bool
- func IntersectIntSets(sets []map[int]bool, minIdx int) map[int]bool
- func IsDirEmpty(dir string) (bool, error)
- func IsNil(i interface{}) bool
- func IterTimeChunks(start, end time.Time, chunkSize time.Duration, ...) error
- func KeysOfIntSet(set map[int]bool) []int
- func KeysOfParamSet(set map[string][]string) []string
- func LogErr(err error)
- func MD5FromReader(r io.Reader, w io.Writer) ([]byte, error)
- func MD5SSlice(val []string) (string, error)
- func MD5Sum(val interface{}) (string, error)
- func MapsEqual(a, b map[string]string) bool
- func MaxInt(intList ...int) int
- func MaxInt32(a, b int32) int32
- func MaxInt64(a, b int64) int64
- func MaybeReadGobFile(file string, data interface{}) error
- func MinInt(a, b int) int
- func MinInt32(a, b int32) int32
- func MinInt64(a, b int64) int64
- func Mkdir(name string, perm os.FileMode)
- func MkdirAll(name string, perm os.FileMode)
- func NewThreadSafeWriter(w io.Writer) io.Writer
- func ParseIntSet(expr string) ([]int, error)
- func ParseTimeNs(t string) (time.Time, error)
- func Permute(ints []int) [][]int
- func PermuteStrings(strs []string) [][]string
- func RandomName() string
- func RandomNameR(r *mathrand.Rand) string
- func ReadGobFile(file string, data interface{}) error
- func Remove(name string)
- func RemoveAll(path string)
- func Rename(oldpath, newpath string)
- func Repeat(interval time.Duration, stopCh <-chan bool, fn func())
- func RepeatCtx(interval time.Duration, ctx context.Context, fn func())
- func RepeatJoin(str, sep string, n int) string
- func Reverse(s []string) []string
- func Round(v float64) float64
- func RoundUpToPowerOf2(i int32) int32
- func SSliceCmp(a, b []string) int
- func SSliceEqual(a, b []string) bool
- func SafeAtoi(n string) int
- func SignInt(v int) int
- func StringToCodeName(s string) string
- func TimeIsZero(t time.Time) bool
- func TimeStamp(targetUnit time.Duration) int64
- func TimeStampMs() int64
- func TimeToUnixFloat(t time.Time) float64
- func ToDos(s string) string
- func Trunc(s string, n int) string
- func Truncate(s string, length int) string
- func UnZip(dest, src string) error
- func UnixFloatToTime(t float64) time.Time
- func UnixMillisToTime(t int64) time.Time
- func ValidateCommit(hash string) bool
- func WithBufferedWriter(w io.Writer, fn func(w io.Writer) error) (err error)
- func WithGzipWriter(w io.Writer, fn func(w io.Writer) error) (err error)
- func WithReadFile(file string, fn func(f io.Reader) error) error
- func WithWriteFile(file string, writeFn func(io.Writer) error) error
- func WriteGobFile(file string, data interface{}) error
- func ZipIt(target, source string) error
- type CondMonitor
- type GobDecoder
- type GobEncoder
- type Int64Slice
- type LRUCache
- type LRUCodec
- type MemLRUCache
- type MonitorRelease
- type MultiWriter
- type NamedErrGroup
- type StringSet
- func (s StringSet) AddLists(lists ...[]string) StringSet
- func (s StringSet) Complement(other StringSet) StringSet
- func (s StringSet) Copy() StringSet
- func (s StringSet) Equals(other StringSet) bool
- func (s StringSet) Intersect(other StringSet) StringSet
- func (s StringSet) Keys() []string
- func (s StringSet) String() string
- func (s StringSet) Union(other StringSet) StringSet
- type TempRepo
- type ThreadSafeWriter
- type Validator
Constants ¶
const ( KB float64 = 1 << (10 * iota) MB GB TB PB PROJECT_CHROMIUM = "chromium" BUG_DEFAULT_PROJECT = PROJECT_CHROMIUM BUGS_PATTERN = "(?m)^(?:BUG=|Bug:)(.+)$" SECONDS_TO_MILLIS = int64(time.Second / time.Millisecond) MILLIS_TO_NANOS = int64(time.Millisecond / time.Nanosecond) MICROS_TO_NANOS = int64(time.Microsecond / time.Nanosecond) // time.RFC3339Nano only uses as many sub-second digits are required to // represent the time, which makes it unsuitable for sorting. This // format ensures that all 9 nanosecond digits are used, padding with // zeroes if necessary. RFC3339NanoZeroPad = sklog.RFC3339NanoZeroPad // SAFE_TIMESTAMP_FORMAT is time format which is similar to // RFC3339NanoZeroPad, but with most of the punctuation omitted. This // timestamp can only be used to format and parse times in UTC. SAFE_TIMESTAMP_FORMAT = "20060102T150405.000000000Z" )
Variables ¶
var ( BUGS_REGEX = regexp.MustCompile(BUGS_PATTERN) TimeZero = time.Time{}.UTC() TimeUnixZero = time.Unix(0, 0).UTC() )
Functions ¶
func AddParamSetToParamSet ¶
func AddParams ¶
AddParams adds the second instance of map[string]string to the first and returns the first map.
func AddParamsToParamSet ¶
func BugsFromCommitMsg ¶
BugsFromCommitMsg parses BUG= tags from a commit message and returns them.
func ChunkIterInt ¶
ChunkIterInt iterates over a slice of ints in chunks of smaller slices.
func ContainsAny ¶
ContainsAny returns true if |s| contains any element of |a|.
func ContainsAnyMap ¶
ContainsAnyMap checks to see if any of the children maps are contained in the parent map.
func ContainsAnyMapInSliceValues ¶
ContainsAnyMapInSliceValues checks to see if any of the children maps are contained in the parent map.
func ContainsMap ¶
ContainsMap checks if child map is contained within the parent map
func ContainsMapInSliceValues ¶
ContainsMapInSliceValues checks if child map is contained within the parent map.
func CookieDomainMatch ¶
CookieDomainMatch returns True if domainA domain-matches domainB, according to RFC 2965. domainA and domainB may only be host domain names. IP addresses are currently not supported.
Host names can be specified either as an IP address or a HDN string. Sometimes we compare one host name with another. (Such comparisons SHALL be case-insensitive.) Host A's name domain-matches host B's if * their host name strings string-compare equal; or * A is a HDN string and has the form NB, where N is a non-empty name string, B has the form .B', and B' is a HDN string. (So, x.y.com domain-matches .Y.com but not Y.com.) Note that domain-match is not a commutative operation: a.b.c.com domain-matches .c.com, but not the reverse.
func CopyStringMap ¶
CopyStringMap returns a copy of the provided map[string]string such that reflect.DeepEqual returns true for the given map and the returned map. In particular, preserves nil input.
func CopyStringSlice ¶
CopyStringSlice copies the given []string such that reflect.DeepEqual returns true for the given slice and the returned slice. In particular, preserves nil slice input.
func Float64StableSum ¶
Float64StableSum returns the sum of the elements of the given []float64 in a relatively stable manner.
func FromDos ¶
FromDos performs like the "fromdos" tool on Linux: it converts line endings in the given string from Dos to Unix format.
func GetFormattedByteSize ¶
GetFormattedByteSize returns a formatted pretty string representation of the provided byte size. Eg: Input of 1024 would return "1.00KB".
func GetStackTrace ¶
func GetStackTrace() string
GetStackTrace returns the stacktrace including GetStackTrace itself.
func InsertString ¶
InsertString inserts the given string into the slice at the given index.
func InsertStringSorted ¶
InsertStringSorted inserts the given string into the sorted slice of strings if it does not already exist. Maintains sorted order.
func Int64Equal ¶
Int64Equal returns true if the int64 slices are equal.
func IntersectIntSets ¶
IntersectIntSets calculates the intersection of a list of integer sets.
func IsDirEmpty ¶
IsDirEmpty checks to see if the specified directory has any contents.
func IsNil ¶
func IsNil(i interface{}) bool
Returns true if i is nil or is an interface containing a nil or invalid value.
func IterTimeChunks ¶
func IterTimeChunks(start, end time.Time, chunkSize time.Duration, fn func(time.Time, time.Time) error) error
IterTimeChunks calls the given function for each time chunk of the given duration within the given time range.
func KeysOfIntSet ¶
KeysOfIntSet returns the keys of a set of strings represented by the keys of a map.
func KeysOfParamSet ¶
KeysOfParamSet returns the keys of a param set.
func LogErr ¶
func LogErr(err error)
LogErr logs err if it's not nil. This is intended to be used for calls where generally a returned error can be ignored.
func MD5FromReader ¶
MD5FromReader returns the MD5 hash of the content in the provided reader. If the writer w is not nil it will also write the content of the reader to w.
func MD5Sum ¶
MD5Sum returns the MD5 hash of the given value. It supports anything that can be encoded via bencode (https://en.wikipedia.org/wiki/Bencode).
func MaybeReadGobFile ¶
MaybeReadGobFile reads data from the given file into the given data structure. If the file does not exist, no error is returned and no data is written.
func NewThreadSafeWriter ¶
NewThreadSafeWriter returns a ThreadSafeWriter which wraps the given Writer.
func ParseIntSet ¶
ParseIntSet parses a string expression like "5", "3-8", or "3,4,9" into a slice of integers: [5], [3, 4, 5, 6, 7, 8], [3, 4, 9].
func Permute ¶
Permute returns all permutations of the given slice of ints. Duplicates in the input slice will result in duplicate permutations returned.
func PermuteStrings ¶
PermuteStrings returns all permutations of the given slice of strings. Duplicates in the input slice will result in duplicate permutations returned.
func RandomName ¶
func RandomName() string
RandomName returns a randomly-generated name of the form, "adjective-noun-number", using the default generator from the math/rand package.
func RandomNameR ¶
RandomNameR returns a randomly-generated name of the form, "adjective-noun-number", using the given math/rand.Rand instance.
func ReadGobFile ¶
ReadGobFile reads data from the given file into the given data structure.
func Remove ¶
func Remove(name string)
Remove removes the specified file and logs an error if one is returned.
func RemoveAll ¶
func RemoveAll(path string)
RemoveAll removes the specified path and logs an error if one is returned.
func Rename ¶
func Rename(oldpath, newpath string)
Rename renames the specified file and logs an error if one is returned.
func Repeat ¶
Repeat calls the provided function 'fn' immediately and then in intervals defined by 'interval'. If anything is sent on the provided stop channel, the iteration stops.
func RepeatCtx ¶
RepeatCtx calls the provided function 'fn' immediately and then in intervals defined by 'interval'. If the given context is canceled, the iteration stops.
func RepeatJoin ¶
RepeatJoin repeats a given string N times with the given separator between each instance.
func RoundUpToPowerOf2 ¶
RoundUpToPowerOf2 rounds the given int up to the nearest power of 2.
func SSliceCmp ¶
SSliceCmp compares two string slices by comparing each element in order. Returns -1 if the first slice is "less" than the second, 0 if they are equal, and 1 if the first slice is "greater" than the second.
func SSliceEqual ¶
func SafeAtoi ¶
SafeParseInt parses a string that is known to contain digits into an int. If the number is larger than MAX_INT, 0 will be returned after logging an error.
func StringToCodeName ¶
StringToCodeName returns a name generated from the source string. The string is hashed and used as the seed for a random number generator.
func TimeIsZero ¶
TimeIsZero returns true if the time.Time is a zero-value or corresponds to a zero Unix timestamp.
func TimeStamp ¶
Returns the current time in the units defined by the given target unit. e.g. TimeStamp(time.Millisecond) will return the time in Milliseconds. The result is always rounded down to the lowest integer from the representation in nano seconds.
func TimeStampMs ¶
func TimeStampMs() int64
Returns the current time in milliseconds since the epoch.
func TimeToUnixFloat ¶
TimeToUnixFloat takes a time.Time and returns a float64 representing a Unix timestamp.
func ToDos ¶
ToDos performs like the "todos" tool on Linux: it converts line endings in the given string from Unix to Dos format.
func Truncate ¶
Truncate the given string to the given length. If the string was shortened, change the last three characters to ellipses, unless the specified length is 3 or less.
func UnZip ¶
UnZip unzips the file specified in src into the 'dest' directory. Note: * The parent directory will be created using the mode of the first directory in the zip. * src could be partially populated if an error is returned.
func UnixFloatToTime ¶
UnixFloatToTime takes a float64 representing a Unix timestamp in seconds and returns a time.Time. Rounds to milliseconds.
func UnixMillisToTime ¶
UnixMillisToTime takes an int64 representing a Unix timestamp in milliseconds and returns a time.Time.
func ValidateCommit ¶
ValidateCommit returns true iff the given commit hash looks valid. Does not perform any check as to whether the commit means anything in a particular repository.
func WithBufferedWriter ¶
WithBufferedWriter is a helper for wrapping an io.Writer with a bufio.Writer.
func WithGzipWriter ¶
WithGzipWriter is a helper for wrapping an io.Writer with a gzip.Writer.
func WithReadFile ¶
WithReadFile opens the given file for reading and runs the given function.
func WithWriteFile ¶
WithWriteFile provides an interface for writing to a backing file using a temporary intermediate file for more atomicity in case a long-running write gets interrupted.
func WriteGobFile ¶
WriteGobFile writes the given data to the given file, using gob encoding.
Types ¶
type CondMonitor ¶
type CondMonitor struct {
// contains filtered or unexported fields
}
CondMonitor implements a monitor that limits the number of threads per int64-id that can concurrently enter a critical section. This could be used like this:
... mon := NewCondInt64Monitor(5) ... defer mon.Enter(id).Release() ...
This allows 5 threads for each value of id to enter the critical section which starts after the call to 'Enter' and ends when 'Release' is called.
func NewCondMonitor ¶
func NewCondMonitor(nConcurrent int) *CondMonitor
NewCondMonitor creates a new monitor with the given number of concurrent threads that can enter the critical section for every int64 value provided to the 'Enter' call.
func (*CondMonitor) Enter ¶
func (m *CondMonitor) Enter(id int64) MonitorRelease
Enter marks the start of a critical section. It limits the number of threads
type GobDecoder ¶
type GobDecoder struct {
// contains filtered or unexported fields
}
GobDecoder decodes bytes into structs via GOB decoding. Not safe for concurrent use.
Here's a template for writing a type-specific decoder:
FooDecoder decodes bytes into Foos via GOB decoding. Not safe for concurrent use.
type FooDecoder struct { *util.GobDecoder }
// NewFooDecoder returns a FooDecoder instance.
func NewFooDecoder() *FooDecoder { return &FooDecoder{ GobDecoder: util.NewGobDecoder(func() interface{} { return &Foo{} }, func(ch <-chan interface{}) interface{} { items := []*Foo{} for item := range ch { items = append(items, item.(*Foo)) } return items }), } }
// Result returns all decoded Foos provided to Process (in arbitrary order), or // any error encountered.
func (d *FooDecoder) Result() ([]*Foo, error) { res, err := d.GobDecoder.Result() if err != nil { return nil, err } return res.([]*Foo), nil }
func NewGobDecoder ¶
func NewGobDecoder(newItem func() interface{}, collect func(<-chan interface{}) interface{}) *GobDecoder
NewGobDecoder returns a GobDecoder instance. The first argument is a goroutine-safe function which returns a zero-valued instance of the type being decoded, eg.
func() interface{} { return &MyType{} }
The second argument is a function which collects decoded instances of that type from a channel and returns a slice, eg.
func(ch <-chan interface{}) interface{} { items := []*MyType{} for item := range ch { items = append(items, item.(*MyType)) } return items }
func (*GobDecoder) Process ¶
func (d *GobDecoder) Process(b []byte) bool
Process decodes the byte slice and includes it in Result() (in arbitrary order). Returns false if Result is certain to return an error. Caller must ensure b does not change until after Result() returns.
func (*GobDecoder) Result ¶
func (d *GobDecoder) Result() (interface{}, error)
Result returns all decoded items provided to Process (in arbitrary order), or any error encountered.
type GobEncoder ¶
type GobEncoder struct {
// contains filtered or unexported fields
}
GobEncoder encodes structs into bytes via GOB encoding. Not safe for concurrent use.
Here's a template for writing a type-specific encoder:
// FooEncoder encodes Foos into bytes via GOB encoding. Not safe for // concurrent use.
type FooEncoder { util.GobEncoder }
// Next returns one of the Foox provided to Process (in arbitrary order) and // its serialized bytes. If any items remain, returns the item, the // serialized bytes, nil. If all items have been returned, returns nil, nil, // nil. If an error is encountered, returns nil, nil, error.
func (e *FooEncoder) Next() (*Foo, []byte, error) { item, serialized, err := e.GobEncoder.Next() if err != nil { return nil, nil, err } else if item == nil { return nil, nil, nil } return item.(*Foo), serialized, nil }
func (*GobEncoder) Next ¶
func (e *GobEncoder) Next() (interface{}, []byte, error)
Next returns one of the items provided to Process (in arbitrary order) and its serialized bytes. If any items remain, returns the item, the serialized bytes, nil. If all items have been returned, returns nil, nil, nil. If an error is encountered, returns nil, nil, error.
func (*GobEncoder) Process ¶
func (e *GobEncoder) Process(item interface{}) bool
Process encodes the item into a byte slice that will be returned from Next() (in arbitrary order). Returns false if Next is certain to return an error. Caller must ensure item does not change until after the first call to Next(). May not be called after calling Next().
type Int64Slice ¶
type Int64Slice []int64
func (Int64Slice) Len ¶
func (p Int64Slice) Len() int
func (Int64Slice) Less ¶
func (p Int64Slice) Less(i, j int) bool
func (Int64Slice) Swap ¶
func (p Int64Slice) Swap(i, j int)
type LRUCache ¶
type LRUCache interface { // Add adds a key-value pair to the cache. Add(key, value interface{}) bool // Get returns a key value for the given cache. If ok is true // the fetch was succesfull. Get(key interface{}) (value interface{}, ok bool) // Len returns the current size of the cache. Len() int // Remove removes a key value pair from the cache. Remove(key interface{}) // Keys returns all the keys in the LRUCache. Keys() []interface{} }
Generic LRUCache interface.
type LRUCodec ¶
type LRUCodec interface { // Encode serializes the given value to a byte array (inverse of Decode). Encode(interface{}) ([]byte, error) // Decode deserializes the byte array to an instance of the type that // was passed to Encode in a prior call. Decode([]byte) (interface{}, error) }
LRUCodec converts serializes/deserializes an instance of a type to/from byte arrays. Encode and Decode have to be the inverse of each other.
type MemLRUCache ¶
type MemLRUCache struct {
// contains filtered or unexported fields
}
func NewMemLRUCache ¶
func NewMemLRUCache(maxEntries int) *MemLRUCache
func (*MemLRUCache) Add ¶
func (m *MemLRUCache) Add(key, value interface{}) bool
func (*MemLRUCache) Get ¶
func (m *MemLRUCache) Get(key interface{}) (value interface{}, ok bool)
func (*MemLRUCache) Keys ¶
func (m *MemLRUCache) Keys() []interface{}
func (*MemLRUCache) Len ¶
func (m *MemLRUCache) Len() int
func (*MemLRUCache) Remove ¶
func (m *MemLRUCache) Remove(key interface{})
type MonitorRelease ¶
type MonitorRelease func()
MonitorRelease is returned by the Enter call.
func (MonitorRelease) Release ¶
func (m MonitorRelease) Release()
Release is called to identify the end of the critical section.
type MultiWriter ¶
MultiWriter is like io.MultiWriter but attempts to write to all of the given io.Writers, even if writing to one fails.
type NamedErrGroup ¶
type NamedErrGroup struct {
// contains filtered or unexported fields
}
NamedErrGroup is like errgroup.Group, except each function in the group gets a name. It waits for all goroutines to finish and reports all errors by name.
func NewNamedErrGroup ¶
func NewNamedErrGroup() *NamedErrGroup
NewNamedErrGroup returns a NamedErrGroup instance.
func (*NamedErrGroup) Go ¶
func (g *NamedErrGroup) Go(name string, fn func() error)
Go runs the given function in a goroutine.
func (*NamedErrGroup) Wait ¶
func (g *NamedErrGroup) Wait() error
Wait waits for all of the goroutines to finish and reports any errors.
type StringSet ¶
StringSet is a set of strings, represented by the keys of a map.
func NewStringSet ¶
NewStringSet returns the given list(s) of strings as a StringSet.
func (StringSet) AddLists ¶
AddLists adds lists of strings to the StringSet and returns the receiving StringSet.
func (StringSet) Complement ¶
Complement returns a new StringSet containing all the original strings that are not in StringSet other
func (StringSet) Copy ¶
Copy returns a copy of the StringSet such that reflect.DeepEqual returns true for the original and copy. In particular, preserves nil input.
func (StringSet) Intersect ¶
Intersect returns a new StringSet containing all the original strings that are also in StringSet other
type TempRepo ¶
type TempRepo struct { // Root of unzipped Git repo. Dir string }
TempRepo is used to setup and teardown a temporary repo for unit testing.
func NewTempRepo ¶
func NewTempRepo() *TempRepo
NewTempRepo assumes the repo is called testrepo.zip and is in a directory called testdata under the directory of the unit test that is calling it.
The directory that was created is stored in TempRepo Path.
func NewTempRepoFrom ¶
NewTempRepoFrom returns a TempRepo instance based on the contents of the given zip file path. Unzips to a temporary directory which is stored in TempRepo.Dir.
type ThreadSafeWriter ¶
type ThreadSafeWriter struct {
// contains filtered or unexported fields
}
ThreadSafeWriter wraps an io.Writer and provides thread safety.