id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
16,400
jpillora/go-ogle-analytics
type-timing.go
TCPConnectTime
func (h *Timing) TCPConnectTime(tCPConnectTime int64) *Timing { h.tCPConnectTime = tCPConnectTime h.tCPConnectTimeSet = true return h }
go
func (h *Timing) TCPConnectTime(tCPConnectTime int64) *Timing { h.tCPConnectTime = tCPConnectTime h.tCPConnectTimeSet = true return h }
[ "func", "(", "h", "*", "Timing", ")", "TCPConnectTime", "(", "tCPConnectTime", "int64", ")", "*", "Timing", "{", "h", ".", "tCPConnectTime", "=", "tCPConnectTime", "\n", "h", ".", "tCPConnectTimeSet", "=", "true", "\n", "return", "h", "\n", "}" ]
// Specifies the time it took for a TCP connection to be made. // The value is in milliseconds.
[ "Specifies", "the", "time", "it", "took", "for", "a", "TCP", "connection", "to", "be", "made", ".", "The", "value", "is", "in", "milliseconds", "." ]
14b04e0594ef6a9fd943363b135656f0ec8c9d0e
https://github.com/jpillora/go-ogle-analytics/blob/14b04e0594ef6a9fd943363b135656f0ec8c9d0e/type-timing.go#L144-L148
16,401
jpillora/go-ogle-analytics
type-timing.go
ServerResponseTime
func (h *Timing) ServerResponseTime(serverResponseTime int64) *Timing { h.serverResponseTime = serverResponseTime h.serverResponseTimeSet = true return h }
go
func (h *Timing) ServerResponseTime(serverResponseTime int64) *Timing { h.serverResponseTime = serverResponseTime h.serverResponseTimeSet = true return h }
[ "func", "(", "h", "*", "Timing", ")", "ServerResponseTime", "(", "serverResponseTime", "int64", ")", "*", "Timing", "{", "h", ".", "serverResponseTime", "=", "serverResponseTime", "\n", "h", ".", "serverResponseTimeSet", "=", "true", "\n", "return", "h", "\n",...
// Specifies the time it took for the server to respond after // the connect time. The value is in milliseconds.
[ "Specifies", "the", "time", "it", "took", "for", "the", "server", "to", "respond", "after", "the", "connect", "time", ".", "The", "value", "is", "in", "milliseconds", "." ]
14b04e0594ef6a9fd943363b135656f0ec8c9d0e
https://github.com/jpillora/go-ogle-analytics/blob/14b04e0594ef6a9fd943363b135656f0ec8c9d0e/type-timing.go#L152-L156
16,402
jpillora/go-ogle-analytics
type-timing.go
DOMInteractiveTime
func (h *Timing) DOMInteractiveTime(dOMInteractiveTime int64) *Timing { h.dOMInteractiveTime = dOMInteractiveTime h.dOMInteractiveTimeSet = true return h }
go
func (h *Timing) DOMInteractiveTime(dOMInteractiveTime int64) *Timing { h.dOMInteractiveTime = dOMInteractiveTime h.dOMInteractiveTimeSet = true return h }
[ "func", "(", "h", "*", "Timing", ")", "DOMInteractiveTime", "(", "dOMInteractiveTime", "int64", ")", "*", "Timing", "{", "h", ".", "dOMInteractiveTime", "=", "dOMInteractiveTime", "\n", "h", ".", "dOMInteractiveTimeSet", "=", "true", "\n", "return", "h", "\n",...
// Specifies the time it took for Document.readyState to be // 'interactive'. The value is in milliseconds.
[ "Specifies", "the", "time", "it", "took", "for", "Document", ".", "readyState", "to", "be", "interactive", ".", "The", "value", "is", "in", "milliseconds", "." ]
14b04e0594ef6a9fd943363b135656f0ec8c9d0e
https://github.com/jpillora/go-ogle-analytics/blob/14b04e0594ef6a9fd943363b135656f0ec8c9d0e/type-timing.go#L160-L164
16,403
jpillora/go-ogle-analytics
type-timing.go
ContentLoadTime
func (h *Timing) ContentLoadTime(contentLoadTime int64) *Timing { h.contentLoadTime = contentLoadTime h.contentLoadTimeSet = true return h }
go
func (h *Timing) ContentLoadTime(contentLoadTime int64) *Timing { h.contentLoadTime = contentLoadTime h.contentLoadTimeSet = true return h }
[ "func", "(", "h", "*", "Timing", ")", "ContentLoadTime", "(", "contentLoadTime", "int64", ")", "*", "Timing", "{", "h", ".", "contentLoadTime", "=", "contentLoadTime", "\n", "h", ".", "contentLoadTimeSet", "=", "true", "\n", "return", "h", "\n", "}" ]
// Specifies the time it took for the DOMContentLoaded Event // to fire. The value is in milliseconds.
[ "Specifies", "the", "time", "it", "took", "for", "the", "DOMContentLoaded", "Event", "to", "fire", ".", "The", "value", "is", "in", "milliseconds", "." ]
14b04e0594ef6a9fd943363b135656f0ec8c9d0e
https://github.com/jpillora/go-ogle-analytics/blob/14b04e0594ef6a9fd943363b135656f0ec8c9d0e/type-timing.go#L168-L172
16,404
jpillora/go-ogle-analytics
type-transaction.go
Affiliation
func (h *Transaction) Affiliation(affiliation string) *Transaction { h.affiliation = affiliation h.affiliationSet = true return h }
go
func (h *Transaction) Affiliation(affiliation string) *Transaction { h.affiliation = affiliation h.affiliationSet = true return h }
[ "func", "(", "h", "*", "Transaction", ")", "Affiliation", "(", "affiliation", "string", ")", "*", "Transaction", "{", "h", ".", "affiliation", "=", "affiliation", "\n", "h", ".", "affiliationSet", "=", "true", "\n", "return", "h", "\n", "}" ]
// Specifies the affiliation or store name.
[ "Specifies", "the", "affiliation", "or", "store", "name", "." ]
14b04e0594ef6a9fd943363b135656f0ec8c9d0e
https://github.com/jpillora/go-ogle-analytics/blob/14b04e0594ef6a9fd943363b135656f0ec8c9d0e/type-transaction.go#L55-L59
16,405
jpillora/go-ogle-analytics
type-transaction.go
Revenue
func (h *Transaction) Revenue(revenue float64) *Transaction { h.revenue = revenue h.revenueSet = true return h }
go
func (h *Transaction) Revenue(revenue float64) *Transaction { h.revenue = revenue h.revenueSet = true return h }
[ "func", "(", "h", "*", "Transaction", ")", "Revenue", "(", "revenue", "float64", ")", "*", "Transaction", "{", "h", ".", "revenue", "=", "revenue", "\n", "h", ".", "revenueSet", "=", "true", "\n", "return", "h", "\n", "}" ]
// Specifies the total revenue associated with the transaction. // This value should include any shipping or tax costs.
[ "Specifies", "the", "total", "revenue", "associated", "with", "the", "transaction", ".", "This", "value", "should", "include", "any", "shipping", "or", "tax", "costs", "." ]
14b04e0594ef6a9fd943363b135656f0ec8c9d0e
https://github.com/jpillora/go-ogle-analytics/blob/14b04e0594ef6a9fd943363b135656f0ec8c9d0e/type-transaction.go#L63-L67
16,406
jpillora/go-ogle-analytics
type-transaction.go
Shipping
func (h *Transaction) Shipping(shipping float64) *Transaction { h.shipping = shipping h.shippingSet = true return h }
go
func (h *Transaction) Shipping(shipping float64) *Transaction { h.shipping = shipping h.shippingSet = true return h }
[ "func", "(", "h", "*", "Transaction", ")", "Shipping", "(", "shipping", "float64", ")", "*", "Transaction", "{", "h", ".", "shipping", "=", "shipping", "\n", "h", ".", "shippingSet", "=", "true", "\n", "return", "h", "\n", "}" ]
// Specifies the total shipping cost of the transaction.
[ "Specifies", "the", "total", "shipping", "cost", "of", "the", "transaction", "." ]
14b04e0594ef6a9fd943363b135656f0ec8c9d0e
https://github.com/jpillora/go-ogle-analytics/blob/14b04e0594ef6a9fd943363b135656f0ec8c9d0e/type-transaction.go#L70-L74
16,407
jpillora/go-ogle-analytics
type-transaction.go
Tax
func (h *Transaction) Tax(tax float64) *Transaction { h.tax = tax h.taxSet = true return h }
go
func (h *Transaction) Tax(tax float64) *Transaction { h.tax = tax h.taxSet = true return h }
[ "func", "(", "h", "*", "Transaction", ")", "Tax", "(", "tax", "float64", ")", "*", "Transaction", "{", "h", ".", "tax", "=", "tax", "\n", "h", ".", "taxSet", "=", "true", "\n", "return", "h", "\n", "}" ]
// Specifies the total tax of the transaction.
[ "Specifies", "the", "total", "tax", "of", "the", "transaction", "." ]
14b04e0594ef6a9fd943363b135656f0ec8c9d0e
https://github.com/jpillora/go-ogle-analytics/blob/14b04e0594ef6a9fd943363b135656f0ec8c9d0e/type-transaction.go#L77-L81
16,408
circonus-labs/circonusllhist
circonusllhist.go
New
func New() *Histogram { return &Histogram{ allocd: defaultHistSize, used: 0, bvs: make([]bin, defaultHistSize), useLocks: true, } }
go
func New() *Histogram { return &Histogram{ allocd: defaultHistSize, used: 0, bvs: make([]bin, defaultHistSize), useLocks: true, } }
[ "func", "New", "(", ")", "*", "Histogram", "{", "return", "&", "Histogram", "{", "allocd", ":", "defaultHistSize", ",", "used", ":", "0", ",", "bvs", ":", "make", "(", "[", "]", "bin", ",", "defaultHistSize", ")", ",", "useLocks", ":", "true", ",", ...
// New returns a new Histogram
[ "New", "returns", "a", "new", "Histogram" ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L402-L409
16,409
circonus-labs/circonusllhist
circonusllhist.go
NewNoLocks
func NewNoLocks() *Histogram { return &Histogram{ allocd: defaultHistSize, used: 0, bvs: make([]bin, defaultHistSize), useLocks: false, } }
go
func NewNoLocks() *Histogram { return &Histogram{ allocd: defaultHistSize, used: 0, bvs: make([]bin, defaultHistSize), useLocks: false, } }
[ "func", "NewNoLocks", "(", ")", "*", "Histogram", "{", "return", "&", "Histogram", "{", "allocd", ":", "defaultHistSize", ",", "used", ":", "0", ",", "bvs", ":", "make", "(", "[", "]", "bin", ",", "defaultHistSize", ")", ",", "useLocks", ":", "false", ...
// New returns a Histogram without locking
[ "New", "returns", "a", "Histogram", "without", "locking" ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L412-L419
16,410
circonus-labs/circonusllhist
circonusllhist.go
NewFromStrings
func NewFromStrings(strs []string, locks bool) (*Histogram, error) { bin, err := stringsToBin(strs) if err != nil { return nil, err } return newFromBins(bin, locks), nil }
go
func NewFromStrings(strs []string, locks bool) (*Histogram, error) { bin, err := stringsToBin(strs) if err != nil { return nil, err } return newFromBins(bin, locks), nil }
[ "func", "NewFromStrings", "(", "strs", "[", "]", "string", ",", "locks", "bool", ")", "(", "*", "Histogram", ",", "error", ")", "{", "bin", ",", "err", ":=", "stringsToBin", "(", "strs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",...
// NewFromStrings returns a Histogram created from DecStrings strings
[ "NewFromStrings", "returns", "a", "Histogram", "created", "from", "DecStrings", "strings" ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L422-L430
16,411
circonus-labs/circonusllhist
circonusllhist.go
newFromBins
func newFromBins(bins []bin, locks bool) *Histogram { return &Histogram{ allocd: uint16(len(bins) + 10), // pad it with 10 used: uint16(len(bins)), bvs: bins, useLocks: locks, } }
go
func newFromBins(bins []bin, locks bool) *Histogram { return &Histogram{ allocd: uint16(len(bins) + 10), // pad it with 10 used: uint16(len(bins)), bvs: bins, useLocks: locks, } }
[ "func", "newFromBins", "(", "bins", "[", "]", "bin", ",", "locks", "bool", ")", "*", "Histogram", "{", "return", "&", "Histogram", "{", "allocd", ":", "uint16", "(", "len", "(", "bins", ")", "+", "10", ")", ",", "// pad it with 10", "used", ":", "uin...
// NewFromBins returns a Histogram created from a bins struct slice
[ "NewFromBins", "returns", "a", "Histogram", "created", "from", "a", "bins", "struct", "slice" ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L433-L440
16,412
circonus-labs/circonusllhist
circonusllhist.go
RecordIntScale
func (h *Histogram) RecordIntScale(val int64, scale int) error { return h.RecordIntScales(val, scale, 1) }
go
func (h *Histogram) RecordIntScale(val int64, scale int) error { return h.RecordIntScales(val, scale, 1) }
[ "func", "(", "h", "*", "Histogram", ")", "RecordIntScale", "(", "val", "int64", ",", "scale", "int", ")", "error", "{", "return", "h", ".", "RecordIntScales", "(", "val", ",", "scale", ",", "1", ")", "\n", "}" ]
// RecordIntScale records an integer scaler value, returning an error if the // value is out of range.
[ "RecordIntScale", "records", "an", "integer", "scaler", "value", "returning", "an", "error", "if", "the", "value", "is", "out", "of", "range", "." ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L475-L477
16,413
circonus-labs/circonusllhist
circonusllhist.go
RecordDuration
func (h *Histogram) RecordDuration(v time.Duration) error { return h.RecordIntScale(int64(v), -9) }
go
func (h *Histogram) RecordDuration(v time.Duration) error { return h.RecordIntScale(int64(v), -9) }
[ "func", "(", "h", "*", "Histogram", ")", "RecordDuration", "(", "v", "time", ".", "Duration", ")", "error", "{", "return", "h", ".", "RecordIntScale", "(", "int64", "(", "v", ")", ",", "-", "9", ")", "\n", "}" ]
// RecordDuration records the given time.Duration in seconds, returning an error // if the value is out of range.
[ "RecordDuration", "records", "the", "given", "time", ".", "Duration", "in", "seconds", "returning", "an", "error", "if", "the", "value", "is", "out", "of", "range", "." ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L487-L489
16,414
circonus-labs/circonusllhist
circonusllhist.go
internalFind
func (h *Histogram) internalFind(hb *bin) (bool, uint16) { if h.used == 0 { return false, 0 } f2 := hb.newFastL2() if h.lookup[f2.l1] != nil { if idx := h.lookup[f2.l1][f2.l2]; idx != 0 { return true, idx - 1 } } rv := -1 idx := uint16(0) l := int(0) r := int(h.used - 1) for l < r { check := (r + l) / 2 rv = h.bvs[check].compare(hb) if rv == 0 { l = check r = check } else if rv > 0 { l = check + 1 } else { r = check - 1 } } if rv != 0 { rv = h.bvs[l].compare(hb) } idx = uint16(l) if rv == 0 { return true, idx } if rv < 0 { return false, idx } idx++ return false, idx }
go
func (h *Histogram) internalFind(hb *bin) (bool, uint16) { if h.used == 0 { return false, 0 } f2 := hb.newFastL2() if h.lookup[f2.l1] != nil { if idx := h.lookup[f2.l1][f2.l2]; idx != 0 { return true, idx - 1 } } rv := -1 idx := uint16(0) l := int(0) r := int(h.used - 1) for l < r { check := (r + l) / 2 rv = h.bvs[check].compare(hb) if rv == 0 { l = check r = check } else if rv > 0 { l = check + 1 } else { r = check - 1 } } if rv != 0 { rv = h.bvs[l].compare(hb) } idx = uint16(l) if rv == 0 { return true, idx } if rv < 0 { return false, idx } idx++ return false, idx }
[ "func", "(", "h", "*", "Histogram", ")", "internalFind", "(", "hb", "*", "bin", ")", "(", "bool", ",", "uint16", ")", "{", "if", "h", ".", "used", "==", "0", "{", "return", "false", ",", "0", "\n", "}", "\n", "f2", ":=", "hb", ".", "newFastL2",...
// find where a new bin should go
[ "find", "where", "a", "new", "bin", "should", "go" ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L518-L556
16,415
circonus-labs/circonusllhist
circonusllhist.go
RecordIntScales
func (h *Histogram) RecordIntScales(val int64, scale int, n int64) error { sign := int64(1) if val == 0 { scale = 0 } else { scale++ if val < 0 { val = 0 - val sign = -1 } if val < 10 { val *= 10 scale -= 1 } for val >= 100 { val /= 10 scale++ } } if scale < -128 { val = 0 scale = 0 } else if scale > 127 { val = 0xff scale = 0 } val *= sign hb := bin{val: int8(val), exp: int8(scale), count: 0} h.insertBin(&hb, n) return nil }
go
func (h *Histogram) RecordIntScales(val int64, scale int, n int64) error { sign := int64(1) if val == 0 { scale = 0 } else { scale++ if val < 0 { val = 0 - val sign = -1 } if val < 10 { val *= 10 scale -= 1 } for val >= 100 { val /= 10 scale++ } } if scale < -128 { val = 0 scale = 0 } else if scale > 127 { val = 0xff scale = 0 } val *= sign hb := bin{val: int8(val), exp: int8(scale), count: 0} h.insertBin(&hb, n) return nil }
[ "func", "(", "h", "*", "Histogram", ")", "RecordIntScales", "(", "val", "int64", ",", "scale", "int", ",", "n", "int64", ")", "error", "{", "sign", ":=", "int64", "(", "1", ")", "\n", "if", "val", "==", "0", "{", "scale", "=", "0", "\n", "}", "...
// RecordIntScales records n occurrences of the given value, returning an error if // the value is out of range.
[ "RecordIntScales", "records", "n", "occurrences", "of", "the", "given", "value", "returning", "an", "error", "if", "the", "value", "is", "out", "of", "range", "." ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L606-L636
16,416
circonus-labs/circonusllhist
circonusllhist.go
Copy
func (h *Histogram) Copy() *Histogram { if h.useLocks { h.mutex.Lock() defer h.mutex.Unlock() } newhist := New() newhist.allocd = h.allocd newhist.used = h.used newhist.useLocks = h.useLocks newhist.bvs = []bin{} for _, v := range h.bvs { newhist.bvs = append(newhist.bvs, v) } for i, u := range h.lookup { for _, v := range u { newhist.lookup[i] = append(newhist.lookup[i], v) } } return newhist }
go
func (h *Histogram) Copy() *Histogram { if h.useLocks { h.mutex.Lock() defer h.mutex.Unlock() } newhist := New() newhist.allocd = h.allocd newhist.used = h.used newhist.useLocks = h.useLocks newhist.bvs = []bin{} for _, v := range h.bvs { newhist.bvs = append(newhist.bvs, v) } for i, u := range h.lookup { for _, v := range u { newhist.lookup[i] = append(newhist.lookup[i], v) } } return newhist }
[ "func", "(", "h", "*", "Histogram", ")", "Copy", "(", ")", "*", "Histogram", "{", "if", "h", ".", "useLocks", "{", "h", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mutex", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "newhist"...
// Copy creates and returns an exact copy of a histogram.
[ "Copy", "creates", "and", "returns", "an", "exact", "copy", "of", "a", "histogram", "." ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L799-L822
16,417
circonus-labs/circonusllhist
circonusllhist.go
FullReset
func (h *Histogram) FullReset() { if h.useLocks { h.mutex.Lock() defer h.mutex.Unlock() } h.allocd = defaultHistSize h.bvs = make([]bin, defaultHistSize) h.used = 0 h.lookup = [256][]uint16{} }
go
func (h *Histogram) FullReset() { if h.useLocks { h.mutex.Lock() defer h.mutex.Unlock() } h.allocd = defaultHistSize h.bvs = make([]bin, defaultHistSize) h.used = 0 h.lookup = [256][]uint16{} }
[ "func", "(", "h", "*", "Histogram", ")", "FullReset", "(", ")", "{", "if", "h", ".", "useLocks", "{", "h", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mutex", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "h", ".", "allocd", ...
// FullReset resets a histogram to default empty values.
[ "FullReset", "resets", "a", "histogram", "to", "default", "empty", "values", "." ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L825-L835
16,418
circonus-labs/circonusllhist
circonusllhist.go
CopyAndReset
func (h *Histogram) CopyAndReset() *Histogram { newhist := h.Copy() h.FullReset() return newhist }
go
func (h *Histogram) CopyAndReset() *Histogram { newhist := h.Copy() h.FullReset() return newhist }
[ "func", "(", "h", "*", "Histogram", ")", "CopyAndReset", "(", ")", "*", "Histogram", "{", "newhist", ":=", "h", ".", "Copy", "(", ")", "\n", "h", ".", "FullReset", "(", ")", "\n", "return", "newhist", "\n", "}" ]
// CopyAndReset creates and returns an exact copy of a histogram, // and resets it to default empty values.
[ "CopyAndReset", "creates", "and", "returns", "an", "exact", "copy", "of", "a", "histogram", "and", "resets", "it", "to", "default", "empty", "values", "." ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L839-L843
16,419
circonus-labs/circonusllhist
circonusllhist.go
stringsToBin
func stringsToBin(strs []string) ([]bin, error) { bins := make([]bin, len(strs)) for i, str := range strs { // H[0.0e+00]=1 // H[0.0e+00]= <1> countString := strings.Split(str, "=")[1] countInt, err := strconv.ParseInt(countString, 10, 64) if err != nil { return nil, err } // H[ <0.0> e+00]=1 valString := strings.Split(strings.Split(strings.Split(str, "=")[0], "e")[0], "[")[1] valInt, err := strconv.ParseFloat(valString, 64) if err != nil { return nil, err } // H[0.0e <+00> ]=1 expString := strings.Split(strings.Split(strings.Split(str, "=")[0], "e")[1], "]")[0] expInt, err := strconv.ParseInt(expString, 10, 8) if err != nil { return nil, err } bins[i] = *newBinRaw(int8(valInt*10), int8(expInt), uint64(countInt)) } return bins, nil }
go
func stringsToBin(strs []string) ([]bin, error) { bins := make([]bin, len(strs)) for i, str := range strs { // H[0.0e+00]=1 // H[0.0e+00]= <1> countString := strings.Split(str, "=")[1] countInt, err := strconv.ParseInt(countString, 10, 64) if err != nil { return nil, err } // H[ <0.0> e+00]=1 valString := strings.Split(strings.Split(strings.Split(str, "=")[0], "e")[0], "[")[1] valInt, err := strconv.ParseFloat(valString, 64) if err != nil { return nil, err } // H[0.0e <+00> ]=1 expString := strings.Split(strings.Split(strings.Split(str, "=")[0], "e")[1], "]")[0] expInt, err := strconv.ParseInt(expString, 10, 8) if err != nil { return nil, err } bins[i] = *newBinRaw(int8(valInt*10), int8(expInt), uint64(countInt)) } return bins, nil }
[ "func", "stringsToBin", "(", "strs", "[", "]", "string", ")", "(", "[", "]", "bin", ",", "error", ")", "{", "bins", ":=", "make", "(", "[", "]", "bin", ",", "len", "(", "strs", ")", ")", "\n", "for", "i", ",", "str", ":=", "range", "strs", "{...
// takes the output of DecStrings and deserializes it into a Bin struct slice
[ "takes", "the", "output", "of", "DecStrings", "and", "deserializes", "it", "into", "a", "Bin", "struct", "slice" ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L863-L894
16,420
circonus-labs/circonusllhist
circonusllhist.go
UnmarshalJSON
func (h *Histogram) UnmarshalJSON(b []byte) error { var s string if err := json.Unmarshal(b, &s); err != nil { return err } data, err := base64.StdEncoding.DecodeString(s) if err != nil { return err } h, err = Deserialize(bytes.NewBuffer(data)) return err }
go
func (h *Histogram) UnmarshalJSON(b []byte) error { var s string if err := json.Unmarshal(b, &s); err != nil { return err } data, err := base64.StdEncoding.DecodeString(s) if err != nil { return err } h, err = Deserialize(bytes.NewBuffer(data)) return err }
[ "func", "(", "h", "*", "Histogram", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "var", "s", "string", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "s", ")", ";", "err", "!=", "nil", "{", "retur...
// UnmarshalJSON - histogram will come in a base64 encoded serialized form
[ "UnmarshalJSON", "-", "histogram", "will", "come", "in", "a", "base64", "encoded", "serialized", "form" ]
87d4d00b35adeefe4911ece727838749e0fab113
https://github.com/circonus-labs/circonusllhist/blob/87d4d00b35adeefe4911ece727838749e0fab113/circonusllhist.go#L897-L908
16,421
bep/gitmap
gitmap.go
Map
func Map(repository, revision string) (*GitRepo, error) { m := make(GitMap) // First get the top level repo path absRepoPath, err := filepath.Abs(repository) if err != nil { return nil, err } out, err := git("-C", repository, "rev-parse", "--show-cdup") if err != nil { return nil, err } cdUp := strings.TrimSpace(string(out)) topLevelPath := filepath.ToSlash(filepath.Join(absRepoPath, cdUp)) gitLogArgs := strings.Fields(fmt.Sprintf( `--name-only --no-merges --format=format:%%x1e%%H%%x1f%%h%%x1f%%s%%x1f%%aN%%x1f%%aE%%x1f%%ai %s`, revision, )) gitLogArgs = append([]string{"-C", repository, "log"}, gitLogArgs...) out, err = git(gitLogArgs...) if err != nil { return nil, err } entriesStr := string(out) entriesStr = strings.Trim(entriesStr, "\n\x1e'") entries := strings.Split(entriesStr, "\x1e") for _, e := range entries { lines := strings.Split(e, "\n") gitInfo, err := toGitInfo(lines[0]) if err != nil { return nil, err } for _, filename := range lines[1:] { filename := strings.TrimSpace(filename) if filename == "" { continue } if _, ok := m[filename]; !ok { m[filename] = gitInfo } } } return &GitRepo{Files: m, TopLevelAbsPath: topLevelPath}, nil }
go
func Map(repository, revision string) (*GitRepo, error) { m := make(GitMap) // First get the top level repo path absRepoPath, err := filepath.Abs(repository) if err != nil { return nil, err } out, err := git("-C", repository, "rev-parse", "--show-cdup") if err != nil { return nil, err } cdUp := strings.TrimSpace(string(out)) topLevelPath := filepath.ToSlash(filepath.Join(absRepoPath, cdUp)) gitLogArgs := strings.Fields(fmt.Sprintf( `--name-only --no-merges --format=format:%%x1e%%H%%x1f%%h%%x1f%%s%%x1f%%aN%%x1f%%aE%%x1f%%ai %s`, revision, )) gitLogArgs = append([]string{"-C", repository, "log"}, gitLogArgs...) out, err = git(gitLogArgs...) if err != nil { return nil, err } entriesStr := string(out) entriesStr = strings.Trim(entriesStr, "\n\x1e'") entries := strings.Split(entriesStr, "\x1e") for _, e := range entries { lines := strings.Split(e, "\n") gitInfo, err := toGitInfo(lines[0]) if err != nil { return nil, err } for _, filename := range lines[1:] { filename := strings.TrimSpace(filename) if filename == "" { continue } if _, ok := m[filename]; !ok { m[filename] = gitInfo } } } return &GitRepo{Files: m, TopLevelAbsPath: topLevelPath}, nil }
[ "func", "Map", "(", "repository", ",", "revision", "string", ")", "(", "*", "GitRepo", ",", "error", ")", "{", "m", ":=", "make", "(", "GitMap", ")", "\n\n", "// First get the top level repo path", "absRepoPath", ",", "err", ":=", "filepath", ".", "Abs", "...
// Map creates a GitRepo with a file map from the given repository path and revision. // Use blank or HEAD as revision for the currently active revision.
[ "Map", "creates", "a", "GitRepo", "with", "a", "file", "map", "from", "the", "given", "repository", "path", "and", "revision", ".", "Use", "blank", "or", "HEAD", "as", "revision", "for", "the", "currently", "active", "revision", "." ]
ecb6fe06dbfd6bb4225e7fda7dc15612ecc8d960
https://github.com/bep/gitmap/blob/ecb6fe06dbfd6bb4225e7fda7dc15612ecc8d960/gitmap.go#L52-L108
16,422
equinox-io/equinox
sdk.go
SetPublicKeyPEM
func (o *Options) SetPublicKeyPEM(pembytes []byte) error { block, _ := pem.Decode(pembytes) if block == nil { return errors.New("couldn't parse PEM data") } pub, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { return err } o.PublicKey = pub return nil }
go
func (o *Options) SetPublicKeyPEM(pembytes []byte) error { block, _ := pem.Decode(pembytes) if block == nil { return errors.New("couldn't parse PEM data") } pub, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { return err } o.PublicKey = pub return nil }
[ "func", "(", "o", "*", "Options", ")", "SetPublicKeyPEM", "(", "pembytes", "[", "]", "byte", ")", "error", "{", "block", ",", "_", ":=", "pem", ".", "Decode", "(", "pembytes", ")", "\n", "if", "block", "==", "nil", "{", "return", "errors", ".", "Ne...
// SetPublicKeyPEM is a convenience method to set the PublicKey property // used for checking a completed update's signature by parsing a // Public Key formatted as PEM data.
[ "SetPublicKeyPEM", "is", "a", "convenience", "method", "to", "set", "the", "PublicKey", "property", "used", "for", "checking", "a", "completed", "update", "s", "signature", "by", "parsing", "a", "Public", "Key", "formatted", "as", "PEM", "data", "." ]
69e912ff1f4b1d6900524412bb6cbde21392e093
https://github.com/equinox-io/equinox/blob/69e912ff1f4b1d6900524412bb6cbde21392e093/sdk.go#L110-L122
16,423
equinox-io/equinox
internal/go-update/apply.go
RollbackError
func RollbackError(err error) error { if err == nil { return nil } if rerr, ok := err.(*rollbackErr); ok { return rerr.rollbackErr } return nil }
go
func RollbackError(err error) error { if err == nil { return nil } if rerr, ok := err.(*rollbackErr); ok { return rerr.rollbackErr } return nil }
[ "func", "RollbackError", "(", "err", "error", ")", "error", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "rerr", ",", "ok", ":=", "err", ".", "(", "*", "rollbackErr", ")", ";", "ok", "{", "return", "rerr", ".", "rol...
// RollbackError takes an error value returned by Apply and returns the error, if any, // that occurred when attempting to roll back from a failed update. Applications should // always call this function on any non-nil errors returned by Apply. // // If no rollback was needed or if the rollback was successful, RollbackError returns nil, // otherwise it returns the error encountered when trying to roll back.
[ "RollbackError", "takes", "an", "error", "value", "returned", "by", "Apply", "and", "returns", "the", "error", "if", "any", "that", "occurred", "when", "attempting", "to", "roll", "back", "from", "a", "failed", "update", ".", "Applications", "should", "always"...
69e912ff1f4b1d6900524412bb6cbde21392e093
https://github.com/equinox-io/equinox/blob/69e912ff1f4b1d6900524412bb6cbde21392e093/internal/go-update/apply.go#L181-L189
16,424
equinox-io/equinox
internal/go-update/apply.go
CheckPermissions
func (o *Options) CheckPermissions() error { // get the directory the file exists in path, err := o.getPath() if err != nil { return err } fileDir := filepath.Dir(path) fileName := filepath.Base(path) // attempt to open a file in the file's directory newPath := filepath.Join(fileDir, fmt.Sprintf(".%s.new", fileName)) fp, err := openFile(newPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, o.TargetMode) if err != nil { return err } fp.Close() _ = os.Remove(newPath) return nil }
go
func (o *Options) CheckPermissions() error { // get the directory the file exists in path, err := o.getPath() if err != nil { return err } fileDir := filepath.Dir(path) fileName := filepath.Base(path) // attempt to open a file in the file's directory newPath := filepath.Join(fileDir, fmt.Sprintf(".%s.new", fileName)) fp, err := openFile(newPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, o.TargetMode) if err != nil { return err } fp.Close() _ = os.Remove(newPath) return nil }
[ "func", "(", "o", "*", "Options", ")", "CheckPermissions", "(", ")", "error", "{", "// get the directory the file exists in", "path", ",", "err", ":=", "o", ".", "getPath", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n"...
// CheckPermissions determines whether the process has the correct permissions to // perform the requested update. If the update can proceed, it returns nil, otherwise // it returns the error that would occur if an update were attempted.
[ "CheckPermissions", "determines", "whether", "the", "process", "has", "the", "correct", "permissions", "to", "perform", "the", "requested", "update", ".", "If", "the", "update", "can", "proceed", "it", "returns", "nil", "otherwise", "it", "returns", "the", "erro...
69e912ff1f4b1d6900524412bb6cbde21392e093
https://github.com/equinox-io/equinox/blob/69e912ff1f4b1d6900524412bb6cbde21392e093/internal/go-update/apply.go#L231-L251
16,425
equinox-io/equinox
internal/osext/osext.go
Executable
func Executable() (string, error) { p, err := executable() return filepath.Clean(p), err }
go
func Executable() (string, error) { p, err := executable() return filepath.Clean(p), err }
[ "func", "Executable", "(", ")", "(", "string", ",", "error", ")", "{", "p", ",", "err", ":=", "executable", "(", ")", "\n", "return", "filepath", ".", "Clean", "(", "p", ")", ",", "err", "\n", "}" ]
// Executable returns an absolute path that can be used to // re-invoke the current program. // It may not be valid after the current program exits.
[ "Executable", "returns", "an", "absolute", "path", "that", "can", "be", "used", "to", "re", "-", "invoke", "the", "current", "program", ".", "It", "may", "not", "be", "valid", "after", "the", "current", "program", "exits", "." ]
69e912ff1f4b1d6900524412bb6cbde21392e093
https://github.com/equinox-io/equinox/blob/69e912ff1f4b1d6900524412bb6cbde21392e093/internal/osext/osext.go#L13-L16
16,426
equinox-io/equinox
internal/go-update/verifier.go
NewRSAVerifier
func NewRSAVerifier() Verifier { return verifyFn(func(checksum, signature []byte, hash crypto.Hash, publicKey crypto.PublicKey) error { key, ok := publicKey.(*rsa.PublicKey) if !ok { return errors.New("not a valid RSA public key") } return rsa.VerifyPKCS1v15(key, hash, checksum, signature) }) }
go
func NewRSAVerifier() Verifier { return verifyFn(func(checksum, signature []byte, hash crypto.Hash, publicKey crypto.PublicKey) error { key, ok := publicKey.(*rsa.PublicKey) if !ok { return errors.New("not a valid RSA public key") } return rsa.VerifyPKCS1v15(key, hash, checksum, signature) }) }
[ "func", "NewRSAVerifier", "(", ")", "Verifier", "{", "return", "verifyFn", "(", "func", "(", "checksum", ",", "signature", "[", "]", "byte", ",", "hash", "crypto", ".", "Hash", ",", "publicKey", "crypto", ".", "PublicKey", ")", "error", "{", "key", ",", ...
// NewRSAVerifier returns a Verifier that uses the RSA algorithm to verify updates.
[ "NewRSAVerifier", "returns", "a", "Verifier", "that", "uses", "the", "RSA", "algorithm", "to", "verify", "updates", "." ]
69e912ff1f4b1d6900524412bb6cbde21392e093
https://github.com/equinox-io/equinox/blob/69e912ff1f4b1d6900524412bb6cbde21392e093/internal/go-update/verifier.go#L25-L33
16,427
equinox-io/equinox
internal/go-update/verifier.go
NewECDSAVerifier
func NewECDSAVerifier() Verifier { return verifyFn(func(checksum, signature []byte, hash crypto.Hash, publicKey crypto.PublicKey) error { key, ok := publicKey.(*ecdsa.PublicKey) if !ok { return errors.New("not a valid ECDSA public key") } var rs rsDER if _, err := asn1.Unmarshal(signature, &rs); err != nil { return err } if !ecdsa.Verify(key, checksum, rs.R, rs.S) { return errors.New("failed to verify ecsda signature") } return nil }) }
go
func NewECDSAVerifier() Verifier { return verifyFn(func(checksum, signature []byte, hash crypto.Hash, publicKey crypto.PublicKey) error { key, ok := publicKey.(*ecdsa.PublicKey) if !ok { return errors.New("not a valid ECDSA public key") } var rs rsDER if _, err := asn1.Unmarshal(signature, &rs); err != nil { return err } if !ecdsa.Verify(key, checksum, rs.R, rs.S) { return errors.New("failed to verify ecsda signature") } return nil }) }
[ "func", "NewECDSAVerifier", "(", ")", "Verifier", "{", "return", "verifyFn", "(", "func", "(", "checksum", ",", "signature", "[", "]", "byte", ",", "hash", "crypto", ".", "Hash", ",", "publicKey", "crypto", ".", "PublicKey", ")", "error", "{", "key", ","...
// NewECDSAVerifier returns a Verifier that uses the ECDSA algorithm to verify updates.
[ "NewECDSAVerifier", "returns", "a", "Verifier", "that", "uses", "the", "ECDSA", "algorithm", "to", "verify", "updates", "." ]
69e912ff1f4b1d6900524412bb6cbde21392e093
https://github.com/equinox-io/equinox/blob/69e912ff1f4b1d6900524412bb6cbde21392e093/internal/go-update/verifier.go#L41-L56
16,428
equinox-io/equinox
sdk_ctx.go
CheckContext
func CheckContext(ctx context.Context, appID string, opts Options) (Response, error) { var req, err = checkRequest(appID, &opts) if err != nil { return Response{}, err } return doCheckRequest(opts, req.WithContext(ctx)) }
go
func CheckContext(ctx context.Context, appID string, opts Options) (Response, error) { var req, err = checkRequest(appID, &opts) if err != nil { return Response{}, err } return doCheckRequest(opts, req.WithContext(ctx)) }
[ "func", "CheckContext", "(", "ctx", "context", ".", "Context", ",", "appID", "string", ",", "opts", "Options", ")", "(", "Response", ",", "error", ")", "{", "var", "req", ",", "err", "=", "checkRequest", "(", "appID", ",", "&", "opts", ")", "\n\n", "...
// CheckContext is like Check but includes a context.
[ "CheckContext", "is", "like", "Check", "but", "includes", "a", "context", "." ]
69e912ff1f4b1d6900524412bb6cbde21392e093
https://github.com/equinox-io/equinox/blob/69e912ff1f4b1d6900524412bb6cbde21392e093/sdk_ctx.go#L10-L18
16,429
equinox-io/equinox
sdk_ctx.go
ApplyContext
func (r Response) ApplyContext(ctx context.Context) error { var req, opts, err = r.applyRequest() if err != nil { return err } return r.applyUpdate(req.WithContext(ctx), opts) }
go
func (r Response) ApplyContext(ctx context.Context) error { var req, opts, err = r.applyRequest() if err != nil { return err } return r.applyUpdate(req.WithContext(ctx), opts) }
[ "func", "(", "r", "Response", ")", "ApplyContext", "(", "ctx", "context", ".", "Context", ")", "error", "{", "var", "req", ",", "opts", ",", "err", "=", "r", ".", "applyRequest", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n...
// ApplyContext is like Apply but includes a context.
[ "ApplyContext", "is", "like", "Apply", "but", "includes", "a", "context", "." ]
69e912ff1f4b1d6900524412bb6cbde21392e093
https://github.com/equinox-io/equinox/blob/69e912ff1f4b1d6900524412bb6cbde21392e093/sdk_ctx.go#L21-L29
16,430
spacemonkeygo/errors
errhttp/http.go
GetStatusCode
func GetStatusCode(err error, default_code int) int { rv := errors.GetData(err, statusCode) sc, ok := rv.(int) if ok { return sc } return default_code }
go
func GetStatusCode(err error, default_code int) int { rv := errors.GetData(err, statusCode) sc, ok := rv.(int) if ok { return sc } return default_code }
[ "func", "GetStatusCode", "(", "err", "error", ",", "default_code", "int", ")", "int", "{", "rv", ":=", "errors", ".", "GetData", "(", "err", ",", "statusCode", ")", "\n", "sc", ",", "ok", ":=", "rv", ".", "(", "int", ")", "\n", "if", "ok", "{", "...
// GetStatusCode will return the status code associated with an error, and // default_code if none is found.
[ "GetStatusCode", "will", "return", "the", "status", "code", "associated", "with", "an", "error", "and", "default_code", "if", "none", "is", "found", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errhttp/http.go#L56-L63
16,431
spacemonkeygo/errors
utils.go
LogWithStack
func LogWithStack(messages ...interface{}) { buf := make([]byte, Config.Stacklogsize) buf = buf[:runtime.Stack(buf, false)] LogMethod("%s\n%s", fmt.Sprintln(messages...), buf) }
go
func LogWithStack(messages ...interface{}) { buf := make([]byte, Config.Stacklogsize) buf = buf[:runtime.Stack(buf, false)] LogMethod("%s\n%s", fmt.Sprintln(messages...), buf) }
[ "func", "LogWithStack", "(", "messages", "...", "interface", "{", "}", ")", "{", "buf", ":=", "make", "(", "[", "]", "byte", ",", "Config", ".", "Stacklogsize", ")", "\n", "buf", "=", "buf", "[", ":", "runtime", ".", "Stack", "(", "buf", ",", "fals...
// LogWithStack will log the given messages with the current stack
[ "LogWithStack", "will", "log", "the", "given", "messages", "with", "the", "current", "stack" ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/utils.go#L32-L36
16,432
spacemonkeygo/errors
utils.go
CatchPanic
func CatchPanic(err_ref *error) { r := recover() if r == nil { return } err, ok := r.(error) if ok { *err_ref = PanicError.Wrap(err) return } *err_ref = PanicError.New("%v", r) }
go
func CatchPanic(err_ref *error) { r := recover() if r == nil { return } err, ok := r.(error) if ok { *err_ref = PanicError.Wrap(err) return } *err_ref = PanicError.New("%v", r) }
[ "func", "CatchPanic", "(", "err_ref", "*", "error", ")", "{", "r", ":=", "recover", "(", ")", "\n", "if", "r", "==", "nil", "{", "return", "\n", "}", "\n", "err", ",", "ok", ":=", "r", ".", "(", "error", ")", "\n", "if", "ok", "{", "*", "err_...
// CatchPanic can be used to catch panics and turn them into errors. See the // example.
[ "CatchPanic", "can", "be", "used", "to", "catch", "panics", "and", "turn", "them", "into", "errors", ".", "See", "the", "example", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/utils.go#L40-L51
16,433
spacemonkeygo/errors
utils.go
Add
func (e *ErrorGroup) Add(err error) { if err == nil { return } if e.limit > 0 && len(e.Errors) == e.limit { e.excess++ } else { e.Errors = append(e.Errors, err) } }
go
func (e *ErrorGroup) Add(err error) { if err == nil { return } if e.limit > 0 && len(e.Errors) == e.limit { e.excess++ } else { e.Errors = append(e.Errors, err) } }
[ "func", "(", "e", "*", "ErrorGroup", ")", "Add", "(", "err", "error", ")", "{", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n", "if", "e", ".", "limit", ">", "0", "&&", "len", "(", "e", ".", "Errors", ")", "==", "e", ".", "limit", ...
// Add is called with errors. nil errors are ignored.
[ "Add", "is", "called", "with", "errors", ".", "nil", "errors", "are", "ignored", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/utils.go#L74-L83
16,434
spacemonkeygo/errors
utils.go
Finalize
func (e *ErrorGroup) Finalize() error { if len(e.Errors) == 0 { return nil } if len(e.Errors) == 1 && e.excess == 0 { return e.Errors[0] } msgs := make([]string, 0, len(e.Errors)) for _, err := range e.Errors { msgs = append(msgs, err.Error()) } if e.excess > 0 { msgs = append(msgs, fmt.Sprintf("... and %d more.", e.excess)) e.excess = 0 } e.Errors = nil return ErrorGroupError.New(strings.Join(msgs, "\n")) }
go
func (e *ErrorGroup) Finalize() error { if len(e.Errors) == 0 { return nil } if len(e.Errors) == 1 && e.excess == 0 { return e.Errors[0] } msgs := make([]string, 0, len(e.Errors)) for _, err := range e.Errors { msgs = append(msgs, err.Error()) } if e.excess > 0 { msgs = append(msgs, fmt.Sprintf("... and %d more.", e.excess)) e.excess = 0 } e.Errors = nil return ErrorGroupError.New(strings.Join(msgs, "\n")) }
[ "func", "(", "e", "*", "ErrorGroup", ")", "Finalize", "(", ")", "error", "{", "if", "len", "(", "e", ".", "Errors", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "if", "len", "(", "e", ".", "Errors", ")", "==", "1", "&&", "e", ".", ...
// Finalize will collate all the found errors. If no errors were found, it will // return nil. If one error was found, it will be returned directly. Otherwise // an ErrorGroupError will be returned.
[ "Finalize", "will", "collate", "all", "the", "found", "errors", ".", "If", "no", "errors", "were", "found", "it", "will", "return", "nil", ".", "If", "one", "error", "was", "found", "it", "will", "be", "returned", "directly", ".", "Otherwise", "an", "Err...
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/utils.go#L88-L105
16,435
spacemonkeygo/errors
utils.go
Add
func (e *LoggingErrorGroup) Add(err error) { e.total++ if err != nil { LogMethod("%s: %s", e.name, err) e.failed++ } }
go
func (e *LoggingErrorGroup) Add(err error) { e.total++ if err != nil { LogMethod("%s: %s", e.name, err) e.failed++ } }
[ "func", "(", "e", "*", "LoggingErrorGroup", ")", "Add", "(", "err", "error", ")", "{", "e", ".", "total", "++", "\n", "if", "err", "!=", "nil", "{", "LogMethod", "(", "\"", "\"", ",", "e", ".", "name", ",", "err", ")", "\n", "e", ".", "failed",...
// Add will handle a given error. If the error is non-nil, total and failed // are both incremented and the error is logged. If the error is nil, only // total is incremented.
[ "Add", "will", "handle", "a", "given", "error", ".", "If", "the", "error", "is", "non", "-", "nil", "total", "and", "failed", "are", "both", "incremented", "and", "the", "error", "is", "logged", ".", "If", "the", "error", "is", "nil", "only", "total", ...
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/utils.go#L124-L130
16,436
spacemonkeygo/errors
utils.go
Finalize
func (e *LoggingErrorGroup) Finalize() (err error) { if e.failed > 0 { err = ErrorGroupError.New("%s: %d of %d failed.", e.name, e.failed, e.total) } e.total = 0 e.failed = 0 return err }
go
func (e *LoggingErrorGroup) Finalize() (err error) { if e.failed > 0 { err = ErrorGroupError.New("%s: %d of %d failed.", e.name, e.failed, e.total) } e.total = 0 e.failed = 0 return err }
[ "func", "(", "e", "*", "LoggingErrorGroup", ")", "Finalize", "(", ")", "(", "err", "error", ")", "{", "if", "e", ".", "failed", ">", "0", "{", "err", "=", "ErrorGroupError", ".", "New", "(", "\"", "\"", ",", "e", ".", "name", ",", "e", ".", "fa...
// Finalize returns no error if no failures were observed, otherwise it will // return an ErrorGroupError with statistics about the observed errors.
[ "Finalize", "returns", "no", "error", "if", "no", "failures", "were", "observed", "otherwise", "it", "will", "return", "an", "ErrorGroupError", "with", "statistics", "about", "the", "observed", "errors", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/utils.go#L134-L142
16,437
spacemonkeygo/errors
utils.go
Finalize
func Finalize(finalizers ...Finalizer) error { var errs ErrorGroup for _, finalizer := range finalizers { errs.Add(finalizer.Finalize()) } return errs.Finalize() }
go
func Finalize(finalizers ...Finalizer) error { var errs ErrorGroup for _, finalizer := range finalizers { errs.Add(finalizer.Finalize()) } return errs.Finalize() }
[ "func", "Finalize", "(", "finalizers", "...", "Finalizer", ")", "error", "{", "var", "errs", "ErrorGroup", "\n", "for", "_", ",", "finalizer", ":=", "range", "finalizers", "{", "errs", ".", "Add", "(", "finalizer", ".", "Finalize", "(", ")", ")", "\n", ...
// Finalize takes a group of ErrorGroups and joins them together into one error
[ "Finalize", "takes", "a", "group", "of", "ErrorGroups", "and", "joins", "them", "together", "into", "one", "error" ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/utils.go#L149-L155
16,438
spacemonkeygo/errors
errors.go
SetData
func SetData(key DataKey, value interface{}) ErrorOption { return func(m map[DataKey]interface{}) { m[key] = value } }
go
func SetData(key DataKey, value interface{}) ErrorOption { return func(m map[DataKey]interface{}) { m[key] = value } }
[ "func", "SetData", "(", "key", "DataKey", ",", "value", "interface", "{", "}", ")", "ErrorOption", "{", "return", "func", "(", "m", "map", "[", "DataKey", "]", "interface", "{", "}", ")", "{", "m", "[", "key", "]", "=", "value", "\n", "}", "\n", ...
// SetData will take the given value and store it with the error or error class // and its descendents associated with the given DataKey. Be sure to check out // the example. value can be nil to disable values for subhierarchies.
[ "SetData", "will", "take", "the", "given", "value", "and", "store", "it", "with", "the", "error", "or", "error", "class", "and", "its", "descendents", "associated", "with", "the", "given", "DataKey", ".", "Be", "sure", "to", "check", "out", "the", "example...
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L68-L72
16,439
spacemonkeygo/errors
errors.go
NewClass
func (parent *ErrorClass) NewClass(name string, options ...ErrorOption) *ErrorClass { ec := &ErrorClass{ parent: parent, name: name, data: make(map[DataKey]interface{})} for _, option := range options { option(ec.data) } if !boolWrapper(ec.data[disableInheritance], false) { // hoist options for speed for key, val := range parent.data { _, exists := ec.data[key] if !exists { ec.data[key] = val } } return ec } else { delete(ec.data, disableInheritance) } return ec }
go
func (parent *ErrorClass) NewClass(name string, options ...ErrorOption) *ErrorClass { ec := &ErrorClass{ parent: parent, name: name, data: make(map[DataKey]interface{})} for _, option := range options { option(ec.data) } if !boolWrapper(ec.data[disableInheritance], false) { // hoist options for speed for key, val := range parent.data { _, exists := ec.data[key] if !exists { ec.data[key] = val } } return ec } else { delete(ec.data, disableInheritance) } return ec }
[ "func", "(", "parent", "*", "ErrorClass", ")", "NewClass", "(", "name", "string", ",", "options", "...", "ErrorOption", ")", "*", "ErrorClass", "{", "ec", ":=", "&", "ErrorClass", "{", "parent", ":", "parent", ",", "name", ":", "name", ",", "data", ":"...
// NewClass creates an error class with the provided name and options. The new // class will descend from the receiver.
[ "NewClass", "creates", "an", "error", "class", "with", "the", "provided", "name", "and", "options", ".", "The", "new", "class", "will", "descend", "from", "the", "receiver", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L130-L156
16,440
spacemonkeygo/errors
errors.go
MustAddData
func (e *ErrorClass) MustAddData(key DataKey, value interface{}) { if _, ex := e.data[key]; ex { panic("key already exists") } e.data[key] = value }
go
func (e *ErrorClass) MustAddData(key DataKey, value interface{}) { if _, ex := e.data[key]; ex { panic("key already exists") } e.data[key] = value }
[ "func", "(", "e", "*", "ErrorClass", ")", "MustAddData", "(", "key", "DataKey", ",", "value", "interface", "{", "}", ")", "{", "if", "_", ",", "ex", ":=", "e", ".", "data", "[", "key", "]", ";", "ex", "{", "panic", "(", "\"", "\"", ")", "\n", ...
// MustAddData allows adding data key value pairs to error classes after they // are created. This is useful for allowing external packages add namespaced // values to errors defined outside of their package. It will panic if the // key is already set in the error class.
[ "MustAddData", "allows", "adding", "data", "key", "value", "pairs", "to", "error", "classes", "after", "they", "are", "created", ".", "This", "is", "useful", "for", "allowing", "external", "packages", "add", "namespaced", "values", "to", "errors", "defined", "...
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L162-L167
16,441
spacemonkeygo/errors
errors.go
Is
func (e *ErrorClass) Is(parent *ErrorClass) bool { for check := e; check != nil; check = check.parent { if check == parent { return true } } return false }
go
func (e *ErrorClass) Is(parent *ErrorClass) bool { for check := e; check != nil; check = check.parent { if check == parent { return true } } return false }
[ "func", "(", "e", "*", "ErrorClass", ")", "Is", "(", "parent", "*", "ErrorClass", ")", "bool", "{", "for", "check", ":=", "e", ";", "check", "!=", "nil", ";", "check", "=", "check", ".", "parent", "{", "if", "check", "==", "parent", "{", "return", ...
// Is returns true if the receiver class is or is a descendent of parent.
[ "Is", "returns", "true", "if", "the", "receiver", "class", "is", "or", "is", "a", "descendent", "of", "parent", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L189-L196
16,442
spacemonkeygo/errors
errors.go
String
func (e frame) String() string { if e.pc == 0 { return "unknown.unknown:0" } f := runtime.FuncForPC(e.pc) if f == nil { return "unknown.unknown:0" } file, line := f.FileLine(e.pc) return fmt.Sprintf("%s:%s:%d", f.Name(), filepath.Base(file), line) }
go
func (e frame) String() string { if e.pc == 0 { return "unknown.unknown:0" } f := runtime.FuncForPC(e.pc) if f == nil { return "unknown.unknown:0" } file, line := f.FileLine(e.pc) return fmt.Sprintf("%s:%s:%d", f.Name(), filepath.Base(file), line) }
[ "func", "(", "e", "frame", ")", "String", "(", ")", "string", "{", "if", "e", ".", "pc", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "f", ":=", "runtime", ".", "FuncForPC", "(", "e", ".", "pc", ")", "\n", "if", "f", "==", "nil", ...
// String returns a human readable form of the frame.
[ "String", "returns", "a", "human", "readable", "form", "of", "the", "frame", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L204-L214
16,443
spacemonkeygo/errors
errors.go
callerState
func callerState(depth int) frame { pc, _, _, ok := runtime.Caller(depth) if !ok { return frame{pc: 0} } return frame{pc: pc} }
go
func callerState(depth int) frame { pc, _, _, ok := runtime.Caller(depth) if !ok { return frame{pc: 0} } return frame{pc: pc} }
[ "func", "callerState", "(", "depth", "int", ")", "frame", "{", "pc", ",", "_", ",", "_", ",", "ok", ":=", "runtime", ".", "Caller", "(", "depth", ")", "\n", "if", "!", "ok", "{", "return", "frame", "{", "pc", ":", "0", "}", "\n", "}", "\n", "...
// callerState records the pc into an frame for two callers up.
[ "callerState", "records", "the", "pc", "into", "an", "frame", "for", "two", "callers", "up", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L217-L223
16,444
spacemonkeygo/errors
errors.go
record
func record(err error, depth int) error { if err == nil { return nil } cast, ok := err.(*Error) if !ok { return err } cast.exits = append(cast.exits, callerState(depth)) return cast }
go
func record(err error, depth int) error { if err == nil { return nil } cast, ok := err.(*Error) if !ok { return err } cast.exits = append(cast.exits, callerState(depth)) return cast }
[ "func", "record", "(", "err", "error", ",", "depth", "int", ")", "error", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "cast", ",", "ok", ":=", "err", ".", "(", "*", "Error", ")", "\n", "if", "!", "ok", "{", "return", ...
// record will record the pc at the given depth into the error if it is // capable of recording it.
[ "record", "will", "record", "the", "pc", "at", "the", "given", "depth", "into", "the", "error", "if", "it", "is", "capable", "of", "recording", "it", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L227-L237
16,445
spacemonkeygo/errors
errors.go
AttachStack
func AttachStack(err error) { if err == nil { return } cast, ok := err.(*Error) if !ok { return } if len(cast.stacks) < 1 { // only record stacks if this error was supposed to return } cast.stacks = append(cast.stacks, getStack(2)) }
go
func AttachStack(err error) { if err == nil { return } cast, ok := err.(*Error) if !ok { return } if len(cast.stacks) < 1 { // only record stacks if this error was supposed to return } cast.stacks = append(cast.stacks, getStack(2)) }
[ "func", "AttachStack", "(", "err", "error", ")", "{", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n", "cast", ",", "ok", ":=", "err", ".", "(", "*", "Error", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n", "if", "len", "...
// AttachStack adds another stack to the current error's stack trace if it // exists
[ "AttachStack", "adds", "another", "stack", "to", "the", "current", "error", "s", "stack", "trace", "if", "it", "exists" ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L340-L353
16,446
spacemonkeygo/errors
errors.go
WrapUnless
func (e *ErrorClass) WrapUnless(err error, classes ...*ErrorClass) error { return e.wrap(err, classes, nil) }
go
func (e *ErrorClass) WrapUnless(err error, classes ...*ErrorClass) error { return e.wrap(err, classes, nil) }
[ "func", "(", "e", "*", "ErrorClass", ")", "WrapUnless", "(", "err", "error", ",", "classes", "...", "*", "ErrorClass", ")", "error", "{", "return", "e", ".", "wrap", "(", "err", ",", "classes", ",", "nil", ")", "\n", "}" ]
// WrapUnless wraps the given error in the receiver error class unless the // error is already an instance of one of the provided error classes.
[ "WrapUnless", "wraps", "the", "given", "error", "in", "the", "receiver", "error", "class", "unless", "the", "error", "is", "already", "an", "instance", "of", "one", "of", "the", "provided", "error", "classes", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L357-L359
16,447
spacemonkeygo/errors
errors.go
Wrap
func (e *ErrorClass) Wrap(err error, options ...ErrorOption) error { return e.wrap(err, nil, options) }
go
func (e *ErrorClass) Wrap(err error, options ...ErrorOption) error { return e.wrap(err, nil, options) }
[ "func", "(", "e", "*", "ErrorClass", ")", "Wrap", "(", "err", "error", ",", "options", "...", "ErrorOption", ")", "error", "{", "return", "e", ".", "wrap", "(", "err", ",", "nil", ",", "options", ")", "\n", "}" ]
// Wrap wraps the given error in the receiver error class with the provided // error-specific options.
[ "Wrap", "wraps", "the", "given", "error", "in", "the", "receiver", "error", "class", "with", "the", "provided", "error", "-", "specific", "options", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L363-L365
16,448
spacemonkeygo/errors
errors.go
New
func (e *ErrorClass) New(format string, args ...interface{}) error { return e.wrap(fmt.Errorf(format, args...), nil, nil) }
go
func (e *ErrorClass) New(format string, args ...interface{}) error { return e.wrap(fmt.Errorf(format, args...), nil, nil) }
[ "func", "(", "e", "*", "ErrorClass", ")", "New", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "error", "{", "return", "e", ".", "wrap", "(", "fmt", ".", "Errorf", "(", "format", ",", "args", "...", ")", ",", "nil", ","...
// New makes a new error type. It takes a format string.
[ "New", "makes", "a", "new", "error", "type", ".", "It", "takes", "a", "format", "string", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L368-L370
16,449
spacemonkeygo/errors
errors.go
NewWith
func (e *ErrorClass) NewWith(message string, options ...ErrorOption) error { return e.wrap(errors.New(message), nil, options) }
go
func (e *ErrorClass) NewWith(message string, options ...ErrorOption) error { return e.wrap(errors.New(message), nil, options) }
[ "func", "(", "e", "*", "ErrorClass", ")", "NewWith", "(", "message", "string", ",", "options", "...", "ErrorOption", ")", "error", "{", "return", "e", ".", "wrap", "(", "errors", ".", "New", "(", "message", ")", ",", "nil", ",", "options", ")", "\n",...
// NewWith makes a new error type with the provided error-specific options.
[ "NewWith", "makes", "a", "new", "error", "type", "with", "the", "provided", "error", "-", "specific", "options", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L373-L375
16,450
spacemonkeygo/errors
errors.go
Error
func (e *Error) Error() string { message := strings.TrimRight(e.err.Error(), "\n ") if strings.Contains(message, "\n") { message = fmt.Sprintf("%s:\n %s", e.class.String(), strings.Replace(message, "\n", "\n ", -1)) } else { message = fmt.Sprintf("%s: %s", e.class.String(), message) } if stack := e.Stack(); stack != "" { message = fmt.Sprintf( "%s\n\"%s\" backtrace:\n%s", message, e.class, stack) } if exits := e.Exits(); exits != "" { message = fmt.Sprintf( "%s\n\"%s\" exits:\n%s", message, e.class, exits) } return message }
go
func (e *Error) Error() string { message := strings.TrimRight(e.err.Error(), "\n ") if strings.Contains(message, "\n") { message = fmt.Sprintf("%s:\n %s", e.class.String(), strings.Replace(message, "\n", "\n ", -1)) } else { message = fmt.Sprintf("%s: %s", e.class.String(), message) } if stack := e.Stack(); stack != "" { message = fmt.Sprintf( "%s\n\"%s\" backtrace:\n%s", message, e.class, stack) } if exits := e.Exits(); exits != "" { message = fmt.Sprintf( "%s\n\"%s\" exits:\n%s", message, e.class, exits) } return message }
[ "func", "(", "e", "*", "Error", ")", "Error", "(", ")", "string", "{", "message", ":=", "strings", ".", "TrimRight", "(", "e", ".", "err", ".", "Error", "(", ")", ",", "\"", "\\n", "\"", ")", "\n", "if", "strings", ".", "Contains", "(", "message"...
// Error conforms to the error interface. Error will return the backtrace if // it was captured and any recorded exits.
[ "Error", "conforms", "to", "the", "error", "interface", ".", "Error", "will", "return", "the", "backtrace", "if", "it", "was", "captured", "and", "any", "recorded", "exits", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L379-L396
16,451
spacemonkeygo/errors
errors.go
Message
func (e *Error) Message() string { message := strings.TrimRight(GetMessage(e.err), "\n ") if strings.Contains(message, "\n") { return fmt.Sprintf("%s:\n %s", e.class.String(), strings.Replace(message, "\n", "\n ", -1)) } return fmt.Sprintf("%s: %s", e.class.String(), message) }
go
func (e *Error) Message() string { message := strings.TrimRight(GetMessage(e.err), "\n ") if strings.Contains(message, "\n") { return fmt.Sprintf("%s:\n %s", e.class.String(), strings.Replace(message, "\n", "\n ", -1)) } return fmt.Sprintf("%s: %s", e.class.String(), message) }
[ "func", "(", "e", "*", "Error", ")", "Message", "(", ")", "string", "{", "message", ":=", "strings", ".", "TrimRight", "(", "GetMessage", "(", "e", ".", "err", ")", ",", "\"", "\\n", "\"", ")", "\n", "if", "strings", ".", "Contains", "(", "message"...
// Message returns just the error message without the backtrace or exits.
[ "Message", "returns", "just", "the", "error", "message", "without", "the", "backtrace", "or", "exits", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L399-L406
16,452
spacemonkeygo/errors
errors.go
WrappedErr
func WrappedErr(err error) error { cast, ok := err.(*Error) if !ok { return err } return cast.WrappedErr() }
go
func WrappedErr(err error) error { cast, ok := err.(*Error) if !ok { return err } return cast.WrappedErr() }
[ "func", "WrappedErr", "(", "err", "error", ")", "error", "{", "cast", ",", "ok", ":=", "err", ".", "(", "*", "Error", ")", "\n", "if", "!", "ok", "{", "return", "err", "\n", "}", "\n", "return", "cast", ".", "WrappedErr", "(", ")", "\n", "}" ]
// WrappedErr returns the wrapped error, if the current error is simply // wrapping some previously returned error or system error. If the error isn't // hierarchical it is just returned.
[ "WrappedErr", "returns", "the", "wrapped", "error", "if", "the", "current", "error", "is", "simply", "wrapping", "some", "previously", "returned", "error", "or", "system", "error", ".", "If", "the", "error", "isn", "t", "hierarchical", "it", "is", "just", "r...
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L418-L424
16,453
spacemonkeygo/errors
errors.go
GetClass
func GetClass(err error) *ErrorClass { if err == nil { return nil } cast, ok := err.(*Error) if !ok { return findSystemErrorClass(err) } return cast.class }
go
func GetClass(err error) *ErrorClass { if err == nil { return nil } cast, ok := err.(*Error) if !ok { return findSystemErrorClass(err) } return cast.class }
[ "func", "GetClass", "(", "err", "error", ")", "*", "ErrorClass", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "cast", ",", "ok", ":=", "err", ".", "(", "*", "Error", ")", "\n", "if", "!", "ok", "{", "return", "findSystemE...
// GetClass will return the appropriate error class for the given error. // If the error is not nil, GetClass always returns a hierarchical error class, // and even attempts to determine a class for common system error types.
[ "GetClass", "will", "return", "the", "appropriate", "error", "class", "for", "the", "given", "error", ".", "If", "the", "error", "is", "not", "nil", "GetClass", "always", "returns", "a", "hierarchical", "error", "class", "and", "even", "attempts", "to", "det...
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L441-L450
16,454
spacemonkeygo/errors
errors.go
Stack
func (e *Error) Stack() string { if len(e.stacks) > 0 { var frames []string for _, stack := range e.stacks { if frames == nil { frames = make([]string, 0, len(stack)) } else { frames = append(frames, "----- attached stack -----") } for _, f := range stack { frames = append(frames, f.String()) } } return strings.Join(frames, "\n") } return "" }
go
func (e *Error) Stack() string { if len(e.stacks) > 0 { var frames []string for _, stack := range e.stacks { if frames == nil { frames = make([]string, 0, len(stack)) } else { frames = append(frames, "----- attached stack -----") } for _, f := range stack { frames = append(frames, f.String()) } } return strings.Join(frames, "\n") } return "" }
[ "func", "(", "e", "*", "Error", ")", "Stack", "(", ")", "string", "{", "if", "len", "(", "e", ".", "stacks", ")", ">", "0", "{", "var", "frames", "[", "]", "string", "\n", "for", "_", ",", "stack", ":=", "range", "e", ".", "stacks", "{", "if"...
// Stack will return the stack associated with the error if one is found. You // probably want the package-level GetStack.
[ "Stack", "will", "return", "the", "stack", "associated", "with", "the", "error", "if", "one", "is", "found", ".", "You", "probably", "want", "the", "package", "-", "level", "GetStack", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L454-L470
16,455
spacemonkeygo/errors
errors.go
GetStack
func GetStack(err error) string { if err == nil { return "" } cast, ok := err.(*Error) if !ok { return "" } return cast.Stack() }
go
func GetStack(err error) string { if err == nil { return "" } cast, ok := err.(*Error) if !ok { return "" } return cast.Stack() }
[ "func", "GetStack", "(", "err", "error", ")", "string", "{", "if", "err", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "cast", ",", "ok", ":=", "err", ".", "(", "*", "Error", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ...
// GetStack will return the stack associated with the error if one is found.
[ "GetStack", "will", "return", "the", "stack", "associated", "with", "the", "error", "if", "one", "is", "found", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L473-L482
16,456
spacemonkeygo/errors
errors.go
Exits
func (e *Error) Exits() string { if len(e.exits) > 0 { exits := make([]string, len(e.exits)) for i, ex := range e.exits { exits[i] = ex.String() } return strings.Join(exits, "\n") } return "" }
go
func (e *Error) Exits() string { if len(e.exits) > 0 { exits := make([]string, len(e.exits)) for i, ex := range e.exits { exits[i] = ex.String() } return strings.Join(exits, "\n") } return "" }
[ "func", "(", "e", "*", "Error", ")", "Exits", "(", ")", "string", "{", "if", "len", "(", "e", ".", "exits", ")", ">", "0", "{", "exits", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "e", ".", "exits", ")", ")", "\n", "for", "i", ...
// Exits will return the exits recorded on the error if any are found. You // probably want the package-level GetExits.
[ "Exits", "will", "return", "the", "exits", "recorded", "on", "the", "error", "if", "any", "are", "found", ".", "You", "probably", "want", "the", "package", "-", "level", "GetExits", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L486-L495
16,457
spacemonkeygo/errors
errors.go
GetExits
func GetExits(err error) string { if err == nil { return "" } cast, ok := err.(*Error) if !ok { return "" } return cast.Exits() }
go
func GetExits(err error) string { if err == nil { return "" } cast, ok := err.(*Error) if !ok { return "" } return cast.Exits() }
[ "func", "GetExits", "(", "err", "error", ")", "string", "{", "if", "err", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "cast", ",", "ok", ":=", "err", ".", "(", "*", "Error", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ...
// GetExits will return the exits recorded on the error if any are found.
[ "GetExits", "will", "return", "the", "exits", "recorded", "on", "the", "error", "if", "any", "are", "found", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L498-L507
16,458
spacemonkeygo/errors
errors.go
GetMessage
func GetMessage(err error) string { if err == nil { return "" } cast, ok := err.(*Error) if !ok { return err.Error() } return cast.Message() }
go
func GetMessage(err error) string { if err == nil { return "" } cast, ok := err.(*Error) if !ok { return err.Error() } return cast.Message() }
[ "func", "GetMessage", "(", "err", "error", ")", "string", "{", "if", "err", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "cast", ",", "ok", ":=", "err", ".", "(", "*", "Error", ")", "\n", "if", "!", "ok", "{", "return", "err", ".", ...
// GetMessage returns just the error message without the backtrace or exits.
[ "GetMessage", "returns", "just", "the", "error", "message", "without", "the", "backtrace", "or", "exits", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L510-L519
16,459
spacemonkeygo/errors
errors.go
Is
func (e *Error) Is(ec *ErrorClass, opts ...EquivalenceOption) bool { return ec.Contains(e, opts...) }
go
func (e *Error) Is(ec *ErrorClass, opts ...EquivalenceOption) bool { return ec.Contains(e, opts...) }
[ "func", "(", "e", "*", "Error", ")", "Is", "(", "ec", "*", "ErrorClass", ",", "opts", "...", "EquivalenceOption", ")", "bool", "{", "return", "ec", ".", "Contains", "(", "e", ",", "opts", "...", ")", "\n", "}" ]
// Is returns whether or not an error belongs to a specific class. Typically // you should use Contains instead.
[ "Is", "returns", "whether", "or", "not", "an", "error", "belongs", "to", "a", "specific", "class", ".", "Typically", "you", "should", "use", "Contains", "instead", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L540-L542
16,460
spacemonkeygo/errors
errors.go
Contains
func (e *ErrorClass) Contains(err error, opts ...EquivalenceOption) bool { if err == nil { return false } cast, ok := err.(*Error) if !ok { return findSystemErrorClass(err).Is(e) } if cast.class.Is(e) { return true } if combineEquivOpts(opts)&IncludeWrapped == 0 { return false } return e.Contains(cast.err, opts...) }
go
func (e *ErrorClass) Contains(err error, opts ...EquivalenceOption) bool { if err == nil { return false } cast, ok := err.(*Error) if !ok { return findSystemErrorClass(err).Is(e) } if cast.class.Is(e) { return true } if combineEquivOpts(opts)&IncludeWrapped == 0 { return false } return e.Contains(cast.err, opts...) }
[ "func", "(", "e", "*", "ErrorClass", ")", "Contains", "(", "err", "error", ",", "opts", "...", "EquivalenceOption", ")", "bool", "{", "if", "err", "==", "nil", "{", "return", "false", "\n", "}", "\n", "cast", ",", "ok", ":=", "err", ".", "(", "*", ...
// Contains returns whether or not the receiver error class contains the given // error instance.
[ "Contains", "returns", "whether", "or", "not", "the", "receiver", "error", "class", "contains", "the", "given", "error", "instance", "." ]
9064522e9fd1cda39b0ea2484105af3c66410fb3
https://github.com/spacemonkeygo/errors/blob/9064522e9fd1cda39b0ea2484105af3c66410fb3/errors.go#L546-L561
16,461
rogpeppe/fastuuid
uuid.go
MustNewGenerator
func MustNewGenerator() *Generator { g, err := NewGenerator() if err != nil { panic(err) } return g }
go
func MustNewGenerator() *Generator { g, err := NewGenerator() if err != nil { panic(err) } return g }
[ "func", "MustNewGenerator", "(", ")", "*", "Generator", "{", "g", ",", "err", ":=", "NewGenerator", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "g", "\n", "}" ]
// MustNewGenerator is like NewGenerator // but panics on failure.
[ "MustNewGenerator", "is", "like", "NewGenerator", "but", "panics", "on", "failure", "." ]
d61b6ae132d93dcb396be506396bf9a5127a41aa
https://github.com/rogpeppe/fastuuid/blob/d61b6ae132d93dcb396be506396bf9a5127a41aa/uuid.go#L42-L48
16,462
rogpeppe/fastuuid
uuid.go
Next
func (g *Generator) Next() [24]byte { x := atomic.AddUint64(&g.counter, 1) var counterBytes [8]byte binary.LittleEndian.PutUint64(counterBytes[:], x) uuid := g.seed for i, b := range counterBytes { uuid[i] ^= b } return uuid }
go
func (g *Generator) Next() [24]byte { x := atomic.AddUint64(&g.counter, 1) var counterBytes [8]byte binary.LittleEndian.PutUint64(counterBytes[:], x) uuid := g.seed for i, b := range counterBytes { uuid[i] ^= b } return uuid }
[ "func", "(", "g", "*", "Generator", ")", "Next", "(", ")", "[", "24", "]", "byte", "{", "x", ":=", "atomic", ".", "AddUint64", "(", "&", "g", ".", "counter", ",", "1", ")", "\n", "var", "counterBytes", "[", "8", "]", "byte", "\n", "binary", "."...
// Next returns the next UUID from the generator. // Only the first 8 bytes can differ from the previous // UUID, so taking a slice of the first 16 bytes // is sufficient to provide a somewhat less secure 128 bit UUID. // // It is OK to call this method concurrently.
[ "Next", "returns", "the", "next", "UUID", "from", "the", "generator", ".", "Only", "the", "first", "8", "bytes", "can", "differ", "from", "the", "previous", "UUID", "so", "taking", "a", "slice", "of", "the", "first", "16", "bytes", "is", "sufficient", "t...
d61b6ae132d93dcb396be506396bf9a5127a41aa
https://github.com/rogpeppe/fastuuid/blob/d61b6ae132d93dcb396be506396bf9a5127a41aa/uuid.go#L56-L66
16,463
karlkfi/inject
definition.go
Resolve
func (d *definition) Resolve(g Graph) reflect.Value { if d.value != nil { // already resolved return *d.value } value := d.provider.Provide(g) obj, ok := value.Interface().(Initializable) if ok && obj != nil { obj.Initialize() } // cache the result d.value = &value // update the ptr value reflect.ValueOf(d.ptr).Elem().Set(value) return value }
go
func (d *definition) Resolve(g Graph) reflect.Value { if d.value != nil { // already resolved return *d.value } value := d.provider.Provide(g) obj, ok := value.Interface().(Initializable) if ok && obj != nil { obj.Initialize() } // cache the result d.value = &value // update the ptr value reflect.ValueOf(d.ptr).Elem().Set(value) return value }
[ "func", "(", "d", "*", "definition", ")", "Resolve", "(", "g", "Graph", ")", "reflect", ".", "Value", "{", "if", "d", ".", "value", "!=", "nil", "{", "// already resolved", "return", "*", "d", ".", "value", "\n", "}", "\n\n", "value", ":=", "d", "....
// Resolve calls the provider, initializes the result, and populates the pointer with the result value
[ "Resolve", "calls", "the", "provider", "initializes", "the", "result", "and", "populates", "the", "pointer", "with", "the", "result", "value" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/definition.go#L42-L62
16,464
karlkfi/inject
definition.go
Obscure
func (d *definition) Obscure(g Graph) { if d.value == nil { // already obscured return } obj, ok := d.value.Interface().(Finalizable) // uncache the result d.value = nil // zero out the ptr value ptrValue := reflect.ValueOf(d.ptr).Elem() ptrValue.Set(reflect.Zero(ptrValue.Type())) if ok && obj != nil { obj.Finalize() } }
go
func (d *definition) Obscure(g Graph) { if d.value == nil { // already obscured return } obj, ok := d.value.Interface().(Finalizable) // uncache the result d.value = nil // zero out the ptr value ptrValue := reflect.ValueOf(d.ptr).Elem() ptrValue.Set(reflect.Zero(ptrValue.Type())) if ok && obj != nil { obj.Finalize() } }
[ "func", "(", "d", "*", "definition", ")", "Obscure", "(", "g", "Graph", ")", "{", "if", "d", ".", "value", "==", "nil", "{", "// already obscured", "return", "\n", "}", "\n\n", "obj", ",", "ok", ":=", "d", ".", "value", ".", "Interface", "(", ")", ...
// Obscure zeros out the pointer value and finalizes its previous value
[ "Obscure", "zeros", "out", "the", "pointer", "value", "and", "finalizes", "its", "previous", "value" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/definition.go#L65-L83
16,465
karlkfi/inject
provider.go
NewProvider
func NewProvider(constructor interface{}, argPtrs ...interface{}) Provider { fnValue := reflect.ValueOf(constructor) if fnValue.Kind() != reflect.Func { panic(fmt.Sprintf("constructor (%v) is not a function, found %v", fnValue, fnValue.Kind())) } fnType := reflect.TypeOf(constructor) if fnType.NumOut() != 1 { panic(fmt.Sprintf("constructor must have exactly 1 return value, found %v", fnType.NumOut())) } argCount := fnType.NumIn() if !fnValue.Type().IsVariadic() && argCount != len(argPtrs) { panic(fmt.Sprintf("argPtrs (%d) must match constructor arguments (%d)", len(argPtrs), argCount)) } var kind reflect.Kind for i, argPtr := range argPtrs { isVariadic := fnValue.Type().IsVariadic() && (fnType.NumIn() == 1 || i >= fnType.NumIn()) if i < fnType.NumIn() { kind = fnType.In(i).Kind() } else { kind = fnType.In(fnType.NumIn() - 1).Kind() } if reflect.TypeOf(argPtr).Kind() != reflect.Ptr { panic(fmt.Sprintf("argPtrs must all be pointers, found %v", reflect.TypeOf(argPtr))) } if !isVariadic && reflect.ValueOf(argPtr).Elem().Kind() != kind { panic("argPtrs must match constructor argument types") } } return provider{ constructor: constructor, argPtrs: argPtrs, } }
go
func NewProvider(constructor interface{}, argPtrs ...interface{}) Provider { fnValue := reflect.ValueOf(constructor) if fnValue.Kind() != reflect.Func { panic(fmt.Sprintf("constructor (%v) is not a function, found %v", fnValue, fnValue.Kind())) } fnType := reflect.TypeOf(constructor) if fnType.NumOut() != 1 { panic(fmt.Sprintf("constructor must have exactly 1 return value, found %v", fnType.NumOut())) } argCount := fnType.NumIn() if !fnValue.Type().IsVariadic() && argCount != len(argPtrs) { panic(fmt.Sprintf("argPtrs (%d) must match constructor arguments (%d)", len(argPtrs), argCount)) } var kind reflect.Kind for i, argPtr := range argPtrs { isVariadic := fnValue.Type().IsVariadic() && (fnType.NumIn() == 1 || i >= fnType.NumIn()) if i < fnType.NumIn() { kind = fnType.In(i).Kind() } else { kind = fnType.In(fnType.NumIn() - 1).Kind() } if reflect.TypeOf(argPtr).Kind() != reflect.Ptr { panic(fmt.Sprintf("argPtrs must all be pointers, found %v", reflect.TypeOf(argPtr))) } if !isVariadic && reflect.ValueOf(argPtr).Elem().Kind() != kind { panic("argPtrs must match constructor argument types") } } return provider{ constructor: constructor, argPtrs: argPtrs, } }
[ "func", "NewProvider", "(", "constructor", "interface", "{", "}", ",", "argPtrs", "...", "interface", "{", "}", ")", "Provider", "{", "fnValue", ":=", "reflect", ".", "ValueOf", "(", "constructor", ")", "\n", "if", "fnValue", ".", "Kind", "(", ")", "!=",...
// NewProvider specifies how to construct a value given its constructor function and argument pointers
[ "NewProvider", "specifies", "how", "to", "construct", "a", "value", "given", "its", "constructor", "function", "and", "argument", "pointers" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/provider.go#L14-L53
16,466
karlkfi/inject
provider.go
Provide
func (p provider) Provide(g Graph) reflect.Value { fnType := reflect.TypeOf(p.constructor) argCount := fnType.NumIn() if fnType.IsVariadic() { argCount = len(p.argPtrs) } args := make([]reflect.Value, argCount, argCount) var inType reflect.Type for i := 0; i < argCount; i++ { arg := g.Resolve(p.argPtrs[i]) argType := arg.Type() if i < fnType.NumIn() { inType = fnType.In(i) } else { inType = fnType.In(fnType.NumIn() - 1) } if inType.Kind() == reflect.Slice { inType = inType.Elem() } if !argType.AssignableTo(inType) { if !argType.ConvertibleTo(inType) { panic(fmt.Sprintf( "arg %d of type %q cannot be assigned or converted to type %q for provider constructor (%s)", i, argType, inType, p.constructor, )) } arg = arg.Convert(inType) } args[i] = arg } return reflect.ValueOf(p.constructor).Call(args)[0] }
go
func (p provider) Provide(g Graph) reflect.Value { fnType := reflect.TypeOf(p.constructor) argCount := fnType.NumIn() if fnType.IsVariadic() { argCount = len(p.argPtrs) } args := make([]reflect.Value, argCount, argCount) var inType reflect.Type for i := 0; i < argCount; i++ { arg := g.Resolve(p.argPtrs[i]) argType := arg.Type() if i < fnType.NumIn() { inType = fnType.In(i) } else { inType = fnType.In(fnType.NumIn() - 1) } if inType.Kind() == reflect.Slice { inType = inType.Elem() } if !argType.AssignableTo(inType) { if !argType.ConvertibleTo(inType) { panic(fmt.Sprintf( "arg %d of type %q cannot be assigned or converted to type %q for provider constructor (%s)", i, argType, inType, p.constructor, )) } arg = arg.Convert(inType) } args[i] = arg } return reflect.ValueOf(p.constructor).Call(args)[0] }
[ "func", "(", "p", "provider", ")", "Provide", "(", "g", "Graph", ")", "reflect", ".", "Value", "{", "fnType", ":=", "reflect", ".", "TypeOf", "(", "p", ".", "constructor", ")", "\n\n", "argCount", ":=", "fnType", ".", "NumIn", "(", ")", "\n", "if", ...
// Provide returns the result of executing the constructor with argument values resolved from a dependency graph
[ "Provide", "returns", "the", "result", "of", "executing", "the", "constructor", "with", "argument", "values", "resolved", "from", "a", "dependency", "graph" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/provider.go#L56-L93
16,467
karlkfi/inject
provider.go
String
func (p provider) String() string { return fmt.Sprintf("&provider{\n%s,\n%s\n}", indent(fmt.Sprintf("constructor: %s", reflect.TypeOf(p.constructor)), 1), indent(fmt.Sprintf("argPtrs: %s", p.fmtArgPtrs()), 1), ) }
go
func (p provider) String() string { return fmt.Sprintf("&provider{\n%s,\n%s\n}", indent(fmt.Sprintf("constructor: %s", reflect.TypeOf(p.constructor)), 1), indent(fmt.Sprintf("argPtrs: %s", p.fmtArgPtrs()), 1), ) }
[ "func", "(", "p", "provider", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\\n", "\\n", "\"", ",", "indent", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "p", ".",...
// String returns a multiline string representation of the provider
[ "String", "returns", "a", "multiline", "string", "representation", "of", "the", "provider" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/provider.go#L101-L106
16,468
karlkfi/inject
graph.go
NewGraph
func NewGraph(defs ...Definition) Graph { defMap := make(map[interface{}]Definition, len(defs)) for _, def := range defs { defMap[def.Ptr()] = def } return &graph{ definitions: defMap, } }
go
func NewGraph(defs ...Definition) Graph { defMap := make(map[interface{}]Definition, len(defs)) for _, def := range defs { defMap[def.Ptr()] = def } return &graph{ definitions: defMap, } }
[ "func", "NewGraph", "(", "defs", "...", "Definition", ")", "Graph", "{", "defMap", ":=", "make", "(", "map", "[", "interface", "{", "}", "]", "Definition", ",", "len", "(", "defs", ")", ")", "\n", "for", "_", ",", "def", ":=", "range", "defs", "{",...
// NewGraph constructs a new Graph, initializing the provider and value maps.
[ "NewGraph", "constructs", "a", "new", "Graph", "initializing", "the", "provider", "and", "value", "maps", "." ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/graph.go#L27-L35
16,469
karlkfi/inject
graph.go
Define
func (g *graph) Define(ptr interface{}, provider Provider) Definition { def := NewDefinition(ptr, provider) g.Add(def) return def }
go
func (g *graph) Define(ptr interface{}, provider Provider) Definition { def := NewDefinition(ptr, provider) g.Add(def) return def }
[ "func", "(", "g", "*", "graph", ")", "Define", "(", "ptr", "interface", "{", "}", ",", "provider", "Provider", ")", "Definition", "{", "def", ":=", "NewDefinition", "(", "ptr", ",", "provider", ")", "\n", "g", ".", "Add", "(", "def", ")", "\n", "re...
// Define a pointer as being resolved by a provider
[ "Define", "a", "pointer", "as", "being", "resolved", "by", "a", "provider" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/graph.go#L42-L46
16,470
karlkfi/inject
graph.go
ResolveByType
func (g *graph) ResolveByType(ptrType reflect.Type) []reflect.Value { var values []reflect.Value for ptr, def := range g.definitions { if reflect.TypeOf(ptr).Elem() == ptrType { values = append(values, def.Resolve(g)) } } return values }
go
func (g *graph) ResolveByType(ptrType reflect.Type) []reflect.Value { var values []reflect.Value for ptr, def := range g.definitions { if reflect.TypeOf(ptr).Elem() == ptrType { values = append(values, def.Resolve(g)) } } return values }
[ "func", "(", "g", "*", "graph", ")", "ResolveByType", "(", "ptrType", "reflect", ".", "Type", ")", "[", "]", "reflect", ".", "Value", "{", "var", "values", "[", "]", "reflect", ".", "Value", "\n", "for", "ptr", ",", "def", ":=", "range", "g", ".", ...
// Resolve a type into a list of values by resolving all defined pointers with that exact type
[ "Resolve", "a", "type", "into", "a", "list", "of", "values", "by", "resolving", "all", "defined", "pointers", "with", "that", "exact", "type" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/graph.go#L66-L74
16,471
karlkfi/inject
graph.go
ResolveAll
func (g *graph) ResolveAll() []reflect.Value { var values []reflect.Value for _, def := range g.definitions { values = append(values, def.Resolve(g)) } return values }
go
func (g *graph) ResolveAll() []reflect.Value { var values []reflect.Value for _, def := range g.definitions { values = append(values, def.Resolve(g)) } return values }
[ "func", "(", "g", "*", "graph", ")", "ResolveAll", "(", ")", "[", "]", "reflect", ".", "Value", "{", "var", "values", "[", "]", "reflect", ".", "Value", "\n", "for", "_", ",", "def", ":=", "range", "g", ".", "definitions", "{", "values", "=", "ap...
// ResolveAll known pointers into values, caching and returning the results
[ "ResolveAll", "known", "pointers", "into", "values", "caching", "and", "returning", "the", "results" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/graph.go#L88-L94
16,472
karlkfi/inject
graph.go
String
func (g graph) String() string { return fmt.Sprintf("&graph{\n%s\n}", indent(fmt.Sprintf("definitions: %s", g.fmtDefinitions()), 1), ) }
go
func (g graph) String() string { return fmt.Sprintf("&graph{\n%s\n}", indent(fmt.Sprintf("definitions: %s", g.fmtDefinitions()), 1), ) }
[ "func", "(", "g", "graph", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\\n", "\"", ",", "indent", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "g", ".", "fmtDefinitions", "(", ")", ")", ",", ...
// String returns a multiline string representation of the dependency graph
[ "String", "returns", "a", "multiline", "string", "representation", "of", "the", "dependency", "graph" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/graph.go#L104-L108
16,473
karlkfi/inject
auto_provider.go
NewAutoProvider
func NewAutoProvider(constructor interface{}) Provider { fnValue := reflect.ValueOf(constructor) if fnValue.Kind() != reflect.Func { panic("constructor is not a function") } fnType := reflect.TypeOf(constructor) if fnType.NumOut() != 1 { panic("constructor must have exactly 1 return value") } return autoProvider{ constructor: constructor, } }
go
func NewAutoProvider(constructor interface{}) Provider { fnValue := reflect.ValueOf(constructor) if fnValue.Kind() != reflect.Func { panic("constructor is not a function") } fnType := reflect.TypeOf(constructor) if fnType.NumOut() != 1 { panic("constructor must have exactly 1 return value") } return autoProvider{ constructor: constructor, } }
[ "func", "NewAutoProvider", "(", "constructor", "interface", "{", "}", ")", "Provider", "{", "fnValue", ":=", "reflect", ".", "ValueOf", "(", "constructor", ")", "\n", "if", "fnValue", ".", "Kind", "(", ")", "!=", "reflect", ".", "Func", "{", "panic", "("...
// NewAutoProvider specifies how to construct a value given its constructor function. // Argument values are auto-resolved by type.
[ "NewAutoProvider", "specifies", "how", "to", "construct", "a", "value", "given", "its", "constructor", "function", ".", "Argument", "values", "are", "auto", "-", "resolved", "by", "type", "." ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/auto_provider.go#L14-L28
16,474
karlkfi/inject
auto_provider.go
Provide
func (p autoProvider) Provide(g Graph) reflect.Value { fnType := reflect.TypeOf(p.constructor) argCount := fnType.NumIn() args := make([]reflect.Value, argCount, argCount) for i := 0; i < argCount; i++ { argType := fnType.In(i) values := g.ResolveByType(argType) if len(values) > 1 { panic(fmt.Sprintf("more than one defined pointer is assignable to the provider argument %d of type (%v)", i, argType)) } else if len(values) == 0 { panic(fmt.Sprintf("no defined pointer is assignable to the provider argument %d of type (%v)", i, argType)) } args[i] = values[0] } return reflect.ValueOf(p.constructor).Call(args)[0] }
go
func (p autoProvider) Provide(g Graph) reflect.Value { fnType := reflect.TypeOf(p.constructor) argCount := fnType.NumIn() args := make([]reflect.Value, argCount, argCount) for i := 0; i < argCount; i++ { argType := fnType.In(i) values := g.ResolveByType(argType) if len(values) > 1 { panic(fmt.Sprintf("more than one defined pointer is assignable to the provider argument %d of type (%v)", i, argType)) } else if len(values) == 0 { panic(fmt.Sprintf("no defined pointer is assignable to the provider argument %d of type (%v)", i, argType)) } args[i] = values[0] } return reflect.ValueOf(p.constructor).Call(args)[0] }
[ "func", "(", "p", "autoProvider", ")", "Provide", "(", "g", "Graph", ")", "reflect", ".", "Value", "{", "fnType", ":=", "reflect", ".", "TypeOf", "(", "p", ".", "constructor", ")", "\n\n", "argCount", ":=", "fnType", ".", "NumIn", "(", ")", "\n", "ar...
// Provide returns the result of executing the constructor with argument values resolved by type from a dependency graph
[ "Provide", "returns", "the", "result", "of", "executing", "the", "constructor", "with", "argument", "values", "resolved", "by", "type", "from", "a", "dependency", "graph" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/auto_provider.go#L31-L48
16,475
karlkfi/inject
auto_provider.go
String
func (p autoProvider) String() string { return fmt.Sprintf("&autoProvider{\n%s\n}", indent(fmt.Sprintf("constructor: %s", reflect.TypeOf(p.constructor)), 1), ) }
go
func (p autoProvider) String() string { return fmt.Sprintf("&autoProvider{\n%s\n}", indent(fmt.Sprintf("constructor: %s", reflect.TypeOf(p.constructor)), 1), ) }
[ "func", "(", "p", "autoProvider", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\\n", "\"", ",", "indent", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "p", ".", "c...
// String returns a multiline string representation of the autoProvider
[ "String", "returns", "a", "multiline", "string", "representation", "of", "the", "autoProvider" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/auto_provider.go#L56-L60
16,476
karlkfi/inject
find.go
FindByType
func FindByType(g Graph, listPtr interface{}) []reflect.Value { ptrType := reflect.TypeOf(listPtr) if ptrType.Kind() != reflect.Ptr { panic(fmt.Sprintf("listPtr (%v) is not a pointer", ptrType)) } listType := ptrType.Elem() if listType.Kind() != reflect.Slice { panic(fmt.Sprintf("listPtr (%v) is not a pointer to a slice or array", ptrType)) } listValue := reflect.ValueOf(listPtr).Elem() values := g.ResolveByType(listType.Elem()) listValue = reflect.Append(listValue, values...) // update the listPtr value reflect.ValueOf(listPtr).Elem().Set(listValue) return values }
go
func FindByType(g Graph, listPtr interface{}) []reflect.Value { ptrType := reflect.TypeOf(listPtr) if ptrType.Kind() != reflect.Ptr { panic(fmt.Sprintf("listPtr (%v) is not a pointer", ptrType)) } listType := ptrType.Elem() if listType.Kind() != reflect.Slice { panic(fmt.Sprintf("listPtr (%v) is not a pointer to a slice or array", ptrType)) } listValue := reflect.ValueOf(listPtr).Elem() values := g.ResolveByType(listType.Elem()) listValue = reflect.Append(listValue, values...) // update the listPtr value reflect.ValueOf(listPtr).Elem().Set(listValue) return values }
[ "func", "FindByType", "(", "g", "Graph", ",", "listPtr", "interface", "{", "}", ")", "[", "]", "reflect", ".", "Value", "{", "ptrType", ":=", "reflect", ".", "TypeOf", "(", "listPtr", ")", "\n", "if", "ptrType", ".", "Kind", "(", ")", "!=", "reflect"...
// FindByType resolves all defined pointers that match the type of the supplied slice // and appends the resolved values to the slice.
[ "FindByType", "resolves", "all", "defined", "pointers", "that", "match", "the", "type", "of", "the", "supplied", "slice", "and", "appends", "the", "resolved", "values", "to", "the", "slice", "." ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/find.go#L10-L30
16,477
karlkfi/inject
extract.go
ExtractByType
func ExtractByType(g Graph, ptr interface{}) reflect.Value { ptrType := reflect.TypeOf(ptr) if ptrType.Kind() != reflect.Ptr { panic(fmt.Sprintf("ptr (%v) is not a pointer", ptrType)) } targetType := reflect.ValueOf(ptr).Elem().Type() values := g.ResolveByType(targetType) if len(values) > 1 { panic(fmt.Sprintf("more than one defined pointer matches the specified type (%v)", ptr)) } else if len(values) == 0 { panic(fmt.Sprintf("no defined pointer matches the specified type (%v)", ptr)) } value := values[0] // update the ptr value reflect.ValueOf(ptr).Elem().Set(value) return value }
go
func ExtractByType(g Graph, ptr interface{}) reflect.Value { ptrType := reflect.TypeOf(ptr) if ptrType.Kind() != reflect.Ptr { panic(fmt.Sprintf("ptr (%v) is not a pointer", ptrType)) } targetType := reflect.ValueOf(ptr).Elem().Type() values := g.ResolveByType(targetType) if len(values) > 1 { panic(fmt.Sprintf("more than one defined pointer matches the specified type (%v)", ptr)) } else if len(values) == 0 { panic(fmt.Sprintf("no defined pointer matches the specified type (%v)", ptr)) } value := values[0] // update the ptr value reflect.ValueOf(ptr).Elem().Set(value) return value }
[ "func", "ExtractByType", "(", "g", "Graph", ",", "ptr", "interface", "{", "}", ")", "reflect", ".", "Value", "{", "ptrType", ":=", "reflect", ".", "TypeOf", "(", "ptr", ")", "\n", "if", "ptrType", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", ...
// ExtractByType resolves a pointer into a value by finding exactly one defined pointer with the specified type
[ "ExtractByType", "resolves", "a", "pointer", "into", "a", "value", "by", "finding", "exactly", "one", "defined", "pointer", "with", "the", "specified", "type" ]
27c5323a07f81a37802552bb0734fc4bb649aaa1
https://github.com/karlkfi/inject/blob/27c5323a07f81a37802552bb0734fc4bb649aaa1/extract.go#L9-L29
16,478
lestrrat-go/strftime
strftime.go
New
func New(f string) (*Strftime, error) { var wl appenderList if err := compile(&wl, f); err != nil { return nil, errors.Wrap(err, `failed to compile format`) } return &Strftime{ pattern: f, compiled: wl, }, nil }
go
func New(f string) (*Strftime, error) { var wl appenderList if err := compile(&wl, f); err != nil { return nil, errors.Wrap(err, `failed to compile format`) } return &Strftime{ pattern: f, compiled: wl, }, nil }
[ "func", "New", "(", "f", "string", ")", "(", "*", "Strftime", ",", "error", ")", "{", "var", "wl", "appenderList", "\n", "if", "err", ":=", "compile", "(", "&", "wl", ",", "f", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ...
// New creates a new Strftime object. If the compilation fails, then // an error is returned in the second argument.
[ "New", "creates", "a", "new", "Strftime", "object", ".", "If", "the", "compilation", "fails", "then", "an", "error", "is", "returned", "in", "the", "second", "argument", "." ]
8b31f9c59b0feb56c456ce49a7b3d2b2e93a6f18
https://github.com/lestrrat-go/strftime/blob/8b31f9c59b0feb56c456ce49a7b3d2b2e93a6f18/strftime.go#L165-L174
16,479
lestrrat-go/strftime
strftime.go
FormatString
func (f *Strftime) FormatString(t time.Time) string { const bufSize = 64 var b []byte max := len(f.pattern) + 10 if max < bufSize { var buf [bufSize]byte b = buf[:0] } else { b = make([]byte, 0, max) } return string(f.format(b, t)) }
go
func (f *Strftime) FormatString(t time.Time) string { const bufSize = 64 var b []byte max := len(f.pattern) + 10 if max < bufSize { var buf [bufSize]byte b = buf[:0] } else { b = make([]byte, 0, max) } return string(f.format(b, t)) }
[ "func", "(", "f", "*", "Strftime", ")", "FormatString", "(", "t", "time", ".", "Time", ")", "string", "{", "const", "bufSize", "=", "64", "\n", "var", "b", "[", "]", "byte", "\n", "max", ":=", "len", "(", "f", ".", "pattern", ")", "+", "10", "\...
// FormatString takes the time `t` and formats it, returning the // string containing the formated data.
[ "FormatString", "takes", "the", "time", "t", "and", "formats", "it", "returning", "the", "string", "containing", "the", "formated", "data", "." ]
8b31f9c59b0feb56c456ce49a7b3d2b2e93a6f18
https://github.com/lestrrat-go/strftime/blob/8b31f9c59b0feb56c456ce49a7b3d2b2e93a6f18/strftime.go#L208-L219
16,480
mcuadros/go-lookup
lookup.go
LookupString
func LookupString(i interface{}, path string) (reflect.Value, error) { return Lookup(i, strings.Split(path, SplitToken)...) }
go
func LookupString(i interface{}, path string) (reflect.Value, error) { return Lookup(i, strings.Split(path, SplitToken)...) }
[ "func", "LookupString", "(", "i", "interface", "{", "}", ",", "path", "string", ")", "(", "reflect", ".", "Value", ",", "error", ")", "{", "return", "Lookup", "(", "i", ",", "strings", ".", "Split", "(", "path", ",", "SplitToken", ")", "...", ")", ...
// LookupString performs a lookup into a value, using a string. Same as `Loookup` // but using a string with the keys separated by `.`
[ "LookupString", "performs", "a", "lookup", "into", "a", "value", "using", "a", "string", ".", "Same", "as", "Loookup", "but", "using", "a", "string", "with", "the", "keys", "separated", "by", "." ]
5650f26be7675b629fff8356a50d906fa03e9c8b
https://github.com/mcuadros/go-lookup/blob/5650f26be7675b629fff8356a50d906fa03e9c8b/lookup.go#L28-L30
16,481
campoy/unique
unique.go
Slice
func Slice(slicePtr interface{}, less func(i, j int) bool) { v := reflect.ValueOf(slicePtr).Elem() if v.Len() <= 1 { return } sort.Slice(v.Interface(), less) i := 0 for j := 1; j < v.Len(); j++ { if !less(i, j) { continue } i++ v.Index(i).Set(v.Index(j)) } i++ v.SetLen(i) }
go
func Slice(slicePtr interface{}, less func(i, j int) bool) { v := reflect.ValueOf(slicePtr).Elem() if v.Len() <= 1 { return } sort.Slice(v.Interface(), less) i := 0 for j := 1; j < v.Len(); j++ { if !less(i, j) { continue } i++ v.Index(i).Set(v.Index(j)) } i++ v.SetLen(i) }
[ "func", "Slice", "(", "slicePtr", "interface", "{", "}", ",", "less", "func", "(", "i", ",", "j", "int", ")", "bool", ")", "{", "v", ":=", "reflect", ".", "ValueOf", "(", "slicePtr", ")", ".", "Elem", "(", ")", "\n", "if", "v", ".", "Len", "(",...
// Slice sorts the slice pointed by the provided pointer given the provided // less function and removes repeated elements. // The function panics if the provided interface is not a pointer to a slice.
[ "Slice", "sorts", "the", "slice", "pointed", "by", "the", "provided", "pointer", "given", "the", "provided", "less", "function", "and", "removes", "repeated", "elements", ".", "The", "function", "panics", "if", "the", "provided", "interface", "is", "not", "a",...
88950e537e7e644cd746a3102037b5d2b723e9f5
https://github.com/campoy/unique/blob/88950e537e7e644cd746a3102037b5d2b723e9f5/unique.go#L12-L29
16,482
zach-klippenstein/goregen
regen.go
Rng
func (a *GeneratorArgs) Rng() *rand.Rand { if a.rng == nil { panic("GeneratorArgs has not been initialized by NewGenerator yet") } return a.rng }
go
func (a *GeneratorArgs) Rng() *rand.Rand { if a.rng == nil { panic("GeneratorArgs has not been initialized by NewGenerator yet") } return a.rng }
[ "func", "(", "a", "*", "GeneratorArgs", ")", "Rng", "(", ")", "*", "rand", ".", "Rand", "{", "if", "a", ".", "rng", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "a", ".", "rng", "\n", "}" ]
// Rng returns the random number generator used by generators. // Panics if called before the GeneratorArgs has been initialized by NewGenerator.
[ "Rng", "returns", "the", "random", "number", "generator", "used", "by", "generators", ".", "Panics", "if", "called", "before", "the", "GeneratorArgs", "has", "been", "initialized", "by", "NewGenerator", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/regen.go#L171-L176
16,483
zach-klippenstein/goregen
regen.go
NewGenerator
func NewGenerator(pattern string, inputArgs *GeneratorArgs) (generator Generator, err error) { args := GeneratorArgs{} // Copy inputArgs so the caller can't change them. if inputArgs != nil { args = *inputArgs } if err = args.initialize(); err != nil { return nil, err } var regexp *syntax.Regexp regexp, err = syntax.Parse(pattern, args.Flags) if err != nil { return } var gen *internalGenerator gen, err = newGenerator(regexp, &args) if err != nil { return } return gen, nil }
go
func NewGenerator(pattern string, inputArgs *GeneratorArgs) (generator Generator, err error) { args := GeneratorArgs{} // Copy inputArgs so the caller can't change them. if inputArgs != nil { args = *inputArgs } if err = args.initialize(); err != nil { return nil, err } var regexp *syntax.Regexp regexp, err = syntax.Parse(pattern, args.Flags) if err != nil { return } var gen *internalGenerator gen, err = newGenerator(regexp, &args) if err != nil { return } return gen, nil }
[ "func", "NewGenerator", "(", "pattern", "string", ",", "inputArgs", "*", "GeneratorArgs", ")", "(", "generator", "Generator", ",", "err", "error", ")", "{", "args", ":=", "GeneratorArgs", "{", "}", "\n\n", "// Copy inputArgs so the caller can't change them.", "if", ...
// NewGenerator creates a generator that returns random strings that match the regular expression in pattern. // If args is nil, default values are used.
[ "NewGenerator", "creates", "a", "generator", "that", "returns", "random", "strings", "that", "match", "the", "regular", "expression", "in", "pattern", ".", "If", "args", "is", "nil", "default", "values", "are", "used", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/regen.go#L201-L225
16,484
zach-klippenstein/goregen
internal_generator.go
newGenerators
func newGenerators(regexps []*syntax.Regexp, args *GeneratorArgs) ([]*internalGenerator, error) { generators := make([]*internalGenerator, len(regexps), len(regexps)) var err error // create a generator for each alternate pattern for i, subR := range regexps { generators[i], err = newGenerator(subR, args) if err != nil { return nil, err } } return generators, nil }
go
func newGenerators(regexps []*syntax.Regexp, args *GeneratorArgs) ([]*internalGenerator, error) { generators := make([]*internalGenerator, len(regexps), len(regexps)) var err error // create a generator for each alternate pattern for i, subR := range regexps { generators[i], err = newGenerator(subR, args) if err != nil { return nil, err } } return generators, nil }
[ "func", "newGenerators", "(", "regexps", "[", "]", "*", "syntax", ".", "Regexp", ",", "args", "*", "GeneratorArgs", ")", "(", "[", "]", "*", "internalGenerator", ",", "error", ")", "{", "generators", ":=", "make", "(", "[", "]", "*", "internalGenerator",...
// Create a new generator for each expression in regexps.
[ "Create", "a", "new", "generator", "for", "each", "expression", "in", "regexps", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/internal_generator.go#L71-L84
16,485
zach-klippenstein/goregen
internal_generator.go
newGenerator
func newGenerator(regexp *syntax.Regexp, args *GeneratorArgs) (generator *internalGenerator, err error) { simplified := regexp.Simplify() factory, ok := generatorFactories[simplified.Op] if ok { return factory(simplified, args) } return nil, fmt.Errorf("invalid generator pattern: /%s/ as /%s/\n%s", regexp, simplified, inspectRegexpToString(simplified)) }
go
func newGenerator(regexp *syntax.Regexp, args *GeneratorArgs) (generator *internalGenerator, err error) { simplified := regexp.Simplify() factory, ok := generatorFactories[simplified.Op] if ok { return factory(simplified, args) } return nil, fmt.Errorf("invalid generator pattern: /%s/ as /%s/\n%s", regexp, simplified, inspectRegexpToString(simplified)) }
[ "func", "newGenerator", "(", "regexp", "*", "syntax", ".", "Regexp", ",", "args", "*", "GeneratorArgs", ")", "(", "generator", "*", "internalGenerator", ",", "err", "error", ")", "{", "simplified", ":=", "regexp", ".", "Simplify", "(", ")", "\n\n", "factor...
// Create a new generator for r.
[ "Create", "a", "new", "generator", "for", "r", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/internal_generator.go#L87-L97
16,486
zach-klippenstein/goregen
internal_generator.go
noop
func noop(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) { return &internalGenerator{regexp.String(), func() string { return "" }}, nil }
go
func noop(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) { return &internalGenerator{regexp.String(), func() string { return "" }}, nil }
[ "func", "noop", "(", "regexp", "*", "syntax", ".", "Regexp", ",", "args", "*", "GeneratorArgs", ")", "(", "*", "internalGenerator", ",", "error", ")", "{", "return", "&", "internalGenerator", "{", "regexp", ".", "String", "(", ")", ",", "func", "(", ")...
// Generator that does nothing.
[ "Generator", "that", "does", "nothing", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/internal_generator.go#L100-L104
16,487
zach-klippenstein/goregen
internal_generator.go
opCharClass
func opCharClass(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) { enforceOp(regexp, syntax.OpCharClass) charClass := parseCharClass(regexp.Rune) return createCharClassGenerator(regexp.String(), charClass, args) }
go
func opCharClass(regexp *syntax.Regexp, args *GeneratorArgs) (*internalGenerator, error) { enforceOp(regexp, syntax.OpCharClass) charClass := parseCharClass(regexp.Rune) return createCharClassGenerator(regexp.String(), charClass, args) }
[ "func", "opCharClass", "(", "regexp", "*", "syntax", ".", "Regexp", ",", "args", "*", "GeneratorArgs", ")", "(", "*", "internalGenerator", ",", "error", ")", "{", "enforceOp", "(", "regexp", ",", "syntax", ".", "OpCharClass", ")", "\n", "charClass", ":=", ...
// Handles syntax.ClassNL because the parser uses that flag to generate character // classes that respect it.
[ "Handles", "syntax", ".", "ClassNL", "because", "the", "parser", "uses", "that", "flag", "to", "generate", "character", "classes", "that", "respect", "it", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/internal_generator.go#L155-L159
16,488
zach-klippenstein/goregen
internal_generator.go
enforceOp
func enforceOp(r *syntax.Regexp, op syntax.Op) { if r.Op != op { panic(fmt.Sprintf("invalid Op: expected %s, was %s", opToString(op), opToString(r.Op))) } }
go
func enforceOp(r *syntax.Regexp, op syntax.Op) { if r.Op != op { panic(fmt.Sprintf("invalid Op: expected %s, was %s", opToString(op), opToString(r.Op))) } }
[ "func", "enforceOp", "(", "r", "*", "syntax", ".", "Regexp", ",", "op", "syntax", ".", "Op", ")", "{", "if", "r", ".", "Op", "!=", "op", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "opToString", "(", "op", ")", ",", "opToStr...
// Panic if r.Op != op.
[ "Panic", "if", "r", ".", "Op", "!", "=", "op", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/internal_generator.go#L221-L225
16,489
zach-klippenstein/goregen
internal_generator.go
enforceSingleSub
func enforceSingleSub(regexp *syntax.Regexp) error { if len(regexp.Sub) != 1 { return generatorError(nil, "%s expected 1 sub-expression, but got %d: %s", opToString(regexp.Op), len(regexp.Sub), regexp) } return nil }
go
func enforceSingleSub(regexp *syntax.Regexp) error { if len(regexp.Sub) != 1 { return generatorError(nil, "%s expected 1 sub-expression, but got %d: %s", opToString(regexp.Op), len(regexp.Sub), regexp) } return nil }
[ "func", "enforceSingleSub", "(", "regexp", "*", "syntax", ".", "Regexp", ")", "error", "{", "if", "len", "(", "regexp", ".", "Sub", ")", "!=", "1", "{", "return", "generatorError", "(", "nil", ",", "\"", "\"", ",", "opToString", "(", "regexp", ".", "...
// Return an error if r has 0 or more than 1 sub-expression.
[ "Return", "an", "error", "if", "r", "has", "0", "or", "more", "than", "1", "sub", "-", "expression", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/internal_generator.go#L228-L234
16,490
zach-klippenstein/goregen
regexp_format.go
inspectRegexpToString
func inspectRegexpToString(r *syntax.Regexp) string { var buffer bytes.Buffer inspectRegexpToWriter(&buffer, r) return buffer.String() }
go
func inspectRegexpToString(r *syntax.Regexp) string { var buffer bytes.Buffer inspectRegexpToWriter(&buffer, r) return buffer.String() }
[ "func", "inspectRegexpToString", "(", "r", "*", "syntax", ".", "Regexp", ")", "string", "{", "var", "buffer", "bytes", ".", "Buffer", "\n", "inspectRegexpToWriter", "(", "&", "buffer", ",", "r", ")", "\n", "return", "buffer", ".", "String", "(", ")", "\n...
// inspectRegexpToString returns a string describing a regular expression.
[ "inspectRegexpToString", "returns", "a", "string", "describing", "a", "regular", "expression", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/regexp_format.go#L27-L31
16,491
zach-klippenstein/goregen
regexp_format.go
inspectPatternsToString
func inspectPatternsToString(simplify bool, patterns ...string) string { var buffer bytes.Buffer for _, pattern := range patterns { inspectPatternsToWriter(simplify, &buffer, pattern) } return buffer.String() }
go
func inspectPatternsToString(simplify bool, patterns ...string) string { var buffer bytes.Buffer for _, pattern := range patterns { inspectPatternsToWriter(simplify, &buffer, pattern) } return buffer.String() }
[ "func", "inspectPatternsToString", "(", "simplify", "bool", ",", "patterns", "...", "string", ")", "string", "{", "var", "buffer", "bytes", ".", "Buffer", "\n", "for", "_", ",", "pattern", ":=", "range", "patterns", "{", "inspectPatternsToWriter", "(", "simpli...
// inspectPatternsToString returns a string describing one or more regular expressions.
[ "inspectPatternsToString", "returns", "a", "string", "describing", "one", "or", "more", "regular", "expressions", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/regexp_format.go#L34-L40
16,492
zach-klippenstein/goregen
regexp_format.go
parseOrPanic
func parseOrPanic(simplify bool, pattern string) *syntax.Regexp { regexp, err := syntax.Parse(pattern, 0) if err != nil { panic(err) } if simplify { regexp = regexp.Simplify() } return regexp }
go
func parseOrPanic(simplify bool, pattern string) *syntax.Regexp { regexp, err := syntax.Parse(pattern, 0) if err != nil { panic(err) } if simplify { regexp = regexp.Simplify() } return regexp }
[ "func", "parseOrPanic", "(", "simplify", "bool", ",", "pattern", "string", ")", "*", "syntax", ".", "Regexp", "{", "regexp", ",", "err", ":=", "syntax", ".", "Parse", "(", "pattern", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", ...
// ParseOrPanic parses a regular expression into an AST. // Panics on error.
[ "ParseOrPanic", "parses", "a", "regular", "expression", "into", "an", "AST", ".", "Panics", "on", "error", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/regexp_format.go#L74-L83
16,493
zach-klippenstein/goregen
regexp_format.go
runesToString
func runesToString(runes ...rune) string { defer func() { if err := recover(); err != nil { panic(fmt.Errorf("RunesToString panicked")) } }() var buffer bytes.Buffer for _, r := range runes { buffer.WriteRune(r) } return buffer.String() }
go
func runesToString(runes ...rune) string { defer func() { if err := recover(); err != nil { panic(fmt.Errorf("RunesToString panicked")) } }() var buffer bytes.Buffer for _, r := range runes { buffer.WriteRune(r) } return buffer.String() }
[ "func", "runesToString", "(", "runes", "...", "rune", ")", "string", "{", "defer", "func", "(", ")", "{", "if", "err", ":=", "recover", "(", ")", ";", "err", "!=", "nil", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n", ...
// runesToString converts a slice of runes to the string they represent.
[ "runesToString", "converts", "a", "slice", "of", "runes", "to", "the", "string", "they", "represent", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/regexp_format.go#L86-L97
16,494
zach-klippenstein/goregen
regexp_format.go
runesToDecimalString
func runesToDecimalString(runes []rune) string { var buffer bytes.Buffer for _, r := range runes { buffer.WriteString(fmt.Sprintf("%d, ", r)) } return buffer.String() }
go
func runesToDecimalString(runes []rune) string { var buffer bytes.Buffer for _, r := range runes { buffer.WriteString(fmt.Sprintf("%d, ", r)) } return buffer.String() }
[ "func", "runesToDecimalString", "(", "runes", "[", "]", "rune", ")", "string", "{", "var", "buffer", "bytes", ".", "Buffer", "\n", "for", "_", ",", "r", ":=", "range", "runes", "{", "buffer", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", ...
// RunesToDecimalString converts a slice of runes to their comma-separated decimal values.
[ "RunesToDecimalString", "converts", "a", "slice", "of", "runes", "to", "their", "comma", "-", "separated", "decimal", "values", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/regexp_format.go#L100-L106
16,495
zach-klippenstein/goregen
regexp_format.go
opToString
func opToString(op syntax.Op) string { switch op { case syntax.OpNoMatch: return "OpNoMatch" case syntax.OpEmptyMatch: return "OpEmptyMatch" case syntax.OpLiteral: return "OpLiteral" case syntax.OpCharClass: return "OpCharClass" case syntax.OpAnyCharNotNL: return "OpAnyCharNotNL" case syntax.OpAnyChar: return "OpAnyChar" case syntax.OpBeginLine: return "OpBeginLine" case syntax.OpEndLine: return "OpEndLine" case syntax.OpBeginText: return "OpBeginText" case syntax.OpEndText: return "OpEndText" case syntax.OpWordBoundary: return "OpWordBoundary" case syntax.OpNoWordBoundary: return "OpNoWordBoundary" case syntax.OpCapture: return "OpCapture" case syntax.OpStar: return "OpStar" case syntax.OpPlus: return "OpPlus" case syntax.OpQuest: return "OpQuest" case syntax.OpRepeat: return "OpRepeat" case syntax.OpConcat: return "OpConcat" case syntax.OpAlternate: return "OpAlternate" } panic(fmt.Sprintf("invalid op: %d", op)) }
go
func opToString(op syntax.Op) string { switch op { case syntax.OpNoMatch: return "OpNoMatch" case syntax.OpEmptyMatch: return "OpEmptyMatch" case syntax.OpLiteral: return "OpLiteral" case syntax.OpCharClass: return "OpCharClass" case syntax.OpAnyCharNotNL: return "OpAnyCharNotNL" case syntax.OpAnyChar: return "OpAnyChar" case syntax.OpBeginLine: return "OpBeginLine" case syntax.OpEndLine: return "OpEndLine" case syntax.OpBeginText: return "OpBeginText" case syntax.OpEndText: return "OpEndText" case syntax.OpWordBoundary: return "OpWordBoundary" case syntax.OpNoWordBoundary: return "OpNoWordBoundary" case syntax.OpCapture: return "OpCapture" case syntax.OpStar: return "OpStar" case syntax.OpPlus: return "OpPlus" case syntax.OpQuest: return "OpQuest" case syntax.OpRepeat: return "OpRepeat" case syntax.OpConcat: return "OpConcat" case syntax.OpAlternate: return "OpAlternate" } panic(fmt.Sprintf("invalid op: %d", op)) }
[ "func", "opToString", "(", "op", "syntax", ".", "Op", ")", "string", "{", "switch", "op", "{", "case", "syntax", ".", "OpNoMatch", ":", "return", "\"", "\"", "\n", "case", "syntax", ".", "OpEmptyMatch", ":", "return", "\"", "\"", "\n", "case", "syntax"...
// opToString gets the string name of a regular expression operation.
[ "opToString", "gets", "the", "string", "name", "of", "a", "regular", "expression", "operation", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/regexp_format.go#L109-L152
16,496
zach-klippenstein/goregen
char_class.go
newCharClass
func newCharClass(start rune, end rune) *tCharClass { charRange := newCharClassRange(start, end) return &tCharClass{ Ranges: []tCharClassRange{charRange}, TotalSize: charRange.Size, } }
go
func newCharClass(start rune, end rune) *tCharClass { charRange := newCharClassRange(start, end) return &tCharClass{ Ranges: []tCharClassRange{charRange}, TotalSize: charRange.Size, } }
[ "func", "newCharClass", "(", "start", "rune", ",", "end", "rune", ")", "*", "tCharClass", "{", "charRange", ":=", "newCharClassRange", "(", "start", ",", "end", ")", "\n", "return", "&", "tCharClass", "{", "Ranges", ":", "[", "]", "tCharClassRange", "{", ...
// NewCharClass creates a character class with a single range.
[ "NewCharClass", "creates", "a", "character", "class", "with", "a", "single", "range", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/char_class.go#L37-L43
16,497
zach-klippenstein/goregen
char_class.go
GetRuneAt
func (class *tCharClass) GetRuneAt(i int32) rune { for _, r := range class.Ranges { if i < r.Size { return r.Start + rune(i) } i -= r.Size } panic("index out of bounds") }
go
func (class *tCharClass) GetRuneAt(i int32) rune { for _, r := range class.Ranges { if i < r.Size { return r.Start + rune(i) } i -= r.Size } panic("index out of bounds") }
[ "func", "(", "class", "*", "tCharClass", ")", "GetRuneAt", "(", "i", "int32", ")", "rune", "{", "for", "_", ",", "r", ":=", "range", "class", ".", "Ranges", "{", "if", "i", "<", "r", ".", "Size", "{", "return", "r", ".", "Start", "+", "rune", "...
// GetRuneAt gets a rune from CharClass as a contiguous array of runes.
[ "GetRuneAt", "gets", "a", "rune", "from", "CharClass", "as", "a", "contiguous", "array", "of", "runes", "." ]
795b5e3961ea1912fde60af417ad85e86acc0d6a
https://github.com/zach-klippenstein/goregen/blob/795b5e3961ea1912fde60af417ad85e86acc0d6a/char_class.go#L83-L91
16,498
anacrolix/missinggo
hostmaybeport.go
SplitHostMaybePort
func SplitHostMaybePort(hostport string) HostMaybePort { host, portStr, err := net.SplitHostPort(hostport) if err != nil { if strings.Contains(err.Error(), "missing port") { return HostMaybePort{ Host: hostport, NoPort: true, } } return HostMaybePort{ Err: err, } } portI64, err := strconv.ParseInt(portStr, 0, 0) if err != nil { return HostMaybePort{ Host: host, Port: -1, Err: err, } } return HostMaybePort{ Host: host, Port: int(portI64), } }
go
func SplitHostMaybePort(hostport string) HostMaybePort { host, portStr, err := net.SplitHostPort(hostport) if err != nil { if strings.Contains(err.Error(), "missing port") { return HostMaybePort{ Host: hostport, NoPort: true, } } return HostMaybePort{ Err: err, } } portI64, err := strconv.ParseInt(portStr, 0, 0) if err != nil { return HostMaybePort{ Host: host, Port: -1, Err: err, } } return HostMaybePort{ Host: host, Port: int(portI64), } }
[ "func", "SplitHostMaybePort", "(", "hostport", "string", ")", "HostMaybePort", "{", "host", ",", "portStr", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "hostport", ")", "\n", "if", "err", "!=", "nil", "{", "if", "strings", ".", "Contains", "(", "...
// Parse a "hostport" string, a concept that floats around the stdlib a lot // and is painful to work with. If no port is present, what's usually present // is just the host.
[ "Parse", "a", "hostport", "string", "a", "concept", "that", "floats", "around", "the", "stdlib", "a", "lot", "and", "is", "painful", "to", "work", "with", ".", "If", "no", "port", "is", "present", "what", "s", "usually", "present", "is", "just", "the", ...
3d85a149c8127dad7dd81d6d92df99407e67e874
https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/hostmaybeport.go#L27-L52
16,499
anacrolix/missinggo
resource/resource.go
ReadSeeker
func ReadSeeker(r Instance) io.ReadSeeker { fi, err := r.Stat() if err != nil { return nil } return io.NewSectionReader(r, 0, fi.Size()) }
go
func ReadSeeker(r Instance) io.ReadSeeker { fi, err := r.Stat() if err != nil { return nil } return io.NewSectionReader(r, 0, fi.Size()) }
[ "func", "ReadSeeker", "(", "r", "Instance", ")", "io", ".", "ReadSeeker", "{", "fi", ",", "err", ":=", "r", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "io", ".", "NewSectionReader", "(", ...
// Creates a io.ReadSeeker to an Instance.
[ "Creates", "a", "io", ".", "ReadSeeker", "to", "an", "Instance", "." ]
3d85a149c8127dad7dd81d6d92df99407e67e874
https://github.com/anacrolix/missinggo/blob/3d85a149c8127dad7dd81d6d92df99407e67e874/resource/resource.go#L20-L26