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 listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
149,300 | vulcand/oxy | cbreaker/fallback.go | NewResponseFallbackWithLogger | func NewResponseFallbackWithLogger(r Response, l *log.Logger) (*ResponseFallback, error) {
if r.StatusCode == 0 {
return nil, fmt.Errorf("response code should not be 0")
}
return &ResponseFallback{r: r, log: l}, nil
} | go | func NewResponseFallbackWithLogger(r Response, l *log.Logger) (*ResponseFallback, error) {
if r.StatusCode == 0 {
return nil, fmt.Errorf("response code should not be 0")
}
return &ResponseFallback{r: r, log: l}, nil
} | [
"func",
"NewResponseFallbackWithLogger",
"(",
"r",
"Response",
",",
"l",
"*",
"log",
".",
"Logger",
")",
"(",
"*",
"ResponseFallback",
",",
"error",
")",
"{",
"if",
"r",
".",
"StatusCode",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"("... | // NewResponseFallbackWithLogger creates a new ResponseFallback | [
"NewResponseFallbackWithLogger",
"creates",
"a",
"new",
"ResponseFallback"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/fallback.go#L28-L33 |
149,301 | vulcand/oxy | cbreaker/fallback.go | NewRedirectFallbackWithLogger | func NewRedirectFallbackWithLogger(r Redirect, l *log.Logger) (*RedirectFallback, error) {
u, err := url.ParseRequestURI(r.URL)
if err != nil {
return nil, err
}
return &RedirectFallback{r: r, u: u, log: l}, nil
} | go | func NewRedirectFallbackWithLogger(r Redirect, l *log.Logger) (*RedirectFallback, error) {
u, err := url.ParseRequestURI(r.URL)
if err != nil {
return nil, err
}
return &RedirectFallback{r: r, u: u, log: l}, nil
} | [
"func",
"NewRedirectFallbackWithLogger",
"(",
"r",
"Redirect",
",",
"l",
"*",
"log",
".",
"Logger",
")",
"(",
"*",
"RedirectFallback",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"ParseRequestURI",
"(",
"r",
".",
"URL",
")",
"\n",
"if",
... | // NewRedirectFallbackWithLogger creates a new RedirectFallback | [
"NewRedirectFallbackWithLogger",
"creates",
"a",
"new",
"RedirectFallback"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/fallback.go#L74-L80 |
149,302 | vulcand/oxy | ratelimit/bucket.go | newTokenBucket | func newTokenBucket(rate *rate, clock timetools.TimeProvider) *tokenBucket {
return &tokenBucket{
period: rate.period,
timePerToken: time.Duration(int64(rate.period) / rate.average),
burst: rate.burst,
clock: clock,
lastRefresh: clock.UtcNow(),
availableTokens: rate.burs... | go | func newTokenBucket(rate *rate, clock timetools.TimeProvider) *tokenBucket {
return &tokenBucket{
period: rate.period,
timePerToken: time.Duration(int64(rate.period) / rate.average),
burst: rate.burst,
clock: clock,
lastRefresh: clock.UtcNow(),
availableTokens: rate.burs... | [
"func",
"newTokenBucket",
"(",
"rate",
"*",
"rate",
",",
"clock",
"timetools",
".",
"TimeProvider",
")",
"*",
"tokenBucket",
"{",
"return",
"&",
"tokenBucket",
"{",
"period",
":",
"rate",
".",
"period",
",",
"timePerToken",
":",
"time",
".",
"Duration",
"(... | // newTokenBucket crates a `tokenBucket` instance for the specified `Rate`. | [
"newTokenBucket",
"crates",
"a",
"tokenBucket",
"instance",
"for",
"the",
"specified",
"Rate",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L46-L55 |
149,303 | vulcand/oxy | ratelimit/bucket.go | consume | func (tb *tokenBucket) consume(tokens int64) (time.Duration, error) {
tb.updateAvailableTokens()
tb.lastConsumed = 0
if tokens > tb.burst {
return UndefinedDelay, fmt.Errorf("requested tokens larger than max tokens")
}
if tb.availableTokens < tokens {
return tb.timeTillAvailable(tokens), nil
}
tb.availableTo... | go | func (tb *tokenBucket) consume(tokens int64) (time.Duration, error) {
tb.updateAvailableTokens()
tb.lastConsumed = 0
if tokens > tb.burst {
return UndefinedDelay, fmt.Errorf("requested tokens larger than max tokens")
}
if tb.availableTokens < tokens {
return tb.timeTillAvailable(tokens), nil
}
tb.availableTo... | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"consume",
"(",
"tokens",
"int64",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"tb",
".",
"updateAvailableTokens",
"(",
")",
"\n",
"tb",
".",
"lastConsumed",
"=",
"0",
"\n",
"if",
"tokens",
"... | // consume makes an attempt to consume the specified number of tokens from the
// bucket. If there are enough tokens available then `0, nil` is returned; if
// tokens to consume is larger than the burst size, then an error is returned
// and the delay is not defined; otherwise returned a none zero delay that tells
// h... | [
"consume",
"makes",
"an",
"attempt",
"to",
"consume",
"the",
"specified",
"number",
"of",
"tokens",
"from",
"the",
"bucket",
".",
"If",
"there",
"are",
"enough",
"tokens",
"available",
"then",
"0",
"nil",
"is",
"returned",
";",
"if",
"tokens",
"to",
"consu... | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L63-L75 |
149,304 | vulcand/oxy | ratelimit/bucket.go | update | func (tb *tokenBucket) update(rate *rate) error {
if rate.period != tb.period {
return fmt.Errorf("period mismatch: %v != %v", tb.period, rate.period)
}
tb.timePerToken = time.Duration(int64(tb.period) / rate.average)
tb.burst = rate.burst
if tb.availableTokens > rate.burst {
tb.availableTokens = rate.burst
}... | go | func (tb *tokenBucket) update(rate *rate) error {
if rate.period != tb.period {
return fmt.Errorf("period mismatch: %v != %v", tb.period, rate.period)
}
tb.timePerToken = time.Duration(int64(tb.period) / rate.average)
tb.burst = rate.burst
if tb.availableTokens > rate.burst {
tb.availableTokens = rate.burst
}... | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"update",
"(",
"rate",
"*",
"rate",
")",
"error",
"{",
"if",
"rate",
".",
"period",
"!=",
"tb",
".",
"period",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tb",
".",
"period",
",",
"rate"... | // update modifies `average` and `burst` fields of the token bucket according
// to the provided `Rate` | [
"update",
"modifies",
"average",
"and",
"burst",
"fields",
"of",
"the",
"token",
"bucket",
"according",
"to",
"the",
"provided",
"Rate"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L89-L99 |
149,305 | vulcand/oxy | ratelimit/bucket.go | timeTillAvailable | func (tb *tokenBucket) timeTillAvailable(tokens int64) time.Duration {
missingTokens := tokens - tb.availableTokens
return time.Duration(missingTokens) * tb.timePerToken
} | go | func (tb *tokenBucket) timeTillAvailable(tokens int64) time.Duration {
missingTokens := tokens - tb.availableTokens
return time.Duration(missingTokens) * tb.timePerToken
} | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"timeTillAvailable",
"(",
"tokens",
"int64",
")",
"time",
".",
"Duration",
"{",
"missingTokens",
":=",
"tokens",
"-",
"tb",
".",
"availableTokens",
"\n",
"return",
"time",
".",
"Duration",
"(",
"missingTokens",
")"... | // timeTillAvailable returns the number of nanoseconds that we need to
// wait until the specified number of tokens becomes available for consumption. | [
"timeTillAvailable",
"returns",
"the",
"number",
"of",
"nanoseconds",
"that",
"we",
"need",
"to",
"wait",
"until",
"the",
"specified",
"number",
"of",
"tokens",
"becomes",
"available",
"for",
"consumption",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L103-L106 |
149,306 | vulcand/oxy | ratelimit/bucket.go | updateAvailableTokens | func (tb *tokenBucket) updateAvailableTokens() {
now := tb.clock.UtcNow()
timePassed := now.Sub(tb.lastRefresh)
tokens := tb.availableTokens + int64(timePassed/tb.timePerToken)
// If we haven't added any tokens that means that not enough time has passed,
// in this case do not adjust last refill checkpoint, other... | go | func (tb *tokenBucket) updateAvailableTokens() {
now := tb.clock.UtcNow()
timePassed := now.Sub(tb.lastRefresh)
tokens := tb.availableTokens + int64(timePassed/tb.timePerToken)
// If we haven't added any tokens that means that not enough time has passed,
// in this case do not adjust last refill checkpoint, other... | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"updateAvailableTokens",
"(",
")",
"{",
"now",
":=",
"tb",
".",
"clock",
".",
"UtcNow",
"(",
")",
"\n",
"timePassed",
":=",
"now",
".",
"Sub",
"(",
"tb",
".",
"lastRefresh",
")",
"\n\n",
"tokens",
":=",
"tb... | // updateAvailableTokens updates the number of tokens available for consumption.
// It is calculated based on the refill rate, the time passed since last refresh,
// and is limited by the bucket capacity. | [
"updateAvailableTokens",
"updates",
"the",
"number",
"of",
"tokens",
"available",
"for",
"consumption",
".",
"It",
"is",
"calculated",
"based",
"on",
"the",
"refill",
"rate",
"the",
"time",
"passed",
"since",
"last",
"refresh",
"and",
"is",
"limited",
"by",
"t... | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L111-L126 |
149,307 | vulcand/oxy | trace/trace.go | RequestHeaders | func RequestHeaders(headers ...string) Option {
return func(t *Tracer) error {
t.reqHeaders = append(t.reqHeaders, headers...)
return nil
}
} | go | func RequestHeaders(headers ...string) Option {
return func(t *Tracer) error {
t.reqHeaders = append(t.reqHeaders, headers...)
return nil
}
} | [
"func",
"RequestHeaders",
"(",
"headers",
"...",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
")",
"error",
"{",
"t",
".",
"reqHeaders",
"=",
"append",
"(",
"t",
".",
"reqHeaders",
",",
"headers",
"...",
")",
"\n",
"return",... | // RequestHeaders adds request headers to capture | [
"RequestHeaders",
"adds",
"request",
"headers",
"to",
"capture"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/trace/trace.go#L29-L34 |
149,308 | vulcand/oxy | trace/trace.go | ResponseHeaders | func ResponseHeaders(headers ...string) Option {
return func(t *Tracer) error {
t.respHeaders = append(t.respHeaders, headers...)
return nil
}
} | go | func ResponseHeaders(headers ...string) Option {
return func(t *Tracer) error {
t.respHeaders = append(t.respHeaders, headers...)
return nil
}
} | [
"func",
"ResponseHeaders",
"(",
"headers",
"...",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
")",
"error",
"{",
"t",
".",
"respHeaders",
"=",
"append",
"(",
"t",
".",
"respHeaders",
",",
"headers",
"...",
")",
"\n",
"retur... | // ResponseHeaders adds response headers to capture | [
"ResponseHeaders",
"adds",
"response",
"headers",
"to",
"capture"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/trace/trace.go#L37-L42 |
149,309 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerClock | func RebalancerClock(clock timetools.TimeProvider) RebalancerOption {
return func(r *Rebalancer) error {
r.clock = clock
return nil
}
} | go | func RebalancerClock(clock timetools.TimeProvider) RebalancerOption {
return func(r *Rebalancer) error {
r.clock = clock
return nil
}
} | [
"func",
"RebalancerClock",
"(",
"clock",
"timetools",
".",
"TimeProvider",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"clock",
"=",
"clock",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RebalancerClock sets a clock | [
"RebalancerClock",
"sets",
"a",
"clock"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L61-L66 |
149,310 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerBackoff | func RebalancerBackoff(d time.Duration) RebalancerOption {
return func(r *Rebalancer) error {
r.backoffDuration = d
return nil
}
} | go | func RebalancerBackoff(d time.Duration) RebalancerOption {
return func(r *Rebalancer) error {
r.backoffDuration = d
return nil
}
} | [
"func",
"RebalancerBackoff",
"(",
"d",
"time",
".",
"Duration",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"backoffDuration",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RebalancerBackoff sets a beck off duration | [
"RebalancerBackoff",
"sets",
"a",
"beck",
"off",
"duration"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L69-L74 |
149,311 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerMeter | func RebalancerMeter(newMeter NewMeterFn) RebalancerOption {
return func(r *Rebalancer) error {
r.newMeter = newMeter
return nil
}
} | go | func RebalancerMeter(newMeter NewMeterFn) RebalancerOption {
return func(r *Rebalancer) error {
r.newMeter = newMeter
return nil
}
} | [
"func",
"RebalancerMeter",
"(",
"newMeter",
"NewMeterFn",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"newMeter",
"=",
"newMeter",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RebalancerMeter sets a Meter builder function | [
"RebalancerMeter",
"sets",
"a",
"Meter",
"builder",
"function"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L77-L82 |
149,312 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerErrorHandler | func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption {
return func(r *Rebalancer) error {
r.errHandler = h
return nil
}
} | go | func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption {
return func(r *Rebalancer) error {
r.errHandler = h
return nil
}
} | [
"func",
"RebalancerErrorHandler",
"(",
"h",
"utils",
".",
"ErrorHandler",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"errHandler",
"=",
"h",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RebalancerErrorHandler is a functional argument that sets error handler of the server | [
"RebalancerErrorHandler",
"is",
"a",
"functional",
"argument",
"that",
"sets",
"error",
"handler",
"of",
"the",
"server"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L85-L90 |
149,313 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerStickySession | func RebalancerStickySession(stickySession *StickySession) RebalancerOption {
return func(r *Rebalancer) error {
r.stickySession = stickySession
return nil
}
} | go | func RebalancerStickySession(stickySession *StickySession) RebalancerOption {
return func(r *Rebalancer) error {
r.stickySession = stickySession
return nil
}
} | [
"func",
"RebalancerStickySession",
"(",
"stickySession",
"*",
"StickySession",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"stickySession",
"=",
"stickySession",
"\n",
"return",
"nil",
"\n",
"}",
"\... | // RebalancerStickySession sets a sticky session | [
"RebalancerStickySession",
"sets",
"a",
"sticky",
"session"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L93-L98 |
149,314 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerRequestRewriteListener | func RebalancerRequestRewriteListener(rrl RequestRewriteListener) RebalancerOption {
return func(r *Rebalancer) error {
r.requestRewriteListener = rrl
return nil
}
} | go | func RebalancerRequestRewriteListener(rrl RequestRewriteListener) RebalancerOption {
return func(r *Rebalancer) error {
r.requestRewriteListener = rrl
return nil
}
} | [
"func",
"RebalancerRequestRewriteListener",
"(",
"rrl",
"RequestRewriteListener",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"requestRewriteListener",
"=",
"rrl",
"\n",
"return",
"nil",
"\n",
"}",
"\... | // RebalancerRequestRewriteListener is a functional argument that sets error handler of the server | [
"RebalancerRequestRewriteListener",
"is",
"a",
"functional",
"argument",
"that",
"sets",
"error",
"handler",
"of",
"the",
"server"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L101-L106 |
149,315 | vulcand/oxy | roundrobin/rebalancer.go | NewRebalancer | func NewRebalancer(handler balancerHandler, opts ...RebalancerOption) (*Rebalancer, error) {
rb := &Rebalancer{
mtx: &sync.Mutex{},
next: handler,
stickySession: nil,
log: log.StandardLogger(),
}
for _, o := range opts {
if err := o(rb); err != nil {
return nil, err
}
}
if rb.clo... | go | func NewRebalancer(handler balancerHandler, opts ...RebalancerOption) (*Rebalancer, error) {
rb := &Rebalancer{
mtx: &sync.Mutex{},
next: handler,
stickySession: nil,
log: log.StandardLogger(),
}
for _, o := range opts {
if err := o(rb); err != nil {
return nil, err
}
}
if rb.clo... | [
"func",
"NewRebalancer",
"(",
"handler",
"balancerHandler",
",",
"opts",
"...",
"RebalancerOption",
")",
"(",
"*",
"Rebalancer",
",",
"error",
")",
"{",
"rb",
":=",
"&",
"Rebalancer",
"{",
"mtx",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"next",
"... | // NewRebalancer creates a new Rebalancer | [
"NewRebalancer",
"creates",
"a",
"new",
"Rebalancer"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L109-L145 |
149,316 | 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 |
149,317 | 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 |
149,318 | 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 |
149,319 | 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 |
149,320 | 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 |
149,321 | 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 |
149,322 | 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 |
149,323 | 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 |
149,324 | 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 |
149,325 | 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 |
149,326 | 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 |
149,327 | 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 |
149,328 | 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 |
149,329 | 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 |
149,330 | 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 |
149,331 | 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 |
149,332 | 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 |
149,333 | 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 |
149,334 | 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 |
149,335 | 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 |
149,336 | 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 |
149,337 | 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 |
149,338 | 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 |
149,339 | 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 |
149,340 | 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 |
149,341 | 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 |
149,342 | 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 |
149,343 | 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 |
149,344 | 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 |
149,345 | 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 |
149,346 | 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 |
149,347 | 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 |
149,348 | 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 |
149,349 | 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 |
149,350 | 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 |
149,351 | 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 |
149,352 | 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 |
149,353 | 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 |
149,354 | 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 |
149,355 | 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 |
149,356 | 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 |
149,357 | 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 |
149,358 | 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 |
149,359 | 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 |
149,360 | 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 |
149,361 | 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 |
149,362 | 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 |
149,363 | 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 |
149,364 | 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 |
149,365 | 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 |
149,366 | 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 |
149,367 | 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 |
149,368 | 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 |
149,369 | 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 |
149,370 | 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 |
149,371 | 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 |
149,372 | 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 |
149,373 | 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 |
149,374 | 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 |
149,375 | 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 |
149,376 | 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 |
149,377 | 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 |
149,378 | 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 |
149,379 | 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 |
149,380 | 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 |
149,381 | 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 |
149,382 | 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 |
149,383 | 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 |
149,384 | 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 |
149,385 | 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 |
149,386 | 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 |
149,387 | 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 |
149,388 | 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 |
149,389 | 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 |
149,390 | 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 |
149,391 | 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 |
149,392 | 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 |
149,393 | 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 |
149,394 | 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 |
149,395 | 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 |
149,396 | 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 |
149,397 | 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 |
149,398 | 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 |
149,399 | 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 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.