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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
27,300 | vulcand/oxy | roundrobin/rebalancer.go | Servers | func (rb *Rebalancer) Servers() []*url.URL {
rb.mtx.Lock()
defer rb.mtx.Unlock()
return rb.next.Servers()
} | go | func (rb *Rebalancer) Servers() []*url.URL {
rb.mtx.Lock()
defer rb.mtx.Unlock()
return rb.next.Servers()
} | [
"func",
"(",
"rb",
"*",
"Rebalancer",
")",
"Servers",
"(",
")",
"[",
"]",
"*",
"url",
".",
"URL",
"{",
"rb",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"rb",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"rb",
".",
"next",
"."... | // Servers gets all servers | [
"Servers",
"gets",
"all",
"servers"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L158-L163 |
27,301 | vulcand/oxy | roundrobin/rebalancer.go | Wrap | func (rb *Rebalancer) Wrap(next balancerHandler) error {
if rb.next != nil {
return fmt.Errorf("already bound to %T", rb.next)
}
rb.next = next
return nil
} | go | func (rb *Rebalancer) Wrap(next balancerHandler) error {
if rb.next != nil {
return fmt.Errorf("already bound to %T", rb.next)
}
rb.next = next
return nil
} | [
"func",
"(",
"rb",
"*",
"Rebalancer",
")",
"Wrap",
"(",
"next",
"balancerHandler",
")",
"error",
"{",
"if",
"rb",
".",
"next",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rb",
".",
"next",
")",
"\n",
"}",
"\n",
"rb",
... | // Wrap sets the next handler to be called by rebalancer handler. | [
"Wrap",
"sets",
"the",
"next",
"handler",
"to",
"be",
"called",
"by",
"rebalancer",
"handler",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L240-L246 |
27,302 | vulcand/oxy | roundrobin/rebalancer.go | UpsertServer | func (rb *Rebalancer) UpsertServer(u *url.URL, options ...ServerOption) error {
rb.mtx.Lock()
defer rb.mtx.Unlock()
if err := rb.next.UpsertServer(u, options...); err != nil {
return err
}
weight, _ := rb.next.ServerWeight(u)
if err := rb.upsertServer(u, weight); err != nil {
rb.next.RemoveServer(u)
return... | go | func (rb *Rebalancer) UpsertServer(u *url.URL, options ...ServerOption) error {
rb.mtx.Lock()
defer rb.mtx.Unlock()
if err := rb.next.UpsertServer(u, options...); err != nil {
return err
}
weight, _ := rb.next.ServerWeight(u)
if err := rb.upsertServer(u, weight); err != nil {
rb.next.RemoveServer(u)
return... | [
"func",
"(",
"rb",
"*",
"Rebalancer",
")",
"UpsertServer",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"options",
"...",
"ServerOption",
")",
"error",
"{",
"rb",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"rb",
".",
"mtx",
".",
"Unlock",
"(",
"... | // UpsertServer upsert a server | [
"UpsertServer",
"upsert",
"a",
"server"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L249-L263 |
27,303 | vulcand/oxy | roundrobin/rebalancer.go | adjustWeights | func (rb *Rebalancer) adjustWeights() {
rb.mtx.Lock()
defer rb.mtx.Unlock()
// In this case adjusting weights would have no effect, so do nothing
if len(rb.servers) < 2 {
return
}
// Metrics are not ready
if !rb.metricsReady() {
return
}
if !rb.timerExpired() {
return
}
if rb.markServers() {
if rb.s... | go | func (rb *Rebalancer) adjustWeights() {
rb.mtx.Lock()
defer rb.mtx.Unlock()
// In this case adjusting weights would have no effect, so do nothing
if len(rb.servers) < 2 {
return
}
// Metrics are not ready
if !rb.metricsReady() {
return
}
if !rb.timerExpired() {
return
}
if rb.markServers() {
if rb.s... | [
"func",
"(",
"rb",
"*",
"Rebalancer",
")",
"adjustWeights",
"(",
")",
"{",
"rb",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"rb",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"// In this case adjusting weights would have no effect, so do nothing",
"if",... | // adjustWeights Called on every load balancer ServeHTTP call, returns the suggested weights
// on every call, can adjust weights if needed. | [
"adjustWeights",
"Called",
"on",
"every",
"load",
"balancer",
"ServeHTTP",
"call",
"returns",
"the",
"suggested",
"weights",
"on",
"every",
"call",
"can",
"adjust",
"weights",
"if",
"needed",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L318-L342 |
27,304 | vulcand/oxy | roundrobin/rebalancer.go | markServers | func (rb *Rebalancer) markServers() bool {
for i, srv := range rb.servers {
rb.ratings[i] = srv.meter.Rating()
}
g, b := memmetrics.SplitFloat64(splitThreshold, 0, rb.ratings)
for i, srv := range rb.servers {
if g[rb.ratings[i]] {
srv.good = true
} else {
srv.good = false
}
}
if len(g) != 0 && len(b... | go | func (rb *Rebalancer) markServers() bool {
for i, srv := range rb.servers {
rb.ratings[i] = srv.meter.Rating()
}
g, b := memmetrics.SplitFloat64(splitThreshold, 0, rb.ratings)
for i, srv := range rb.servers {
if g[rb.ratings[i]] {
srv.good = true
} else {
srv.good = false
}
}
if len(g) != 0 && len(b... | [
"func",
"(",
"rb",
"*",
"Rebalancer",
")",
"markServers",
"(",
")",
"bool",
"{",
"for",
"i",
",",
"srv",
":=",
"range",
"rb",
".",
"servers",
"{",
"rb",
".",
"ratings",
"[",
"i",
"]",
"=",
"srv",
".",
"meter",
".",
"Rating",
"(",
")",
"\n",
"}"... | // markServers splits servers into two groups of servers with bad and good failure rate.
// It does compare relative performances of the servers though, so if all servers have approximately the same error rate
// this function returns the result as if all servers are equally good. | [
"markServers",
"splits",
"servers",
"into",
"two",
"groups",
"of",
"servers",
"with",
"bad",
"and",
"good",
"failure",
"rate",
".",
"It",
"does",
"compare",
"relative",
"performances",
"of",
"the",
"servers",
"though",
"so",
"if",
"all",
"servers",
"have",
"... | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L392-L408 |
27,305 | vulcand/oxy | roundrobin/rebalancer.go | Record | func (n *codeMeter) Record(code int, d time.Duration) {
if code >= n.codeS && code < n.codeE {
n.r.IncA(1)
} else {
n.r.IncB(1)
}
} | go | func (n *codeMeter) Record(code int, d time.Duration) {
if code >= n.codeS && code < n.codeE {
n.r.IncA(1)
} else {
n.r.IncB(1)
}
} | [
"func",
"(",
"n",
"*",
"codeMeter",
")",
"Record",
"(",
"code",
"int",
",",
"d",
"time",
".",
"Duration",
")",
"{",
"if",
"code",
">=",
"n",
".",
"codeS",
"&&",
"code",
"<",
"n",
".",
"codeE",
"{",
"n",
".",
"r",
".",
"IncA",
"(",
"1",
")",
... | // Record records a meter | [
"Record",
"records",
"a",
"meter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L492-L498 |
27,306 | vulcand/oxy | memmetrics/histogram.go | NewHDRHistogram | func NewHDRHistogram(low, high int64, sigfigs int) (h *HDRHistogram, err error) {
defer func() {
if msg := recover(); msg != nil {
err = fmt.Errorf("%s", msg)
}
}()
return &HDRHistogram{
low: low,
high: high,
sigfigs: sigfigs,
h: hdrhistogram.New(low, high, sigfigs),
}, nil
} | go | func NewHDRHistogram(low, high int64, sigfigs int) (h *HDRHistogram, err error) {
defer func() {
if msg := recover(); msg != nil {
err = fmt.Errorf("%s", msg)
}
}()
return &HDRHistogram{
low: low,
high: high,
sigfigs: sigfigs,
h: hdrhistogram.New(low, high, sigfigs),
}, nil
} | [
"func",
"NewHDRHistogram",
"(",
"low",
",",
"high",
"int64",
",",
"sigfigs",
"int",
")",
"(",
"h",
"*",
"HDRHistogram",
",",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"msg",
":=",
"recover",
"(",
")",
";",
"msg",
"!=",
"nil",
... | // NewHDRHistogram creates a new HDRHistogram | [
"NewHDRHistogram",
"creates",
"a",
"new",
"HDRHistogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L24-L36 |
27,307 | vulcand/oxy | memmetrics/histogram.go | Export | func (h *HDRHistogram) Export() *HDRHistogram {
var hist *hdrhistogram.Histogram
if h.h != nil {
snapshot := h.h.Export()
hist = hdrhistogram.Import(snapshot)
}
return &HDRHistogram{low: h.low, high: h.high, sigfigs: h.sigfigs, h: hist}
} | go | func (h *HDRHistogram) Export() *HDRHistogram {
var hist *hdrhistogram.Histogram
if h.h != nil {
snapshot := h.h.Export()
hist = hdrhistogram.Import(snapshot)
}
return &HDRHistogram{low: h.low, high: h.high, sigfigs: h.sigfigs, h: hist}
} | [
"func",
"(",
"h",
"*",
"HDRHistogram",
")",
"Export",
"(",
")",
"*",
"HDRHistogram",
"{",
"var",
"hist",
"*",
"hdrhistogram",
".",
"Histogram",
"\n",
"if",
"h",
".",
"h",
"!=",
"nil",
"{",
"snapshot",
":=",
"h",
".",
"h",
".",
"Export",
"(",
")",
... | // Export export a HDRHistogram | [
"Export",
"export",
"a",
"HDRHistogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L39-L46 |
27,308 | vulcand/oxy | memmetrics/histogram.go | LatencyAtQuantile | func (h *HDRHistogram) LatencyAtQuantile(q float64) time.Duration {
return time.Duration(h.ValueAtQuantile(q)) * time.Microsecond
} | go | func (h *HDRHistogram) LatencyAtQuantile(q float64) time.Duration {
return time.Duration(h.ValueAtQuantile(q)) * time.Microsecond
} | [
"func",
"(",
"h",
"*",
"HDRHistogram",
")",
"LatencyAtQuantile",
"(",
"q",
"float64",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Duration",
"(",
"h",
".",
"ValueAtQuantile",
"(",
"q",
")",
")",
"*",
"time",
".",
"Microsecond",
"\n",
"}"... | // LatencyAtQuantile sets latency at quantile with microsecond precision | [
"LatencyAtQuantile",
"sets",
"latency",
"at",
"quantile",
"with",
"microsecond",
"precision"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L49-L51 |
27,309 | vulcand/oxy | memmetrics/histogram.go | RecordLatencies | func (h *HDRHistogram) RecordLatencies(d time.Duration, n int64) error {
return h.RecordValues(int64(d/time.Microsecond), n)
} | go | func (h *HDRHistogram) RecordLatencies(d time.Duration, n int64) error {
return h.RecordValues(int64(d/time.Microsecond), n)
} | [
"func",
"(",
"h",
"*",
"HDRHistogram",
")",
"RecordLatencies",
"(",
"d",
"time",
".",
"Duration",
",",
"n",
"int64",
")",
"error",
"{",
"return",
"h",
".",
"RecordValues",
"(",
"int64",
"(",
"d",
"/",
"time",
".",
"Microsecond",
")",
",",
"n",
")",
... | // RecordLatencies Records latencies with microsecond precision | [
"RecordLatencies",
"Records",
"latencies",
"with",
"microsecond",
"precision"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L54-L56 |
27,310 | vulcand/oxy | memmetrics/histogram.go | ValueAtQuantile | func (h *HDRHistogram) ValueAtQuantile(q float64) int64 {
return h.h.ValueAtQuantile(q)
} | go | func (h *HDRHistogram) ValueAtQuantile(q float64) int64 {
return h.h.ValueAtQuantile(q)
} | [
"func",
"(",
"h",
"*",
"HDRHistogram",
")",
"ValueAtQuantile",
"(",
"q",
"float64",
")",
"int64",
"{",
"return",
"h",
".",
"h",
".",
"ValueAtQuantile",
"(",
"q",
")",
"\n",
"}"
] | // ValueAtQuantile sets value at quantile | [
"ValueAtQuantile",
"sets",
"value",
"at",
"quantile"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L64-L66 |
27,311 | vulcand/oxy | memmetrics/histogram.go | RecordValues | func (h *HDRHistogram) RecordValues(v, n int64) error {
return h.h.RecordValues(v, n)
} | go | func (h *HDRHistogram) RecordValues(v, n int64) error {
return h.h.RecordValues(v, n)
} | [
"func",
"(",
"h",
"*",
"HDRHistogram",
")",
"RecordValues",
"(",
"v",
",",
"n",
"int64",
")",
"error",
"{",
"return",
"h",
".",
"h",
".",
"RecordValues",
"(",
"v",
",",
"n",
")",
"\n",
"}"
] | // RecordValues sets record values | [
"RecordValues",
"sets",
"record",
"values"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L69-L71 |
27,312 | vulcand/oxy | memmetrics/histogram.go | Merge | func (h *HDRHistogram) Merge(other *HDRHistogram) error {
if other == nil {
return fmt.Errorf("other is nil")
}
h.h.Merge(other.h)
return nil
} | go | func (h *HDRHistogram) Merge(other *HDRHistogram) error {
if other == nil {
return fmt.Errorf("other is nil")
}
h.h.Merge(other.h)
return nil
} | [
"func",
"(",
"h",
"*",
"HDRHistogram",
")",
"Merge",
"(",
"other",
"*",
"HDRHistogram",
")",
"error",
"{",
"if",
"other",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"h",
".",
"h",
".",
"Merge",
"(",
... | // Merge merge a HDRHistogram | [
"Merge",
"merge",
"a",
"HDRHistogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L74-L80 |
27,313 | vulcand/oxy | memmetrics/histogram.go | RollingClock | func RollingClock(clock timetools.TimeProvider) rhOptSetter {
return func(r *RollingHDRHistogram) error {
r.clock = clock
return nil
}
} | go | func RollingClock(clock timetools.TimeProvider) rhOptSetter {
return func(r *RollingHDRHistogram) error {
r.clock = clock
return nil
}
} | [
"func",
"RollingClock",
"(",
"clock",
"timetools",
".",
"TimeProvider",
")",
"rhOptSetter",
"{",
"return",
"func",
"(",
"r",
"*",
"RollingHDRHistogram",
")",
"error",
"{",
"r",
".",
"clock",
"=",
"clock",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RollingClock sets a clock | [
"RollingClock",
"sets",
"a",
"clock"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L85-L90 |
27,314 | vulcand/oxy | memmetrics/histogram.go | NewRollingHDRHistogram | func NewRollingHDRHistogram(low, high int64, sigfigs int, period time.Duration, bucketCount int, options ...rhOptSetter) (*RollingHDRHistogram, error) {
rh := &RollingHDRHistogram{
bucketCount: bucketCount,
period: period,
low: low,
high: high,
sigfigs: sigfigs,
}
for _, o := range... | go | func NewRollingHDRHistogram(low, high int64, sigfigs int, period time.Duration, bucketCount int, options ...rhOptSetter) (*RollingHDRHistogram, error) {
rh := &RollingHDRHistogram{
bucketCount: bucketCount,
period: period,
low: low,
high: high,
sigfigs: sigfigs,
}
for _, o := range... | [
"func",
"NewRollingHDRHistogram",
"(",
"low",
",",
"high",
"int64",
",",
"sigfigs",
"int",
",",
"period",
"time",
".",
"Duration",
",",
"bucketCount",
"int",
",",
"options",
"...",
"rhOptSetter",
")",
"(",
"*",
"RollingHDRHistogram",
",",
"error",
")",
"{",
... | // NewRollingHDRHistogram created a new RollingHDRHistogram | [
"NewRollingHDRHistogram",
"created",
"a",
"new",
"RollingHDRHistogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L107-L136 |
27,315 | vulcand/oxy | memmetrics/histogram.go | Export | func (r *RollingHDRHistogram) Export() *RollingHDRHistogram {
export := &RollingHDRHistogram{}
export.idx = r.idx
export.lastRoll = r.lastRoll
export.period = r.period
export.bucketCount = r.bucketCount
export.low = r.low
export.high = r.high
export.sigfigs = r.sigfigs
export.clock = r.clock
exportBuckets :=... | go | func (r *RollingHDRHistogram) Export() *RollingHDRHistogram {
export := &RollingHDRHistogram{}
export.idx = r.idx
export.lastRoll = r.lastRoll
export.period = r.period
export.bucketCount = r.bucketCount
export.low = r.low
export.high = r.high
export.sigfigs = r.sigfigs
export.clock = r.clock
exportBuckets :=... | [
"func",
"(",
"r",
"*",
"RollingHDRHistogram",
")",
"Export",
"(",
")",
"*",
"RollingHDRHistogram",
"{",
"export",
":=",
"&",
"RollingHDRHistogram",
"{",
"}",
"\n",
"export",
".",
"idx",
"=",
"r",
".",
"idx",
"\n",
"export",
".",
"lastRoll",
"=",
"r",
"... | // Export export a RollingHDRHistogram | [
"Export",
"export",
"a",
"RollingHDRHistogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L139-L157 |
27,316 | vulcand/oxy | memmetrics/histogram.go | Append | func (r *RollingHDRHistogram) Append(o *RollingHDRHistogram) error {
if r.bucketCount != o.bucketCount || r.period != o.period || r.low != o.low || r.high != o.high || r.sigfigs != o.sigfigs {
return fmt.Errorf("can't merge")
}
for i := range r.buckets {
if err := r.buckets[i].Merge(o.buckets[i]); err != nil {
... | go | func (r *RollingHDRHistogram) Append(o *RollingHDRHistogram) error {
if r.bucketCount != o.bucketCount || r.period != o.period || r.low != o.low || r.high != o.high || r.sigfigs != o.sigfigs {
return fmt.Errorf("can't merge")
}
for i := range r.buckets {
if err := r.buckets[i].Merge(o.buckets[i]); err != nil {
... | [
"func",
"(",
"r",
"*",
"RollingHDRHistogram",
")",
"Append",
"(",
"o",
"*",
"RollingHDRHistogram",
")",
"error",
"{",
"if",
"r",
".",
"bucketCount",
"!=",
"o",
".",
"bucketCount",
"||",
"r",
".",
"period",
"!=",
"o",
".",
"period",
"||",
"r",
".",
"l... | // Append append a RollingHDRHistogram | [
"Append",
"append",
"a",
"RollingHDRHistogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L160-L171 |
27,317 | vulcand/oxy | memmetrics/histogram.go | Reset | func (r *RollingHDRHistogram) Reset() {
r.idx = 0
r.lastRoll = r.clock.UtcNow()
for _, b := range r.buckets {
b.Reset()
}
} | go | func (r *RollingHDRHistogram) Reset() {
r.idx = 0
r.lastRoll = r.clock.UtcNow()
for _, b := range r.buckets {
b.Reset()
}
} | [
"func",
"(",
"r",
"*",
"RollingHDRHistogram",
")",
"Reset",
"(",
")",
"{",
"r",
".",
"idx",
"=",
"0",
"\n",
"r",
".",
"lastRoll",
"=",
"r",
".",
"clock",
".",
"UtcNow",
"(",
")",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"r",
".",
"buckets",
... | // Reset reset a RollingHDRHistogram | [
"Reset",
"reset",
"a",
"RollingHDRHistogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L174-L180 |
27,318 | vulcand/oxy | memmetrics/histogram.go | Merged | func (r *RollingHDRHistogram) Merged() (*HDRHistogram, error) {
m, err := NewHDRHistogram(r.low, r.high, r.sigfigs)
if err != nil {
return m, err
}
for _, h := range r.buckets {
if errMerge := m.Merge(h); errMerge != nil {
return nil, errMerge
}
}
return m, nil
} | go | func (r *RollingHDRHistogram) Merged() (*HDRHistogram, error) {
m, err := NewHDRHistogram(r.low, r.high, r.sigfigs)
if err != nil {
return m, err
}
for _, h := range r.buckets {
if errMerge := m.Merge(h); errMerge != nil {
return nil, errMerge
}
}
return m, nil
} | [
"func",
"(",
"r",
"*",
"RollingHDRHistogram",
")",
"Merged",
"(",
")",
"(",
"*",
"HDRHistogram",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"NewHDRHistogram",
"(",
"r",
".",
"low",
",",
"r",
".",
"high",
",",
"r",
".",
"sigfigs",
")",
"\n",
"... | // Merged gets merged histogram | [
"Merged",
"gets",
"merged",
"histogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L188-L199 |
27,319 | vulcand/oxy | memmetrics/histogram.go | RecordLatencies | func (r *RollingHDRHistogram) RecordLatencies(v time.Duration, n int64) error {
return r.getHist().RecordLatencies(v, n)
} | go | func (r *RollingHDRHistogram) RecordLatencies(v time.Duration, n int64) error {
return r.getHist().RecordLatencies(v, n)
} | [
"func",
"(",
"r",
"*",
"RollingHDRHistogram",
")",
"RecordLatencies",
"(",
"v",
"time",
".",
"Duration",
",",
"n",
"int64",
")",
"error",
"{",
"return",
"r",
".",
"getHist",
"(",
")",
".",
"RecordLatencies",
"(",
"v",
",",
"n",
")",
"\n",
"}"
] | // RecordLatencies sets records latencies | [
"RecordLatencies",
"sets",
"records",
"latencies"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L210-L212 |
27,320 | vulcand/oxy | memmetrics/histogram.go | RecordValues | func (r *RollingHDRHistogram) RecordValues(v, n int64) error {
return r.getHist().RecordValues(v, n)
} | go | func (r *RollingHDRHistogram) RecordValues(v, n int64) error {
return r.getHist().RecordValues(v, n)
} | [
"func",
"(",
"r",
"*",
"RollingHDRHistogram",
")",
"RecordValues",
"(",
"v",
",",
"n",
"int64",
")",
"error",
"{",
"return",
"r",
".",
"getHist",
"(",
")",
".",
"RecordValues",
"(",
"v",
",",
"n",
")",
"\n",
"}"
] | // RecordValues set record values | [
"RecordValues",
"set",
"record",
"values"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/histogram.go#L215-L217 |
27,321 | vulcand/oxy | stream/threshold.go | IsValidExpression | func IsValidExpression(expr string) bool {
_, err := parseExpression(expr)
return err == nil
} | go | func IsValidExpression(expr string) bool {
_, err := parseExpression(expr)
return err == nil
} | [
"func",
"IsValidExpression",
"(",
"expr",
"string",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"parseExpression",
"(",
"expr",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsValidExpression check if it's a valid expression | [
"IsValidExpression",
"check",
"if",
"it",
"s",
"a",
"valid",
"expression"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/stream/threshold.go#L11-L14 |
27,322 | vulcand/oxy | stream/threshold.go | lt | func lt(m interface{}, value interface{}) (hpredicate, error) {
switch mapper := m.(type) {
case toInt:
return intLT(mapper, value)
}
return nil, fmt.Errorf("unsupported argument: %T", m)
} | go | func lt(m interface{}, value interface{}) (hpredicate, error) {
switch mapper := m.(type) {
case toInt:
return intLT(mapper, value)
}
return nil, fmt.Errorf("unsupported argument: %T", m)
} | [
"func",
"lt",
"(",
"m",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"hpredicate",
",",
"error",
")",
"{",
"switch",
"mapper",
":=",
"m",
".",
"(",
"type",
")",
"{",
"case",
"toInt",
":",
"return",
"intLT",
"(",
"mapper",
... | // lt returns predicate that tests that value of the mapper function is less than the constant | [
"lt",
"returns",
"predicate",
"that",
"tests",
"that",
"value",
"of",
"the",
"mapper",
"function",
"is",
"less",
"than",
"the",
"constant"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/stream/threshold.go#L141-L147 |
27,323 | vulcand/oxy | roundrobin/stickysessions.go | GetBackend | func (s *StickySession) GetBackend(req *http.Request, servers []*url.URL) (*url.URL, bool, error) {
cookie, err := req.Cookie(s.cookieName)
switch err {
case nil:
case http.ErrNoCookie:
return nil, false, nil
default:
return nil, false, err
}
serverURL, err := url.Parse(cookie.Value)
if err != nil {
retu... | go | func (s *StickySession) GetBackend(req *http.Request, servers []*url.URL) (*url.URL, bool, error) {
cookie, err := req.Cookie(s.cookieName)
switch err {
case nil:
case http.ErrNoCookie:
return nil, false, nil
default:
return nil, false, err
}
serverURL, err := url.Parse(cookie.Value)
if err != nil {
retu... | [
"func",
"(",
"s",
"*",
"StickySession",
")",
"GetBackend",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"servers",
"[",
"]",
"*",
"url",
".",
"URL",
")",
"(",
"*",
"url",
".",
"URL",
",",
"bool",
",",
"error",
")",
"{",
"cookie",
",",
"err",
"... | // GetBackend returns the backend URL stored in the sticky cookie, iff the backend is still in the valid list of servers. | [
"GetBackend",
"returns",
"the",
"backend",
"URL",
"stored",
"in",
"the",
"sticky",
"cookie",
"iff",
"the",
"backend",
"is",
"still",
"in",
"the",
"valid",
"list",
"of",
"servers",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/stickysessions.go#L19-L38 |
27,324 | vulcand/oxy | roundrobin/stickysessions.go | StickBackend | func (s *StickySession) StickBackend(backend *url.URL, w *http.ResponseWriter) {
cookie := &http.Cookie{Name: s.cookieName, Value: backend.String(), Path: "/"}
http.SetCookie(*w, cookie)
} | go | func (s *StickySession) StickBackend(backend *url.URL, w *http.ResponseWriter) {
cookie := &http.Cookie{Name: s.cookieName, Value: backend.String(), Path: "/"}
http.SetCookie(*w, cookie)
} | [
"func",
"(",
"s",
"*",
"StickySession",
")",
"StickBackend",
"(",
"backend",
"*",
"url",
".",
"URL",
",",
"w",
"*",
"http",
".",
"ResponseWriter",
")",
"{",
"cookie",
":=",
"&",
"http",
".",
"Cookie",
"{",
"Name",
":",
"s",
".",
"cookieName",
",",
... | // StickBackend creates and sets the cookie | [
"StickBackend",
"creates",
"and",
"sets",
"the",
"cookie"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/stickysessions.go#L41-L44 |
27,325 | vulcand/oxy | forward/fwd.go | PassHostHeader | func PassHostHeader(b bool) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.passHost = b
return nil
}
} | go | func PassHostHeader(b bool) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.passHost = b
return nil
}
} | [
"func",
"PassHostHeader",
"(",
"b",
"bool",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"httpForwarder",
".",
"passHost",
"=",
"b",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // PassHostHeader specifies if a client's Host header field should be delegated | [
"PassHostHeader",
"specifies",
"if",
"a",
"client",
"s",
"Host",
"header",
"field",
"should",
"be",
"delegated"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L49-L54 |
27,326 | vulcand/oxy | forward/fwd.go | RoundTripper | func RoundTripper(r http.RoundTripper) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.roundTripper = r
return nil
}
} | go | func RoundTripper(r http.RoundTripper) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.roundTripper = r
return nil
}
} | [
"func",
"RoundTripper",
"(",
"r",
"http",
".",
"RoundTripper",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"httpForwarder",
".",
"roundTripper",
"=",
"r",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"... | // RoundTripper sets a new http.RoundTripper
// Forwarder will use http.DefaultTransport as a default round tripper | [
"RoundTripper",
"sets",
"a",
"new",
"http",
".",
"RoundTripper",
"Forwarder",
"will",
"use",
"http",
".",
"DefaultTransport",
"as",
"a",
"default",
"round",
"tripper"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L58-L63 |
27,327 | vulcand/oxy | forward/fwd.go | Rewriter | func Rewriter(r ReqRewriter) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.rewriter = r
return nil
}
} | go | func Rewriter(r ReqRewriter) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.rewriter = r
return nil
}
} | [
"func",
"Rewriter",
"(",
"r",
"ReqRewriter",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"httpForwarder",
".",
"rewriter",
"=",
"r",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Rewriter defines a request rewriter for the HTTP forwarder | [
"Rewriter",
"defines",
"a",
"request",
"rewriter",
"for",
"the",
"HTTP",
"forwarder"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L66-L71 |
27,328 | vulcand/oxy | forward/fwd.go | WebsocketTLSClientConfig | func WebsocketTLSClientConfig(tcc *tls.Config) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.tlsClientConfig = tcc
return nil
}
} | go | func WebsocketTLSClientConfig(tcc *tls.Config) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.tlsClientConfig = tcc
return nil
}
} | [
"func",
"WebsocketTLSClientConfig",
"(",
"tcc",
"*",
"tls",
".",
"Config",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"httpForwarder",
".",
"tlsClientConfig",
"=",
"tcc",
"\n",
"return",
"nil",
"\n",
... | // WebsocketTLSClientConfig define the websocker client TLS configuration | [
"WebsocketTLSClientConfig",
"define",
"the",
"websocker",
"client",
"TLS",
"configuration"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L74-L79 |
27,329 | vulcand/oxy | forward/fwd.go | BufferPool | func BufferPool(pool httputil.BufferPool) optSetter {
return func(f *Forwarder) error {
f.bufferPool = pool
return nil
}
} | go | func BufferPool(pool httputil.BufferPool) optSetter {
return func(f *Forwarder) error {
f.bufferPool = pool
return nil
}
} | [
"func",
"BufferPool",
"(",
"pool",
"httputil",
".",
"BufferPool",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"bufferPool",
"=",
"pool",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // BufferPool specifies a buffer pool for httputil.ReverseProxy. | [
"BufferPool",
"specifies",
"a",
"buffer",
"pool",
"for",
"httputil",
".",
"ReverseProxy",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L90-L95 |
27,330 | vulcand/oxy | forward/fwd.go | Stream | func Stream(stream bool) optSetter {
return func(f *Forwarder) error {
f.stream = stream
return nil
}
} | go | func Stream(stream bool) optSetter {
return func(f *Forwarder) error {
f.stream = stream
return nil
}
} | [
"func",
"Stream",
"(",
"stream",
"bool",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"stream",
"=",
"stream",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Stream specifies if HTTP responses should be streamed. | [
"Stream",
"specifies",
"if",
"HTTP",
"responses",
"should",
"be",
"streamed",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L98-L103 |
27,331 | vulcand/oxy | forward/fwd.go | StateListener | func StateListener(stateListener UrlForwardingStateListener) optSetter {
return func(f *Forwarder) error {
f.stateListener = stateListener
return nil
}
} | go | func StateListener(stateListener UrlForwardingStateListener) optSetter {
return func(f *Forwarder) error {
f.stateListener = stateListener
return nil
}
} | [
"func",
"StateListener",
"(",
"stateListener",
"UrlForwardingStateListener",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"stateListener",
"=",
"stateListener",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // StateListener defines a state listener for the HTTP forwarder | [
"StateListener",
"defines",
"a",
"state",
"listener",
"for",
"the",
"HTTP",
"forwarder"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L125-L130 |
27,332 | vulcand/oxy | forward/fwd.go | WebsocketConnectionClosedHook | func WebsocketConnectionClosedHook(hook func(req *http.Request, conn net.Conn)) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.websocketConnectionClosedHook = hook
return nil
}
} | go | func WebsocketConnectionClosedHook(hook func(req *http.Request, conn net.Conn)) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.websocketConnectionClosedHook = hook
return nil
}
} | [
"func",
"WebsocketConnectionClosedHook",
"(",
"hook",
"func",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"conn",
"net",
".",
"Conn",
")",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"httpForwarder"... | // WebsocketConnectionClosedHook defines a hook called when websocket connection is closed | [
"WebsocketConnectionClosedHook",
"defines",
"a",
"hook",
"called",
"when",
"websocket",
"connection",
"is",
"closed"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L133-L138 |
27,333 | vulcand/oxy | forward/fwd.go | ResponseModifier | func ResponseModifier(responseModifier func(*http.Response) error) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.modifyResponse = responseModifier
return nil
}
} | go | func ResponseModifier(responseModifier func(*http.Response) error) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.modifyResponse = responseModifier
return nil
}
} | [
"func",
"ResponseModifier",
"(",
"responseModifier",
"func",
"(",
"*",
"http",
".",
"Response",
")",
"error",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"httpForwarder",
".",
"modifyResponse",
"=",
"re... | // ResponseModifier defines a response modifier for the HTTP forwarder | [
"ResponseModifier",
"defines",
"a",
"response",
"modifier",
"for",
"the",
"HTTP",
"forwarder"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L141-L146 |
27,334 | vulcand/oxy | forward/fwd.go | StreamingFlushInterval | func StreamingFlushInterval(flushInterval time.Duration) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.flushInterval = flushInterval
return nil
}
} | go | func StreamingFlushInterval(flushInterval time.Duration) optSetter {
return func(f *Forwarder) error {
f.httpForwarder.flushInterval = flushInterval
return nil
}
} | [
"func",
"StreamingFlushInterval",
"(",
"flushInterval",
"time",
".",
"Duration",
")",
"optSetter",
"{",
"return",
"func",
"(",
"f",
"*",
"Forwarder",
")",
"error",
"{",
"f",
".",
"httpForwarder",
".",
"flushInterval",
"=",
"flushInterval",
"\n",
"return",
"nil... | // StreamingFlushInterval defines a streaming flush interval for the HTTP forwarder | [
"StreamingFlushInterval",
"defines",
"a",
"streaming",
"flush",
"interval",
"for",
"the",
"HTTP",
"forwarder"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L149-L154 |
27,335 | vulcand/oxy | forward/fwd.go | RoundTrip | func (rt ErrorHandlingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
res, err := rt.RoundTripper.RoundTrip(req)
if err != nil {
// We use the recorder from httptest because there isn't another `public` implementation of a recorder.
recorder := httptest.NewRecorder()
rt.errorHandler.ServeHT... | go | func (rt ErrorHandlingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
res, err := rt.RoundTripper.RoundTrip(req)
if err != nil {
// We use the recorder from httptest because there isn't another `public` implementation of a recorder.
recorder := httptest.NewRecorder()
rt.errorHandler.ServeHT... | [
"func",
"(",
"rt",
"ErrorHandlingRoundTripper",
")",
"RoundTrip",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"rt",
".",
"RoundTripper",
".",
"RoundTrip",
"(",
"req",... | // RoundTrip executes the round trip | [
"RoundTrip",
"executes",
"the",
"round",
"trip"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L163-L173 |
27,336 | vulcand/oxy | forward/fwd.go | New | func New(setters ...optSetter) (*Forwarder, error) {
f := &Forwarder{
httpForwarder: &httpForwarder{log: &internalLogger{Logger: log.StandardLogger()}},
handlerContext: &handlerContext{},
}
for _, s := range setters {
if err := s(f); err != nil {
return nil, err
}
}
if !f.stream {
f.flushInterval = ... | go | func New(setters ...optSetter) (*Forwarder, error) {
f := &Forwarder{
httpForwarder: &httpForwarder{log: &internalLogger{Logger: log.StandardLogger()}},
handlerContext: &handlerContext{},
}
for _, s := range setters {
if err := s(f); err != nil {
return nil, err
}
}
if !f.stream {
f.flushInterval = ... | [
"func",
"New",
"(",
"setters",
"...",
"optSetter",
")",
"(",
"*",
"Forwarder",
",",
"error",
")",
"{",
"f",
":=",
"&",
"Forwarder",
"{",
"httpForwarder",
":",
"&",
"httpForwarder",
"{",
"log",
":",
"&",
"internalLogger",
"{",
"Logger",
":",
"log",
".",... | // New creates an instance of Forwarder based on the provided list of configuration options | [
"New",
"creates",
"an",
"instance",
"of",
"Forwarder",
"based",
"on",
"the",
"provided",
"list",
"of",
"configuration",
"options"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L218-L265 |
27,337 | vulcand/oxy | forward/fwd.go | ServeHTTP | func (f *Forwarder) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if f.log.GetLevel() >= log.DebugLevel {
logEntry := f.log.WithField("Request", utils.DumpHttpRequest(req))
logEntry.Debug("vulcand/oxy/forward: begin ServeHttp on request")
defer logEntry.Debug("vulcand/oxy/forward: completed ServeHttp on ... | go | func (f *Forwarder) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if f.log.GetLevel() >= log.DebugLevel {
logEntry := f.log.WithField("Request", utils.DumpHttpRequest(req))
logEntry.Debug("vulcand/oxy/forward: begin ServeHttp on request")
defer logEntry.Debug("vulcand/oxy/forward: completed ServeHttp on ... | [
"func",
"(",
"f",
"*",
"Forwarder",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"f",
".",
"log",
".",
"GetLevel",
"(",
")",
">=",
"log",
".",
"DebugLevel",
"{",
"logEntry",
":=... | // ServeHTTP decides which forwarder to use based on the specified
// request and delegates to the proper implementation | [
"ServeHTTP",
"decides",
"which",
"forwarder",
"to",
"use",
"based",
"on",
"the",
"specified",
"request",
"and",
"delegates",
"to",
"the",
"proper",
"implementation"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L269-L285 |
27,338 | vulcand/oxy | forward/fwd.go | copyWebSocketRequest | func (f *httpForwarder) copyWebSocketRequest(req *http.Request) (outReq *http.Request) {
outReq = new(http.Request)
*outReq = *req // includes shallow copies of maps, but we handle this below
outReq.URL = utils.CopyURL(req.URL)
outReq.URL.Scheme = req.URL.Scheme
// sometimes backends might be registered as HTTP/... | go | func (f *httpForwarder) copyWebSocketRequest(req *http.Request) (outReq *http.Request) {
outReq = new(http.Request)
*outReq = *req // includes shallow copies of maps, but we handle this below
outReq.URL = utils.CopyURL(req.URL)
outReq.URL.Scheme = req.URL.Scheme
// sometimes backends might be registered as HTTP/... | [
"func",
"(",
"f",
"*",
"httpForwarder",
")",
"copyWebSocketRequest",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"outReq",
"*",
"http",
".",
"Request",
")",
"{",
"outReq",
"=",
"new",
"(",
"http",
".",
"Request",
")",
"\n",
"*",
"outReq",
"=",... | // copyWebsocketRequest makes a copy of the specified request. | [
"copyWebsocketRequest",
"makes",
"a",
"copy",
"of",
"the",
"specified",
"request",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L471-L508 |
27,339 | vulcand/oxy | forward/fwd.go | serveHTTP | func (f *httpForwarder) serveHTTP(w http.ResponseWriter, inReq *http.Request, ctx *handlerContext) {
if f.log.GetLevel() >= log.DebugLevel {
logEntry := f.log.WithField("Request", utils.DumpHttpRequest(inReq))
logEntry.Debug("vulcand/oxy/forward/http: begin ServeHttp on request")
defer logEntry.Debug("vulcand/ox... | go | func (f *httpForwarder) serveHTTP(w http.ResponseWriter, inReq *http.Request, ctx *handlerContext) {
if f.log.GetLevel() >= log.DebugLevel {
logEntry := f.log.WithField("Request", utils.DumpHttpRequest(inReq))
logEntry.Debug("vulcand/oxy/forward/http: begin ServeHttp on request")
defer logEntry.Debug("vulcand/ox... | [
"func",
"(",
"f",
"*",
"httpForwarder",
")",
"serveHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"inReq",
"*",
"http",
".",
"Request",
",",
"ctx",
"*",
"handlerContext",
")",
"{",
"if",
"f",
".",
"log",
".",
"GetLevel",
"(",
")",
">=",
"log",
... | // serveHTTP forwards HTTP traffic using the configured transport | [
"serveHTTP",
"forwards",
"HTTP",
"traffic",
"using",
"the",
"configured",
"transport"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L511-L561 |
27,340 | vulcand/oxy | forward/fwd.go | IsWebsocketRequest | func IsWebsocketRequest(req *http.Request) bool {
containsHeader := func(name, value string) bool {
items := strings.Split(req.Header.Get(name), ",")
for _, item := range items {
if value == strings.ToLower(strings.TrimSpace(item)) {
return true
}
}
return false
}
return containsHeader(Connection, ... | go | func IsWebsocketRequest(req *http.Request) bool {
containsHeader := func(name, value string) bool {
items := strings.Split(req.Header.Get(name), ",")
for _, item := range items {
if value == strings.ToLower(strings.TrimSpace(item)) {
return true
}
}
return false
}
return containsHeader(Connection, ... | [
"func",
"IsWebsocketRequest",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"containsHeader",
":=",
"func",
"(",
"name",
",",
"value",
"string",
")",
"bool",
"{",
"items",
":=",
"strings",
".",
"Split",
"(",
"req",
".",
"Header",
".",
"Get... | // IsWebsocketRequest determines if the specified HTTP request is a
// websocket handshake request | [
"IsWebsocketRequest",
"determines",
"if",
"the",
"specified",
"HTTP",
"request",
"is",
"a",
"websocket",
"handshake",
"request"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/fwd.go#L565-L576 |
27,341 | vulcand/oxy | utils/auth.go | ParseAuthHeader | func ParseAuthHeader(header string) (*BasicAuth, error) {
values := strings.Fields(header)
if len(values) != 2 {
return nil, fmt.Errorf(fmt.Sprintf("Failed to parse header '%s'", header))
}
authType := strings.ToLower(values[0])
if authType != "basic" {
return nil, fmt.Errorf("Expected basic auth type, got '%... | go | func ParseAuthHeader(header string) (*BasicAuth, error) {
values := strings.Fields(header)
if len(values) != 2 {
return nil, fmt.Errorf(fmt.Sprintf("Failed to parse header '%s'", header))
}
authType := strings.ToLower(values[0])
if authType != "basic" {
return nil, fmt.Errorf("Expected basic auth type, got '%... | [
"func",
"ParseAuthHeader",
"(",
"header",
"string",
")",
"(",
"*",
"BasicAuth",
",",
"error",
")",
"{",
"values",
":=",
"strings",
".",
"Fields",
"(",
"header",
")",
"\n",
"if",
"len",
"(",
"values",
")",
"!=",
"2",
"{",
"return",
"nil",
",",
"fmt",
... | // ParseAuthHeader creates a new BasicAuth from header values | [
"ParseAuthHeader",
"creates",
"a",
"new",
"BasicAuth",
"from",
"header",
"values"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/auth.go#L21-L43 |
27,342 | vulcand/oxy | utils/dumpreq.go | Clone | func Clone(r *http.Request) *SerializableHttpRequest {
if r == nil {
return nil
}
rc := new(SerializableHttpRequest)
rc.Method = r.Method
rc.URL = r.URL
rc.Proto = r.Proto
rc.ProtoMajor = r.ProtoMajor
rc.ProtoMinor = r.ProtoMinor
rc.Header = r.Header
rc.ContentLength = r.ContentLength
rc.Host = r.Host
rc... | go | func Clone(r *http.Request) *SerializableHttpRequest {
if r == nil {
return nil
}
rc := new(SerializableHttpRequest)
rc.Method = r.Method
rc.URL = r.URL
rc.Proto = r.Proto
rc.ProtoMajor = r.ProtoMajor
rc.ProtoMinor = r.ProtoMinor
rc.Header = r.Header
rc.ContentLength = r.ContentLength
rc.Host = r.Host
rc... | [
"func",
"Clone",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"SerializableHttpRequest",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"rc",
":=",
"new",
"(",
"SerializableHttpRequest",
")",
"\n",
"rc",
".",
"Method",
"=",
... | // Clone clone a request | [
"Clone",
"clone",
"a",
"request"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/dumpreq.go#L33-L50 |
27,343 | vulcand/oxy | utils/dumpreq.go | ToJson | func (s *SerializableHttpRequest) ToJson() string {
jsonVal, err := json.Marshal(s)
if err != nil || jsonVal == nil {
return fmt.Sprintf("Error marshalling SerializableHttpRequest to json: %s", err)
}
return string(jsonVal)
} | go | func (s *SerializableHttpRequest) ToJson() string {
jsonVal, err := json.Marshal(s)
if err != nil || jsonVal == nil {
return fmt.Sprintf("Error marshalling SerializableHttpRequest to json: %s", err)
}
return string(jsonVal)
} | [
"func",
"(",
"s",
"*",
"SerializableHttpRequest",
")",
"ToJson",
"(",
")",
"string",
"{",
"jsonVal",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"jsonVal",
"==",
"nil",
"{",
"return",
"fmt",
".",
"... | // ToJson serializes to JSON | [
"ToJson",
"serializes",
"to",
"JSON"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/dumpreq.go#L53-L59 |
27,344 | vulcand/oxy | stream/stream.go | Wrap | func (s *Stream) Wrap(next http.Handler) error {
s.next = next
return nil
} | go | func (s *Stream) Wrap(next http.Handler) error {
s.next = next
return nil
} | [
"func",
"(",
"s",
"*",
"Stream",
")",
"Wrap",
"(",
"next",
"http",
".",
"Handler",
")",
"error",
"{",
"s",
".",
"next",
"=",
"next",
"\n",
"return",
"nil",
"\n",
"}"
] | // Wrap sets the next handler to be called by stream handler. | [
"Wrap",
"sets",
"the",
"next",
"handler",
"to",
"be",
"called",
"by",
"stream",
"handler",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/stream/stream.go#L93-L96 |
27,345 | vulcand/oxy | utils/source.go | NewExtractor | func NewExtractor(variable string) (SourceExtractor, error) {
if variable == "client.ip" {
return ExtractorFunc(extractClientIP), nil
}
if variable == "request.host" {
return ExtractorFunc(extractHost), nil
}
if strings.HasPrefix(variable, "request.header.") {
header := strings.TrimPrefix(variable, "request.... | go | func NewExtractor(variable string) (SourceExtractor, error) {
if variable == "client.ip" {
return ExtractorFunc(extractClientIP), nil
}
if variable == "request.host" {
return ExtractorFunc(extractHost), nil
}
if strings.HasPrefix(variable, "request.header.") {
header := strings.TrimPrefix(variable, "request.... | [
"func",
"NewExtractor",
"(",
"variable",
"string",
")",
"(",
"SourceExtractor",
",",
"error",
")",
"{",
"if",
"variable",
"==",
"\"",
"\"",
"{",
"return",
"ExtractorFunc",
"(",
"extractClientIP",
")",
",",
"nil",
"\n",
"}",
"\n",
"if",
"variable",
"==",
... | // NewExtractor creates a new SourceExtractor | [
"NewExtractor",
"creates",
"a",
"new",
"SourceExtractor"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/source.go#L28-L43 |
27,346 | vulcand/oxy | roundrobin/rr.go | Weight | func Weight(w int) ServerOption {
return func(s *server) error {
if w < 0 {
return fmt.Errorf("Weight should be >= 0")
}
s.weight = w
return nil
}
} | go | func Weight(w int) ServerOption {
return func(s *server) error {
if w < 0 {
return fmt.Errorf("Weight should be >= 0")
}
s.weight = w
return nil
}
} | [
"func",
"Weight",
"(",
"w",
"int",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"server",
")",
"error",
"{",
"if",
"w",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
".",
"weight",
"=",... | // Weight is an optional functional argument that sets weight of the server | [
"Weight",
"is",
"an",
"optional",
"functional",
"argument",
"that",
"sets",
"weight",
"of",
"the",
"server"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L15-L23 |
27,347 | vulcand/oxy | roundrobin/rr.go | EnableStickySession | func EnableStickySession(stickySession *StickySession) LBOption {
return func(s *RoundRobin) error {
s.stickySession = stickySession
return nil
}
} | go | func EnableStickySession(stickySession *StickySession) LBOption {
return func(s *RoundRobin) error {
s.stickySession = stickySession
return nil
}
} | [
"func",
"EnableStickySession",
"(",
"stickySession",
"*",
"StickySession",
")",
"LBOption",
"{",
"return",
"func",
"(",
"s",
"*",
"RoundRobin",
")",
"error",
"{",
"s",
".",
"stickySession",
"=",
"stickySession",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // EnableStickySession enable sticky session | [
"EnableStickySession",
"enable",
"sticky",
"session"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L34-L39 |
27,348 | vulcand/oxy | roundrobin/rr.go | RoundRobinRequestRewriteListener | func RoundRobinRequestRewriteListener(rrl RequestRewriteListener) LBOption {
return func(s *RoundRobin) error {
s.requestRewriteListener = rrl
return nil
}
} | go | func RoundRobinRequestRewriteListener(rrl RequestRewriteListener) LBOption {
return func(s *RoundRobin) error {
s.requestRewriteListener = rrl
return nil
}
} | [
"func",
"RoundRobinRequestRewriteListener",
"(",
"rrl",
"RequestRewriteListener",
")",
"LBOption",
"{",
"return",
"func",
"(",
"s",
"*",
"RoundRobin",
")",
"error",
"{",
"s",
".",
"requestRewriteListener",
"=",
"rrl",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}... | // RoundRobinRequestRewriteListener is a functional argument that sets error handler of the server | [
"RoundRobinRequestRewriteListener",
"is",
"a",
"functional",
"argument",
"that",
"sets",
"error",
"handler",
"of",
"the",
"server"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L42-L47 |
27,349 | vulcand/oxy | roundrobin/rr.go | New | func New(next http.Handler, opts ...LBOption) (*RoundRobin, error) {
rr := &RoundRobin{
next: next,
index: -1,
mutex: &sync.Mutex{},
servers: []*server{},
stickySession: nil,
log: log.StandardLogger(),
}
for _, o := range opts {
if err := o(rr); err != nil {
return ni... | go | func New(next http.Handler, opts ...LBOption) (*RoundRobin, error) {
rr := &RoundRobin{
next: next,
index: -1,
mutex: &sync.Mutex{},
servers: []*server{},
stickySession: nil,
log: log.StandardLogger(),
}
for _, o := range opts {
if err := o(rr); err != nil {
return ni... | [
"func",
"New",
"(",
"next",
"http",
".",
"Handler",
",",
"opts",
"...",
"LBOption",
")",
"(",
"*",
"RoundRobin",
",",
"error",
")",
"{",
"rr",
":=",
"&",
"RoundRobin",
"{",
"next",
":",
"next",
",",
"index",
":",
"-",
"1",
",",
"mutex",
":",
"&",... | // New created a new RoundRobin | [
"New",
"created",
"a",
"new",
"RoundRobin"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L65-L84 |
27,350 | vulcand/oxy | roundrobin/rr.go | NextServer | func (r *RoundRobin) NextServer() (*url.URL, error) {
srv, err := r.nextServer()
if err != nil {
return nil, err
}
return utils.CopyURL(srv.url), nil
} | go | func (r *RoundRobin) NextServer() (*url.URL, error) {
srv, err := r.nextServer()
if err != nil {
return nil, err
}
return utils.CopyURL(srv.url), nil
} | [
"func",
"(",
"r",
"*",
"RoundRobin",
")",
"NextServer",
"(",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"srv",
",",
"err",
":=",
"r",
".",
"nextServer",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
... | // NextServer gets the next server | [
"NextServer",
"gets",
"the",
"next",
"server"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L151-L157 |
27,351 | vulcand/oxy | roundrobin/rr.go | Servers | func (r *RoundRobin) Servers() []*url.URL {
r.mutex.Lock()
defer r.mutex.Unlock()
out := make([]*url.URL, len(r.servers))
for i, srv := range r.servers {
out[i] = srv.url
}
return out
} | go | func (r *RoundRobin) Servers() []*url.URL {
r.mutex.Lock()
defer r.mutex.Unlock()
out := make([]*url.URL, len(r.servers))
for i, srv := range r.servers {
out[i] = srv.url
}
return out
} | [
"func",
"(",
"r",
"*",
"RoundRobin",
")",
"Servers",
"(",
")",
"[",
"]",
"*",
"url",
".",
"URL",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"out",
":=",
"make",
"(",
"[",
... | // Servers gets servers URL | [
"Servers",
"gets",
"servers",
"URL"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L209-L218 |
27,352 | vulcand/oxy | roundrobin/rr.go | ServerWeight | func (r *RoundRobin) ServerWeight(u *url.URL) (int, bool) {
r.mutex.Lock()
defer r.mutex.Unlock()
if s, _ := r.findServerByURL(u); s != nil {
return s.weight, true
}
return -1, false
} | go | func (r *RoundRobin) ServerWeight(u *url.URL) (int, bool) {
r.mutex.Lock()
defer r.mutex.Unlock()
if s, _ := r.findServerByURL(u); s != nil {
return s.weight, true
}
return -1, false
} | [
"func",
"(",
"r",
"*",
"RoundRobin",
")",
"ServerWeight",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"int",
",",
"bool",
")",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"... | // ServerWeight gets the server weight | [
"ServerWeight",
"gets",
"the",
"server",
"weight"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L221-L229 |
27,353 | vulcand/oxy | roundrobin/rr.go | UpsertServer | func (r *RoundRobin) UpsertServer(u *url.URL, options ...ServerOption) error {
r.mutex.Lock()
defer r.mutex.Unlock()
if u == nil {
return fmt.Errorf("server URL can't be nil")
}
if s, _ := r.findServerByURL(u); s != nil {
for _, o := range options {
if err := o(s); err != nil {
return err
}
}
r... | go | func (r *RoundRobin) UpsertServer(u *url.URL, options ...ServerOption) error {
r.mutex.Lock()
defer r.mutex.Unlock()
if u == nil {
return fmt.Errorf("server URL can't be nil")
}
if s, _ := r.findServerByURL(u); s != nil {
for _, o := range options {
if err := o(s); err != nil {
return err
}
}
r... | [
"func",
"(",
"r",
"*",
"RoundRobin",
")",
"UpsertServer",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"options",
"...",
"ServerOption",
")",
"error",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
... | // UpsertServer In case if server is already present in the load balancer, returns error | [
"UpsertServer",
"In",
"case",
"if",
"server",
"is",
"already",
"present",
"in",
"the",
"load",
"balancer",
"returns",
"error"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L232-L264 |
27,354 | vulcand/oxy | roundrobin/rr.go | SetDefaultWeight | func SetDefaultWeight(weight int) error {
if weight < 0 {
return fmt.Errorf("default weight should be >= 0")
}
defaultWeight = weight
return nil
} | go | func SetDefaultWeight(weight int) error {
if weight < 0 {
return fmt.Errorf("default weight should be >= 0")
}
defaultWeight = weight
return nil
} | [
"func",
"SetDefaultWeight",
"(",
"weight",
"int",
")",
"error",
"{",
"if",
"weight",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defaultWeight",
"=",
"weight",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetDefaultWeight sets the default server weight | [
"SetDefaultWeight",
"sets",
"the",
"default",
"server",
"weight"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rr.go#L332-L338 |
27,355 | vulcand/oxy | ratelimit/tokenlimiter.go | NewRateSet | func NewRateSet() *RateSet {
rs := new(RateSet)
rs.m = make(map[time.Duration]*rate)
return rs
} | go | func NewRateSet() *RateSet {
rs := new(RateSet)
rs.m = make(map[time.Duration]*rate)
return rs
} | [
"func",
"NewRateSet",
"(",
")",
"*",
"RateSet",
"{",
"rs",
":=",
"new",
"(",
"RateSet",
")",
"\n",
"rs",
".",
"m",
"=",
"make",
"(",
"map",
"[",
"time",
".",
"Duration",
"]",
"*",
"rate",
")",
"\n",
"return",
"rs",
"\n",
"}"
] | // NewRateSet crates an empty `RateSet` instance. | [
"NewRateSet",
"crates",
"an",
"empty",
"RateSet",
"instance",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/tokenlimiter.go#L25-L29 |
27,356 | vulcand/oxy | ratelimit/tokenlimiter.go | Add | func (rs *RateSet) Add(period time.Duration, average int64, burst int64) error {
if period <= 0 {
return fmt.Errorf("invalid period: %v", period)
}
if average <= 0 {
return fmt.Errorf("invalid average: %v", average)
}
if burst <= 0 {
return fmt.Errorf("invalid burst: %v", burst)
}
rs.m[period] = &rate{peri... | go | func (rs *RateSet) Add(period time.Duration, average int64, burst int64) error {
if period <= 0 {
return fmt.Errorf("invalid period: %v", period)
}
if average <= 0 {
return fmt.Errorf("invalid average: %v", average)
}
if burst <= 0 {
return fmt.Errorf("invalid burst: %v", burst)
}
rs.m[period] = &rate{peri... | [
"func",
"(",
"rs",
"*",
"RateSet",
")",
"Add",
"(",
"period",
"time",
".",
"Duration",
",",
"average",
"int64",
",",
"burst",
"int64",
")",
"error",
"{",
"if",
"period",
"<=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"period"... | // Add adds a rate to the set. If there is a rate with the same period in the
// set then the new rate overrides the old one. | [
"Add",
"adds",
"a",
"rate",
"to",
"the",
"set",
".",
"If",
"there",
"is",
"a",
"rate",
"with",
"the",
"same",
"period",
"in",
"the",
"set",
"then",
"the",
"new",
"rate",
"overrides",
"the",
"old",
"one",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/tokenlimiter.go#L33-L45 |
27,357 | vulcand/oxy | ratelimit/tokenlimiter.go | New | func New(next http.Handler, extract utils.SourceExtractor, defaultRates *RateSet, opts ...TokenLimiterOption) (*TokenLimiter, error) {
if defaultRates == nil || len(defaultRates.m) == 0 {
return nil, fmt.Errorf("provide default rates")
}
if extract == nil {
return nil, fmt.Errorf("provide extract function")
}
... | go | func New(next http.Handler, extract utils.SourceExtractor, defaultRates *RateSet, opts ...TokenLimiterOption) (*TokenLimiter, error) {
if defaultRates == nil || len(defaultRates.m) == 0 {
return nil, fmt.Errorf("provide default rates")
}
if extract == nil {
return nil, fmt.Errorf("provide extract function")
}
... | [
"func",
"New",
"(",
"next",
"http",
".",
"Handler",
",",
"extract",
"utils",
".",
"SourceExtractor",
",",
"defaultRates",
"*",
"RateSet",
",",
"opts",
"...",
"TokenLimiterOption",
")",
"(",
"*",
"TokenLimiter",
",",
"error",
")",
"{",
"if",
"defaultRates",
... | // New constructs a `TokenLimiter` middleware instance. | [
"New",
"constructs",
"a",
"TokenLimiter",
"middleware",
"instance",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/tokenlimiter.go#L80-L107 |
27,358 | vulcand/oxy | ratelimit/tokenlimiter.go | ExtractRates | func ExtractRates(e RateExtractor) TokenLimiterOption {
return func(cl *TokenLimiter) error {
cl.extractRates = e
return nil
}
} | go | func ExtractRates(e RateExtractor) TokenLimiterOption {
return func(cl *TokenLimiter) error {
cl.extractRates = e
return nil
}
} | [
"func",
"ExtractRates",
"(",
"e",
"RateExtractor",
")",
"TokenLimiterOption",
"{",
"return",
"func",
"(",
"cl",
"*",
"TokenLimiter",
")",
"error",
"{",
"cl",
".",
"extractRates",
"=",
"e",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // ExtractRates sets the rate extractor | [
"ExtractRates",
"sets",
"the",
"rate",
"extractor"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/tokenlimiter.go#L224-L229 |
27,359 | vulcand/oxy | ratelimit/tokenlimiter.go | Clock | func Clock(clock timetools.TimeProvider) TokenLimiterOption {
return func(cl *TokenLimiter) error {
cl.clock = clock
return nil
}
} | go | func Clock(clock timetools.TimeProvider) TokenLimiterOption {
return func(cl *TokenLimiter) error {
cl.clock = clock
return nil
}
} | [
"func",
"Clock",
"(",
"clock",
"timetools",
".",
"TimeProvider",
")",
"TokenLimiterOption",
"{",
"return",
"func",
"(",
"cl",
"*",
"TokenLimiter",
")",
"error",
"{",
"cl",
".",
"clock",
"=",
"clock",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Clock sets the clock | [
"Clock",
"sets",
"the",
"clock"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/tokenlimiter.go#L232-L237 |
27,360 | vulcand/oxy | ratelimit/tokenlimiter.go | Capacity | func Capacity(cap int) TokenLimiterOption {
return func(cl *TokenLimiter) error {
if cap <= 0 {
return fmt.Errorf("bad capacity: %v", cap)
}
cl.capacity = cap
return nil
}
} | go | func Capacity(cap int) TokenLimiterOption {
return func(cl *TokenLimiter) error {
if cap <= 0 {
return fmt.Errorf("bad capacity: %v", cap)
}
cl.capacity = cap
return nil
}
} | [
"func",
"Capacity",
"(",
"cap",
"int",
")",
"TokenLimiterOption",
"{",
"return",
"func",
"(",
"cl",
"*",
"TokenLimiter",
")",
"error",
"{",
"if",
"cap",
"<=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cap",
")",
"\n",
"}",
"\... | // Capacity sets the capacity | [
"Capacity",
"sets",
"the",
"capacity"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/tokenlimiter.go#L240-L248 |
27,361 | vulcand/oxy | buffer/buffer.go | MaxRequestBodyBytes | func MaxRequestBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
return fmt.Errorf("max bytes should be >= 0 got %d", m)
}
b.maxRequestBodyBytes = m
return nil
}
} | go | func MaxRequestBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
return fmt.Errorf("max bytes should be >= 0 got %d", m)
}
b.maxRequestBodyBytes = m
return nil
}
} | [
"func",
"MaxRequestBodyBytes",
"(",
"m",
"int64",
")",
"optSetter",
"{",
"return",
"func",
"(",
"b",
"*",
"Buffer",
")",
"error",
"{",
"if",
"m",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
")",
"\n",
"}",
"\n",
"b",... | // MaxRequestBodyBytes sets the maximum request body size in bytes | [
"MaxRequestBodyBytes",
"sets",
"the",
"maximum",
"request",
"body",
"size",
"in",
"bytes"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/buffer/buffer.go#L160-L168 |
27,362 | vulcand/oxy | buffer/buffer.go | MemRequestBodyBytes | func MemRequestBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
return fmt.Errorf("mem bytes should be >= 0 got %d", m)
}
b.memRequestBodyBytes = m
return nil
}
} | go | func MemRequestBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
return fmt.Errorf("mem bytes should be >= 0 got %d", m)
}
b.memRequestBodyBytes = m
return nil
}
} | [
"func",
"MemRequestBodyBytes",
"(",
"m",
"int64",
")",
"optSetter",
"{",
"return",
"func",
"(",
"b",
"*",
"Buffer",
")",
"error",
"{",
"if",
"m",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
")",
"\n",
"}",
"\n",
"b",... | // MemRequestBodyBytes bytes sets the maximum request body to be stored in memory
// buffer middleware will serialize the excess to disk. | [
"MemRequestBodyBytes",
"bytes",
"sets",
"the",
"maximum",
"request",
"body",
"to",
"be",
"stored",
"in",
"memory",
"buffer",
"middleware",
"will",
"serialize",
"the",
"excess",
"to",
"disk",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/buffer/buffer.go#L172-L180 |
27,363 | vulcand/oxy | buffer/buffer.go | MaxResponseBodyBytes | func MaxResponseBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
return fmt.Errorf("max bytes should be >= 0 got %d", m)
}
b.maxResponseBodyBytes = m
return nil
}
} | go | func MaxResponseBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
return fmt.Errorf("max bytes should be >= 0 got %d", m)
}
b.maxResponseBodyBytes = m
return nil
}
} | [
"func",
"MaxResponseBodyBytes",
"(",
"m",
"int64",
")",
"optSetter",
"{",
"return",
"func",
"(",
"b",
"*",
"Buffer",
")",
"error",
"{",
"if",
"m",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
")",
"\n",
"}",
"\n",
"b"... | // MaxResponseBodyBytes sets the maximum request body size in bytes | [
"MaxResponseBodyBytes",
"sets",
"the",
"maximum",
"request",
"body",
"size",
"in",
"bytes"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/buffer/buffer.go#L183-L191 |
27,364 | vulcand/oxy | buffer/buffer.go | MemResponseBodyBytes | func MemResponseBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
return fmt.Errorf("mem bytes should be >= 0 got %d", m)
}
b.memResponseBodyBytes = m
return nil
}
} | go | func MemResponseBodyBytes(m int64) optSetter {
return func(b *Buffer) error {
if m < 0 {
return fmt.Errorf("mem bytes should be >= 0 got %d", m)
}
b.memResponseBodyBytes = m
return nil
}
} | [
"func",
"MemResponseBodyBytes",
"(",
"m",
"int64",
")",
"optSetter",
"{",
"return",
"func",
"(",
"b",
"*",
"Buffer",
")",
"error",
"{",
"if",
"m",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
")",
"\n",
"}",
"\n",
"b"... | // MemResponseBodyBytes sets the maximum request body to be stored in memory
// buffer middleware will serialize the excess to disk. | [
"MemResponseBodyBytes",
"sets",
"the",
"maximum",
"request",
"body",
"to",
"be",
"stored",
"in",
"memory",
"buffer",
"middleware",
"will",
"serialize",
"the",
"excess",
"to",
"disk",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/buffer/buffer.go#L195-L203 |
27,365 | vulcand/oxy | buffer/buffer.go | Wrap | func (b *Buffer) Wrap(next http.Handler) error {
b.next = next
return nil
} | go | func (b *Buffer) Wrap(next http.Handler) error {
b.next = next
return nil
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"Wrap",
"(",
"next",
"http",
".",
"Handler",
")",
"error",
"{",
"b",
".",
"next",
"=",
"next",
"\n",
"return",
"nil",
"\n",
"}"
] | // Wrap sets the next handler to be called by buffer handler. | [
"Wrap",
"sets",
"the",
"next",
"handler",
"to",
"be",
"called",
"by",
"buffer",
"handler",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/buffer/buffer.go#L206-L209 |
27,366 | vulcand/oxy | buffer/buffer.go | CloseNotify | func (b *bufferWriter) CloseNotify() <-chan bool {
if cn, ok := b.responseWriter.(http.CloseNotifier); ok {
return cn.CloseNotify()
}
b.log.Warningf("Upstream ResponseWriter of type %v does not implement http.CloseNotifier. Returning dummy channel.", reflect.TypeOf(b.responseWriter))
return make(<-chan bool)
} | go | func (b *bufferWriter) CloseNotify() <-chan bool {
if cn, ok := b.responseWriter.(http.CloseNotifier); ok {
return cn.CloseNotify()
}
b.log.Warningf("Upstream ResponseWriter of type %v does not implement http.CloseNotifier. Returning dummy channel.", reflect.TypeOf(b.responseWriter))
return make(<-chan bool)
} | [
"func",
"(",
"b",
"*",
"bufferWriter",
")",
"CloseNotify",
"(",
")",
"<-",
"chan",
"bool",
"{",
"if",
"cn",
",",
"ok",
":=",
"b",
".",
"responseWriter",
".",
"(",
"http",
".",
"CloseNotifier",
")",
";",
"ok",
"{",
"return",
"cn",
".",
"CloseNotify",
... | // CloseNotifier interface - this allows downstream connections to be terminated when the client terminates. | [
"CloseNotifier",
"interface",
"-",
"this",
"allows",
"downstream",
"connections",
"to",
"be",
"terminated",
"when",
"the",
"client",
"terminates",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/buffer/buffer.go#L402-L408 |
27,367 | vulcand/oxy | buffer/buffer.go | Hijack | func (b *bufferWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if hi, ok := b.responseWriter.(http.Hijacker); ok {
conn, rw, err := hi.Hijack()
if err != nil {
b.hijacked = true
}
return conn, rw, err
}
b.log.Warningf("Upstream ResponseWriter of type %v does not implement http.Hijacker. Returning ... | go | func (b *bufferWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if hi, ok := b.responseWriter.(http.Hijacker); ok {
conn, rw, err := hi.Hijack()
if err != nil {
b.hijacked = true
}
return conn, rw, err
}
b.log.Warningf("Upstream ResponseWriter of type %v does not implement http.Hijacker. Returning ... | [
"func",
"(",
"b",
"*",
"bufferWriter",
")",
"Hijack",
"(",
")",
"(",
"net",
".",
"Conn",
",",
"*",
"bufio",
".",
"ReadWriter",
",",
"error",
")",
"{",
"if",
"hi",
",",
"ok",
":=",
"b",
".",
"responseWriter",
".",
"(",
"http",
".",
"Hijacker",
")"... | // Hijack This allows connections to be hijacked for websockets for instance. | [
"Hijack",
"This",
"allows",
"connections",
"to",
"be",
"hijacked",
"for",
"websockets",
"for",
"instance",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/buffer/buffer.go#L411-L421 |
27,368 | vulcand/oxy | memmetrics/roundtrip.go | RTCounter | func RTCounter(new NewCounterFn) rrOptSetter {
return func(r *RTMetrics) error {
r.newCounter = new
return nil
}
} | go | func RTCounter(new NewCounterFn) rrOptSetter {
return func(r *RTMetrics) error {
r.newCounter = new
return nil
}
} | [
"func",
"RTCounter",
"(",
"new",
"NewCounterFn",
")",
"rrOptSetter",
"{",
"return",
"func",
"(",
"r",
"*",
"RTMetrics",
")",
"error",
"{",
"r",
".",
"newCounter",
"=",
"new",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RTCounter set a builder function for Counter | [
"RTCounter",
"set",
"a",
"builder",
"function",
"for",
"Counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L42-L47 |
27,369 | vulcand/oxy | memmetrics/roundtrip.go | RTHistogram | func RTHistogram(fn NewRollingHistogramFn) rrOptSetter {
return func(r *RTMetrics) error {
r.newHist = fn
return nil
}
} | go | func RTHistogram(fn NewRollingHistogramFn) rrOptSetter {
return func(r *RTMetrics) error {
r.newHist = fn
return nil
}
} | [
"func",
"RTHistogram",
"(",
"fn",
"NewRollingHistogramFn",
")",
"rrOptSetter",
"{",
"return",
"func",
"(",
"r",
"*",
"RTMetrics",
")",
"error",
"{",
"r",
".",
"newHist",
"=",
"fn",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RTHistogram set a builder function for RollingHistogram | [
"RTHistogram",
"set",
"a",
"builder",
"function",
"for",
"RollingHistogram"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L50-L55 |
27,370 | vulcand/oxy | memmetrics/roundtrip.go | RTClock | func RTClock(clock timetools.TimeProvider) rrOptSetter {
return func(r *RTMetrics) error {
r.clock = clock
return nil
}
} | go | func RTClock(clock timetools.TimeProvider) rrOptSetter {
return func(r *RTMetrics) error {
r.clock = clock
return nil
}
} | [
"func",
"RTClock",
"(",
"clock",
"timetools",
".",
"TimeProvider",
")",
"rrOptSetter",
"{",
"return",
"func",
"(",
"r",
"*",
"RTMetrics",
")",
"error",
"{",
"r",
".",
"clock",
"=",
"clock",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RTClock sets a clock | [
"RTClock",
"sets",
"a",
"clock"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L58-L63 |
27,371 | vulcand/oxy | memmetrics/roundtrip.go | NewRTMetrics | func NewRTMetrics(settings ...rrOptSetter) (*RTMetrics, error) {
m := &RTMetrics{
statusCodes: make(map[int]*RollingCounter),
statusCodesLock: sync.RWMutex{},
}
for _, s := range settings {
if err := s(m); err != nil {
return nil, err
}
}
if m.clock == nil {
m.clock = &timetools.RealTime{}
}
i... | go | func NewRTMetrics(settings ...rrOptSetter) (*RTMetrics, error) {
m := &RTMetrics{
statusCodes: make(map[int]*RollingCounter),
statusCodesLock: sync.RWMutex{},
}
for _, s := range settings {
if err := s(m); err != nil {
return nil, err
}
}
if m.clock == nil {
m.clock = &timetools.RealTime{}
}
i... | [
"func",
"NewRTMetrics",
"(",
"settings",
"...",
"rrOptSetter",
")",
"(",
"*",
"RTMetrics",
",",
"error",
")",
"{",
"m",
":=",
"&",
"RTMetrics",
"{",
"statusCodes",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"RollingCounter",
")",
",",
"statusCodesLoc... | // NewRTMetrics returns new instance of metrics collector. | [
"NewRTMetrics",
"returns",
"new",
"instance",
"of",
"metrics",
"collector",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L66-L112 |
27,372 | vulcand/oxy | memmetrics/roundtrip.go | Export | func (m *RTMetrics) Export() *RTMetrics {
m.statusCodesLock.RLock()
defer m.statusCodesLock.RUnlock()
m.histogramLock.RLock()
defer m.histogramLock.RUnlock()
export := &RTMetrics{}
export.statusCodesLock = sync.RWMutex{}
export.histogramLock = sync.RWMutex{}
export.total = m.total.Clone()
export.netErrors = m... | go | func (m *RTMetrics) Export() *RTMetrics {
m.statusCodesLock.RLock()
defer m.statusCodesLock.RUnlock()
m.histogramLock.RLock()
defer m.histogramLock.RUnlock()
export := &RTMetrics{}
export.statusCodesLock = sync.RWMutex{}
export.histogramLock = sync.RWMutex{}
export.total = m.total.Clone()
export.netErrors = m... | [
"func",
"(",
"m",
"*",
"RTMetrics",
")",
"Export",
"(",
")",
"*",
"RTMetrics",
"{",
"m",
".",
"statusCodesLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"statusCodesLock",
".",
"RUnlock",
"(",
")",
"\n",
"m",
".",
"histogramLock",
".",
"RLoc... | // Export Returns a new RTMetrics which is a copy of the current one | [
"Export",
"Returns",
"a",
"new",
"RTMetrics",
"which",
"is",
"a",
"copy",
"of",
"the",
"current",
"one"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L115-L139 |
27,373 | vulcand/oxy | memmetrics/roundtrip.go | NetworkErrorRatio | func (m *RTMetrics) NetworkErrorRatio() float64 {
if m.total.Count() == 0 {
return 0
}
return float64(m.netErrors.Count()) / float64(m.total.Count())
} | go | func (m *RTMetrics) NetworkErrorRatio() float64 {
if m.total.Count() == 0 {
return 0
}
return float64(m.netErrors.Count()) / float64(m.total.Count())
} | [
"func",
"(",
"m",
"*",
"RTMetrics",
")",
"NetworkErrorRatio",
"(",
")",
"float64",
"{",
"if",
"m",
".",
"total",
".",
"Count",
"(",
")",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"float64",
"(",
"m",
".",
"netErrors",
".",
"Count",
... | // NetworkErrorRatio calculates the amont of network errors such as time outs and dropped connection
// that occurred in the given time window compared to the total requests count. | [
"NetworkErrorRatio",
"calculates",
"the",
"amont",
"of",
"network",
"errors",
"such",
"as",
"time",
"outs",
"and",
"dropped",
"connection",
"that",
"occurred",
"in",
"the",
"given",
"time",
"window",
"compared",
"to",
"the",
"total",
"requests",
"count",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L148-L153 |
27,374 | vulcand/oxy | memmetrics/roundtrip.go | Append | func (m *RTMetrics) Append(other *RTMetrics) error {
if m == other {
return errors.New("RTMetrics cannot append to self")
}
if err := m.total.Append(other.total); err != nil {
return err
}
if err := m.netErrors.Append(other.netErrors); err != nil {
return err
}
copied := other.Export()
m.statusCodesLo... | go | func (m *RTMetrics) Append(other *RTMetrics) error {
if m == other {
return errors.New("RTMetrics cannot append to self")
}
if err := m.total.Append(other.total); err != nil {
return err
}
if err := m.netErrors.Append(other.netErrors); err != nil {
return err
}
copied := other.Export()
m.statusCodesLo... | [
"func",
"(",
"m",
"*",
"RTMetrics",
")",
"Append",
"(",
"other",
"*",
"RTMetrics",
")",
"error",
"{",
"if",
"m",
"==",
"other",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"total",
... | // Append append a metric | [
"Append",
"append",
"a",
"metric"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L176-L207 |
27,375 | vulcand/oxy | memmetrics/roundtrip.go | Record | func (m *RTMetrics) Record(code int, duration time.Duration) {
m.total.Inc(1)
if code == http.StatusGatewayTimeout || code == http.StatusBadGateway {
m.netErrors.Inc(1)
}
m.recordStatusCode(code)
m.recordLatency(duration)
} | go | func (m *RTMetrics) Record(code int, duration time.Duration) {
m.total.Inc(1)
if code == http.StatusGatewayTimeout || code == http.StatusBadGateway {
m.netErrors.Inc(1)
}
m.recordStatusCode(code)
m.recordLatency(duration)
} | [
"func",
"(",
"m",
"*",
"RTMetrics",
")",
"Record",
"(",
"code",
"int",
",",
"duration",
"time",
".",
"Duration",
")",
"{",
"m",
".",
"total",
".",
"Inc",
"(",
"1",
")",
"\n",
"if",
"code",
"==",
"http",
".",
"StatusGatewayTimeout",
"||",
"code",
"=... | // Record records a metric | [
"Record",
"records",
"a",
"metric"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L210-L217 |
27,376 | vulcand/oxy | memmetrics/roundtrip.go | StatusCodesCounts | func (m *RTMetrics) StatusCodesCounts() map[int]int64 {
sc := make(map[int]int64)
m.statusCodesLock.RLock()
defer m.statusCodesLock.RUnlock()
for k, v := range m.statusCodes {
if v.Count() != 0 {
sc[k] = v.Count()
}
}
return sc
} | go | func (m *RTMetrics) StatusCodesCounts() map[int]int64 {
sc := make(map[int]int64)
m.statusCodesLock.RLock()
defer m.statusCodesLock.RUnlock()
for k, v := range m.statusCodes {
if v.Count() != 0 {
sc[k] = v.Count()
}
}
return sc
} | [
"func",
"(",
"m",
"*",
"RTMetrics",
")",
"StatusCodesCounts",
"(",
")",
"map",
"[",
"int",
"]",
"int64",
"{",
"sc",
":=",
"make",
"(",
"map",
"[",
"int",
"]",
"int64",
")",
"\n",
"m",
".",
"statusCodesLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
... | // StatusCodesCounts returns map with counts of the response codes | [
"StatusCodesCounts",
"returns",
"map",
"with",
"counts",
"of",
"the",
"response",
"codes"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L230-L240 |
27,377 | vulcand/oxy | memmetrics/roundtrip.go | LatencyHistogram | func (m *RTMetrics) LatencyHistogram() (*HDRHistogram, error) {
m.histogramLock.Lock()
defer m.histogramLock.Unlock()
return m.histogram.Merged()
} | go | func (m *RTMetrics) LatencyHistogram() (*HDRHistogram, error) {
m.histogramLock.Lock()
defer m.histogramLock.Unlock()
return m.histogram.Merged()
} | [
"func",
"(",
"m",
"*",
"RTMetrics",
")",
"LatencyHistogram",
"(",
")",
"(",
"*",
"HDRHistogram",
",",
"error",
")",
"{",
"m",
".",
"histogramLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"histogramLock",
".",
"Unlock",
"(",
")",
"\n",
"retur... | // LatencyHistogram computes and returns resulting histogram with latencies observed. | [
"LatencyHistogram",
"computes",
"and",
"returns",
"resulting",
"histogram",
"with",
"latencies",
"observed",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L243-L247 |
27,378 | vulcand/oxy | memmetrics/roundtrip.go | Reset | func (m *RTMetrics) Reset() {
m.statusCodesLock.Lock()
defer m.statusCodesLock.Unlock()
m.histogramLock.Lock()
defer m.histogramLock.Unlock()
m.histogram.Reset()
m.total.Reset()
m.netErrors.Reset()
m.statusCodes = make(map[int]*RollingCounter)
} | go | func (m *RTMetrics) Reset() {
m.statusCodesLock.Lock()
defer m.statusCodesLock.Unlock()
m.histogramLock.Lock()
defer m.histogramLock.Unlock()
m.histogram.Reset()
m.total.Reset()
m.netErrors.Reset()
m.statusCodes = make(map[int]*RollingCounter)
} | [
"func",
"(",
"m",
"*",
"RTMetrics",
")",
"Reset",
"(",
")",
"{",
"m",
".",
"statusCodesLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"statusCodesLock",
".",
"Unlock",
"(",
")",
"\n",
"m",
".",
"histogramLock",
".",
"Lock",
"(",
")",
"\n",
... | // Reset reset metrics | [
"Reset",
"reset",
"metrics"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/roundtrip.go#L250-L259 |
27,379 | vulcand/oxy | utils/netutils.go | NewProxyWriterWithLogger | func NewProxyWriterWithLogger(w http.ResponseWriter, l *log.Logger) *ProxyWriter {
return &ProxyWriter{
w: w,
log: l,
}
} | go | func NewProxyWriterWithLogger(w http.ResponseWriter, l *log.Logger) *ProxyWriter {
return &ProxyWriter{
w: w,
log: l,
}
} | [
"func",
"NewProxyWriterWithLogger",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"l",
"*",
"log",
".",
"Logger",
")",
"*",
"ProxyWriter",
"{",
"return",
"&",
"ProxyWriter",
"{",
"w",
":",
"w",
",",
"log",
":",
"l",
",",
"}",
"\n",
"}"
] | // NewProxyWriterWithLogger creates a new ProxyWriter | [
"NewProxyWriterWithLogger",
"creates",
"a",
"new",
"ProxyWriter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L30-L35 |
27,380 | vulcand/oxy | utils/netutils.go | StatusCode | func (p *ProxyWriter) StatusCode() int {
if p.code == 0 {
// per contract standard lib will set this to http.StatusOK if not set
// by user, here we avoid the confusion by mirroring this logic
return http.StatusOK
}
return p.code
} | go | func (p *ProxyWriter) StatusCode() int {
if p.code == 0 {
// per contract standard lib will set this to http.StatusOK if not set
// by user, here we avoid the confusion by mirroring this logic
return http.StatusOK
}
return p.code
} | [
"func",
"(",
"p",
"*",
"ProxyWriter",
")",
"StatusCode",
"(",
")",
"int",
"{",
"if",
"p",
".",
"code",
"==",
"0",
"{",
"// per contract standard lib will set this to http.StatusOK if not set",
"// by user, here we avoid the confusion by mirroring this logic",
"return",
"htt... | // StatusCode gets status code | [
"StatusCode",
"gets",
"status",
"code"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L38-L45 |
27,381 | vulcand/oxy | utils/netutils.go | WriteHeader | func (p *ProxyWriter) WriteHeader(code int) {
p.code = code
p.w.WriteHeader(code)
} | go | func (p *ProxyWriter) WriteHeader(code int) {
p.code = code
p.w.WriteHeader(code)
} | [
"func",
"(",
"p",
"*",
"ProxyWriter",
")",
"WriteHeader",
"(",
"code",
"int",
")",
"{",
"p",
".",
"code",
"=",
"code",
"\n",
"p",
".",
"w",
".",
"WriteHeader",
"(",
"code",
")",
"\n",
"}"
] | // WriteHeader writes status code | [
"WriteHeader",
"writes",
"status",
"code"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L63-L66 |
27,382 | vulcand/oxy | utils/netutils.go | Flush | func (p *ProxyWriter) Flush() {
if f, ok := p.w.(http.Flusher); ok {
f.Flush()
}
} | go | func (p *ProxyWriter) Flush() {
if f, ok := p.w.(http.Flusher); ok {
f.Flush()
}
} | [
"func",
"(",
"p",
"*",
"ProxyWriter",
")",
"Flush",
"(",
")",
"{",
"if",
"f",
",",
"ok",
":=",
"p",
".",
"w",
".",
"(",
"http",
".",
"Flusher",
")",
";",
"ok",
"{",
"f",
".",
"Flush",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Flush flush the writer | [
"Flush",
"flush",
"the",
"writer"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L69-L73 |
27,383 | vulcand/oxy | utils/netutils.go | NewBufferWriter | func NewBufferWriter(w io.WriteCloser) *BufferWriter {
return &BufferWriter{
W: w,
H: make(http.Header),
}
} | go | func NewBufferWriter(w io.WriteCloser) *BufferWriter {
return &BufferWriter{
W: w,
H: make(http.Header),
}
} | [
"func",
"NewBufferWriter",
"(",
"w",
"io",
".",
"WriteCloser",
")",
"*",
"BufferWriter",
"{",
"return",
"&",
"BufferWriter",
"{",
"W",
":",
"w",
",",
"H",
":",
"make",
"(",
"http",
".",
"Header",
")",
",",
"}",
"\n",
"}"
] | // NewBufferWriter creates a new BufferWriter | [
"NewBufferWriter",
"creates",
"a",
"new",
"BufferWriter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L95-L100 |
27,384 | vulcand/oxy | utils/netutils.go | CopyURL | func CopyURL(i *url.URL) *url.URL {
out := *i
if i.User != nil {
out.User = &(*i.User)
}
return &out
} | go | func CopyURL(i *url.URL) *url.URL {
out := *i
if i.User != nil {
out.User = &(*i.User)
}
return &out
} | [
"func",
"CopyURL",
"(",
"i",
"*",
"url",
".",
"URL",
")",
"*",
"url",
".",
"URL",
"{",
"out",
":=",
"*",
"i",
"\n",
"if",
"i",
".",
"User",
"!=",
"nil",
"{",
"out",
".",
"User",
"=",
"&",
"(",
"*",
"i",
".",
"User",
")",
"\n",
"}",
"\n",
... | // CopyURL provides update safe copy by avoiding shallow copying User field | [
"CopyURL",
"provides",
"update",
"safe",
"copy",
"by",
"avoiding",
"shallow",
"copying",
"User",
"field"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L160-L166 |
27,385 | vulcand/oxy | utils/netutils.go | CopyHeaders | func CopyHeaders(dst http.Header, src http.Header) {
for k, vv := range src {
dst[k] = append(dst[k], vv...)
}
} | go | func CopyHeaders(dst http.Header, src http.Header) {
for k, vv := range src {
dst[k] = append(dst[k], vv...)
}
} | [
"func",
"CopyHeaders",
"(",
"dst",
"http",
".",
"Header",
",",
"src",
"http",
".",
"Header",
")",
"{",
"for",
"k",
",",
"vv",
":=",
"range",
"src",
"{",
"dst",
"[",
"k",
"]",
"=",
"append",
"(",
"dst",
"[",
"k",
"]",
",",
"vv",
"...",
")",
"\... | // CopyHeaders copies http headers from source to destination, it
// does not overide, but adds multiple headers | [
"CopyHeaders",
"copies",
"http",
"headers",
"from",
"source",
"to",
"destination",
"it",
"does",
"not",
"overide",
"but",
"adds",
"multiple",
"headers"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L170-L174 |
27,386 | vulcand/oxy | utils/netutils.go | HasHeaders | func HasHeaders(names []string, headers http.Header) bool {
for _, h := range names {
if headers.Get(h) != "" {
return true
}
}
return false
} | go | func HasHeaders(names []string, headers http.Header) bool {
for _, h := range names {
if headers.Get(h) != "" {
return true
}
}
return false
} | [
"func",
"HasHeaders",
"(",
"names",
"[",
"]",
"string",
",",
"headers",
"http",
".",
"Header",
")",
"bool",
"{",
"for",
"_",
",",
"h",
":=",
"range",
"names",
"{",
"if",
"headers",
".",
"Get",
"(",
"h",
")",
"!=",
"\"",
"\"",
"{",
"return",
"true... | // HasHeaders determines whether any of the header names is present in the http headers | [
"HasHeaders",
"determines",
"whether",
"any",
"of",
"the",
"header",
"names",
"is",
"present",
"in",
"the",
"http",
"headers"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L177-L184 |
27,387 | vulcand/oxy | cbreaker/effect.go | NewWebhookSideEffectsWithLogger | func NewWebhookSideEffectsWithLogger(w Webhook, l *log.Logger) (*WebhookSideEffect, error) {
if w.Method == "" {
return nil, fmt.Errorf("Supply method")
}
_, err := url.Parse(w.URL)
if err != nil {
return nil, err
}
return &WebhookSideEffect{w: w, log: l}, nil
} | go | func NewWebhookSideEffectsWithLogger(w Webhook, l *log.Logger) (*WebhookSideEffect, error) {
if w.Method == "" {
return nil, fmt.Errorf("Supply method")
}
_, err := url.Parse(w.URL)
if err != nil {
return nil, err
}
return &WebhookSideEffect{w: w, log: l}, nil
} | [
"func",
"NewWebhookSideEffectsWithLogger",
"(",
"w",
"Webhook",
",",
"l",
"*",
"log",
".",
"Logger",
")",
"(",
"*",
"WebhookSideEffect",
",",
"error",
")",
"{",
"if",
"w",
".",
"Method",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf"... | // NewWebhookSideEffectsWithLogger creates a new WebhookSideEffect | [
"NewWebhookSideEffectsWithLogger",
"creates",
"a",
"new",
"WebhookSideEffect"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/effect.go#L38-L48 |
27,388 | vulcand/oxy | cbreaker/effect.go | Exec | func (w *WebhookSideEffect) Exec() error {
r, err := http.NewRequest(w.w.Method, w.w.URL, w.getBody())
if err != nil {
return err
}
if len(w.w.Headers) != 0 {
utils.CopyHeaders(r.Header, w.w.Headers)
}
if len(w.w.Form) != 0 {
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
re, err := h... | go | func (w *WebhookSideEffect) Exec() error {
r, err := http.NewRequest(w.w.Method, w.w.URL, w.getBody())
if err != nil {
return err
}
if len(w.w.Headers) != 0 {
utils.CopyHeaders(r.Header, w.w.Headers)
}
if len(w.w.Form) != 0 {
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
re, err := h... | [
"func",
"(",
"w",
"*",
"WebhookSideEffect",
")",
"Exec",
"(",
")",
"error",
"{",
"r",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"w",
".",
"w",
".",
"Method",
",",
"w",
".",
"w",
".",
"URL",
",",
"w",
".",
"getBody",
"(",
")",
")",
"\n... | // Exec execute the side effect | [
"Exec",
"execute",
"the",
"side",
"effect"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/effect.go#L66-L90 |
27,389 | vulcand/oxy | memmetrics/counter.go | CounterClock | func CounterClock(c timetools.TimeProvider) rcOptSetter {
return func(r *RollingCounter) error {
r.clock = c
return nil
}
} | go | func CounterClock(c timetools.TimeProvider) rcOptSetter {
return func(r *RollingCounter) error {
r.clock = c
return nil
}
} | [
"func",
"CounterClock",
"(",
"c",
"timetools",
".",
"TimeProvider",
")",
"rcOptSetter",
"{",
"return",
"func",
"(",
"r",
"*",
"RollingCounter",
")",
"error",
"{",
"r",
".",
"clock",
"=",
"c",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // CounterClock defines a counter clock | [
"CounterClock",
"defines",
"a",
"counter",
"clock"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L13-L18 |
27,390 | vulcand/oxy | memmetrics/counter.go | NewCounter | func NewCounter(buckets int, resolution time.Duration, options ...rcOptSetter) (*RollingCounter, error) {
if buckets <= 0 {
return nil, fmt.Errorf("Buckets should be >= 0")
}
if resolution < time.Second {
return nil, fmt.Errorf("Resolution should be larger than a second")
}
rc := &RollingCounter{
lastBucket... | go | func NewCounter(buckets int, resolution time.Duration, options ...rcOptSetter) (*RollingCounter, error) {
if buckets <= 0 {
return nil, fmt.Errorf("Buckets should be >= 0")
}
if resolution < time.Second {
return nil, fmt.Errorf("Resolution should be larger than a second")
}
rc := &RollingCounter{
lastBucket... | [
"func",
"NewCounter",
"(",
"buckets",
"int",
",",
"resolution",
"time",
".",
"Duration",
",",
"options",
"...",
"rcOptSetter",
")",
"(",
"*",
"RollingCounter",
",",
"error",
")",
"{",
"if",
"buckets",
"<=",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"... | // NewCounter creates a counter with fixed amount of buckets that are rotated every resolution period.
// E.g. 10 buckets with 1 second means that every new second the bucket is refreshed, so it maintains 10 second rolling window.
// By default creates a bucket with 10 buckets and 1 second resolution | [
"NewCounter",
"creates",
"a",
"counter",
"with",
"fixed",
"amount",
"of",
"buckets",
"that",
"are",
"rotated",
"every",
"resolution",
"period",
".",
"E",
".",
"g",
".",
"10",
"buckets",
"with",
"1",
"second",
"means",
"that",
"every",
"new",
"second",
"the... | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L33-L59 |
27,391 | vulcand/oxy | memmetrics/counter.go | Append | func (c *RollingCounter) Append(o *RollingCounter) error {
c.Inc(int(o.Count()))
return nil
} | go | func (c *RollingCounter) Append(o *RollingCounter) error {
c.Inc(int(o.Count()))
return nil
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"Append",
"(",
"o",
"*",
"RollingCounter",
")",
"error",
"{",
"c",
".",
"Inc",
"(",
"int",
"(",
"o",
".",
"Count",
"(",
")",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Append append a counter | [
"Append",
"append",
"a",
"counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L62-L65 |
27,392 | vulcand/oxy | memmetrics/counter.go | Clone | func (c *RollingCounter) Clone() *RollingCounter {
c.cleanup()
other := &RollingCounter{
resolution: c.resolution,
values: make([]int, len(c.values)),
clock: c.clock,
lastBucket: c.lastBucket,
lastUpdated: c.lastUpdated,
}
copy(other.values, c.values)
return other
} | go | func (c *RollingCounter) Clone() *RollingCounter {
c.cleanup()
other := &RollingCounter{
resolution: c.resolution,
values: make([]int, len(c.values)),
clock: c.clock,
lastBucket: c.lastBucket,
lastUpdated: c.lastUpdated,
}
copy(other.values, c.values)
return other
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"Clone",
"(",
")",
"*",
"RollingCounter",
"{",
"c",
".",
"cleanup",
"(",
")",
"\n",
"other",
":=",
"&",
"RollingCounter",
"{",
"resolution",
":",
"c",
".",
"resolution",
",",
"values",
":",
"make",
"(",
"... | // Clone clone a counter | [
"Clone",
"clone",
"a",
"counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L68-L79 |
27,393 | vulcand/oxy | memmetrics/counter.go | Reset | func (c *RollingCounter) Reset() {
c.lastBucket = -1
c.countedBuckets = 0
c.lastUpdated = time.Time{}
for i := range c.values {
c.values[i] = 0
}
} | go | func (c *RollingCounter) Reset() {
c.lastBucket = -1
c.countedBuckets = 0
c.lastUpdated = time.Time{}
for i := range c.values {
c.values[i] = 0
}
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"Reset",
"(",
")",
"{",
"c",
".",
"lastBucket",
"=",
"-",
"1",
"\n",
"c",
".",
"countedBuckets",
"=",
"0",
"\n",
"c",
".",
"lastUpdated",
"=",
"time",
".",
"Time",
"{",
"}",
"\n",
"for",
"i",
":=",
... | // Reset reset a counter | [
"Reset",
"reset",
"a",
"counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L82-L89 |
27,394 | vulcand/oxy | memmetrics/counter.go | WindowSize | func (c *RollingCounter) WindowSize() time.Duration {
return time.Duration(len(c.values)) * c.resolution
} | go | func (c *RollingCounter) WindowSize() time.Duration {
return time.Duration(len(c.values)) * c.resolution
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"WindowSize",
"(",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Duration",
"(",
"len",
"(",
"c",
".",
"values",
")",
")",
"*",
"c",
".",
"resolution",
"\n",
"}"
] | // WindowSize gets windows size | [
"WindowSize",
"gets",
"windows",
"size"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L113-L115 |
27,395 | vulcand/oxy | memmetrics/counter.go | Inc | func (c *RollingCounter) Inc(v int) {
c.cleanup()
c.incBucketValue(v)
} | go | func (c *RollingCounter) Inc(v int) {
c.cleanup()
c.incBucketValue(v)
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"Inc",
"(",
"v",
"int",
")",
"{",
"c",
".",
"cleanup",
"(",
")",
"\n",
"c",
".",
"incBucketValue",
"(",
"v",
")",
"\n",
"}"
] | // Inc increment counter | [
"Inc",
"increment",
"counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L118-L121 |
27,396 | vulcand/oxy | memmetrics/counter.go | getBucket | func (c *RollingCounter) getBucket(t time.Time) int {
return int(t.Truncate(c.resolution).Unix() % int64(len(c.values)))
} | go | func (c *RollingCounter) getBucket(t time.Time) int {
return int(t.Truncate(c.resolution).Unix() % int64(len(c.values)))
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"getBucket",
"(",
"t",
"time",
".",
"Time",
")",
"int",
"{",
"return",
"int",
"(",
"t",
".",
"Truncate",
"(",
"c",
".",
"resolution",
")",
".",
"Unix",
"(",
")",
"%",
"int64",
"(",
"len",
"(",
"c",
... | // Returns the number in the moving window bucket that this slot occupies | [
"Returns",
"the",
"number",
"in",
"the",
"moving",
"window",
"bucket",
"that",
"this",
"slot",
"occupies"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L140-L142 |
27,397 | vulcand/oxy | memmetrics/counter.go | cleanup | func (c *RollingCounter) cleanup() {
now := c.clock.UtcNow()
for i := 0; i < len(c.values); i++ {
now = now.Add(time.Duration(-1*i) * c.resolution)
if now.Truncate(c.resolution).After(c.lastUpdated.Truncate(c.resolution)) {
c.values[c.getBucket(now)] = 0
} else {
break
}
}
} | go | func (c *RollingCounter) cleanup() {
now := c.clock.UtcNow()
for i := 0; i < len(c.values); i++ {
now = now.Add(time.Duration(-1*i) * c.resolution)
if now.Truncate(c.resolution).After(c.lastUpdated.Truncate(c.resolution)) {
c.values[c.getBucket(now)] = 0
} else {
break
}
}
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"cleanup",
"(",
")",
"{",
"now",
":=",
"c",
".",
"clock",
".",
"UtcNow",
"(",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"c",
".",
"values",
")",
";",
"i",
"++",
"{",
"now",
"=... | // Reset buckets that were not updated | [
"Reset",
"buckets",
"that",
"were",
"not",
"updated"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L145-L155 |
27,398 | rs/xid | id.go | readMachineID | func readMachineID() []byte {
id := make([]byte, 3)
hid, err := readPlatformMachineID()
if err != nil || len(hid) == 0 {
hid, err = os.Hostname()
}
if err == nil && len(hid) != 0 {
hw := md5.New()
hw.Write([]byte(hid))
copy(id, hw.Sum(nil))
} else {
// Fallback to rand number if machine id can't be gath... | go | func readMachineID() []byte {
id := make([]byte, 3)
hid, err := readPlatformMachineID()
if err != nil || len(hid) == 0 {
hid, err = os.Hostname()
}
if err == nil && len(hid) != 0 {
hw := md5.New()
hw.Write([]byte(hid))
copy(id, hw.Sum(nil))
} else {
// Fallback to rand number if machine id can't be gath... | [
"func",
"readMachineID",
"(",
")",
"[",
"]",
"byte",
"{",
"id",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"3",
")",
"\n",
"hid",
",",
"err",
":=",
"readPlatformMachineID",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"len",
"(",
"hid",
")",
... | // readMachineId generates machine id and puts it into the machineId global
// variable. If this function fails to get the hostname, it will cause
// a runtime error. | [
"readMachineId",
"generates",
"machine",
"id",
"and",
"puts",
"it",
"into",
"the",
"machineId",
"global",
"variable",
".",
"If",
"this",
"function",
"fails",
"to",
"get",
"the",
"hostname",
"it",
"will",
"cause",
"a",
"runtime",
"error",
"."
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L117-L134 |
27,399 | rs/xid | id.go | randInt | func randInt() uint32 {
b := make([]byte, 3)
if _, err := rand.Reader.Read(b); err != nil {
panic(fmt.Errorf("xid: cannot generate random number: %v;", err))
}
return uint32(b[0])<<16 | uint32(b[1])<<8 | uint32(b[2])
} | go | func randInt() uint32 {
b := make([]byte, 3)
if _, err := rand.Reader.Read(b); err != nil {
panic(fmt.Errorf("xid: cannot generate random number: %v;", err))
}
return uint32(b[0])<<16 | uint32(b[1])<<8 | uint32(b[2])
} | [
"func",
"randInt",
"(",
")",
"uint32",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"3",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"rand",
".",
"Reader",
".",
"Read",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".... | // randInt generates a random uint32 | [
"randInt",
"generates",
"a",
"random",
"uint32"
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L137-L143 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.