_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3 values | text stringlengths 52 85.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q13200 | Dial | train | func Dial(timeout, keepAlive time.Duration) p.Plugin {
return All(Timeouts{Dial: timeout, KeepAlive: keepAlive})
} | go | {
"resource": ""
} |
q13201 | All | train | func All(timeouts Timeouts) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
defineTimeouts(timeouts, ctx)
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13202 | NewRequest | train | func NewRequest() *Request {
ctx := context.New()
ctx.Client.Transport = DefaultTransport
ctx.Request.Header.Set("User-Agent", UserAgent)
return &Request{
Context: ctx,
Middleware: middleware.New(),
}
} | go | {
"resource": ""
} |
q13203 | SetClient | train | func (r *Request) SetClient(cli *Client) *Request {
r.Client = cli
r.Context.UseParent(cli.Context)
r.Middleware.UseParent(cli.Middleware)
return r
} | go | {
"resource": ""
} |
q13204 | Mux | train | func (r *Request) Mux() *mux.Mux {
mx := mux.New()
r.Use(mx)
return mx
} | go | {
"resource": ""
} |
q13205 | Method | train | func (r *Request) Method(method string) *Request {
r.Middleware.UseRequest(func(ctx *context.Context, h context.Handler) {
ctx.Request.Method = method
h.Next(ctx)
})
return r
} | go | {
"resource": ""
} |
q13206 | URL | train | func (r *Request) URL(uri string) *Request {
r.Use(url.URL(uri))
return r
} | go | {
"resource": ""
} |
q13207 | BaseURL | train | func (r *Request) BaseURL(uri string) *Request {
r.Use(url.BaseURL(uri))
return r
} | go | {
"resource": ""
} |
q13208 | Path | train | func (r *Request) Path(path string) *Request {
r.Use(url.Path(path))
return r
} | go | {
"resource": ""
} |
q13209 | AddPath | train | func (r *Request) AddPath(path string) *Request {
r.Use(url.AddPath(path))
return r
} | go | {
"resource": ""
} |
q13210 | SetQuery | train | func (r *Request) SetQuery(name, value string) *Request {
r.Use(query.Set(name, value))
return r
} | go | {
"resource": ""
} |
q13211 | AddQuery | train | func (r *Request) AddQuery(name, value string) *Request {
r.Use(query.Add(name, value))
return r
} | go | {
"resource": ""
} |
q13212 | SetQueryParams | train | func (r *Request) SetQueryParams(params map[string]string) *Request {
r.Use(query.SetMap(params))
return r
} | go | {
"resource": ""
} |
q13213 | DelHeader | train | func (r *Request) DelHeader(name string) *Request {
r.Use(headers.Del(name))
return r
} | go | {
"resource": ""
} |
q13214 | Body | train | func (r *Request) Body(reader io.Reader) *Request {
r.Use(body.Reader(reader))
return r
} | go | {
"resource": ""
} |
q13215 | BodyString | train | func (r *Request) BodyString(data string) *Request {
r.Use(body.String(data))
return r
} | go | {
"resource": ""
} |
q13216 | JSON | train | func (r *Request) JSON(data interface{}) *Request {
r.Use(body.JSON(data))
return r
} | go | {
"resource": ""
} |
q13217 | XML | train | func (r *Request) XML(data interface{}) *Request {
r.Use(body.XML(data))
return r
} | go | {
"resource": ""
} |
q13218 | Do | train | func (r *Request) Do() (*Response, error) {
if r.dispatched {
return nil, errors.New("gentleman: Request was already dispatched")
}
r.dispatched = true
ctx := NewDispatcher(r).Dispatch()
return buildResponse(ctx)
} | go | {
"resource": ""
} |
q13219 | Use | train | func (r *Request) Use(p plugin.Plugin) *Request {
r.Middleware.Use(p)
return r
} | go | {
"resource": ""
} |
q13220 | UseRequest | train | func (r *Request) UseRequest(fn context.HandlerFunc) *Request {
r.Middleware.UseRequest(fn)
return r
} | go | {
"resource": ""
} |
q13221 | UseResponse | train | func (r *Request) UseResponse(fn context.HandlerFunc) *Request {
r.Middleware.UseResponse(fn)
return r
} | go | {
"resource": ""
} |
q13222 | UseError | train | func (r *Request) UseError(fn context.HandlerFunc) *Request {
r.Middleware.UseError(fn)
return r
} | go | {
"resource": ""
} |
q13223 | UseHandler | train | func (r *Request) UseHandler(phase string, fn context.HandlerFunc) *Request {
r.Middleware.UseHandler(phase, fn)
return r
} | go | {
"resource": ""
} |
q13224 | Clone | train | func (r *Request) Clone() *Request {
req := NewRequest()
req.Client = r.Client
req.Context = r.Context.Clone()
req.Middleware = r.Middleware.Clone()
return req
} | go | {
"resource": ""
} |
q13225 | NewDefaultTransport | train | func NewDefaultTransport(dialer *net.Dialer) *http.Transport {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: dialer.Dial,
TLSHandshakeTimeout: TLSHandshakeTimeout,
}
return transport
} | go | {
"resource": ""
} |
q13226 | Basic | train | func Basic(username, password string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Request.SetBasicAuth(username, password)
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13227 | Bearer | train | func Bearer(token string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Request.Header.Set("Authorization", "Bearer "+token)
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13228 | Custom | train | func Custom(value string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Request.Header.Set("Authorization", value)
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13229 | Disable | train | func Disable() p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
// Assert http.Transport to work with the instance
transport, ok := ctx.Client.Transport.(*http.Transport)
if !ok {
h.Next(ctx)
return
}
// Override the http.Client transport
transport.DisableCompression = true
ctx.Client.Transport = transport
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13230 | Add | train | func Add(cookie *http.Cookie) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Request.AddCookie(cookie)
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13231 | Set | train | func Set(key, value string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
cookie := &http.Cookie{Name: key, Value: value}
ctx.Request.AddCookie(cookie)
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13232 | SetMap | train | func SetMap(cookies map[string]string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
for k, v := range cookies {
cookie := &http.Cookie{Name: k, Value: v}
ctx.Request.AddCookie(cookie)
}
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13233 | AddMultiple | train | func AddMultiple(cookies []*http.Cookie) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
for _, cookie := range cookies {
ctx.Request.AddCookie(cookie)
}
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13234 | Jar | train | func Jar() p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
jar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
ctx.Client.Jar = jar
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13235 | Set | train | func Set(transport http.RoundTripper) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
// Override the http.Client transport
ctx.Client.Transport = transport
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13236 | Config | train | func Config(config *tls.Config) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
// Assert http.Transport to work with the instance
transport, ok := ctx.Client.Transport.(*http.Transport)
if !ok {
// If using a custom transport, just ignore it
h.Next(ctx)
return
}
// Override the http.Client transport
transport.TLSClientConfig = config
ctx.Client.Transport = transport
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13237 | Config | train | func Config(opts Options) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Client.CheckRedirect = func(req *http.Request, pool []*http.Request) error {
return redirectPolicy(opts, req, pool)
}
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13238 | Limit | train | func Limit(limit int) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Client.CheckRedirect = func(req *http.Request, pool []*http.Request) error {
return redirectPolicy(Options{Limit: limit}, req, pool)
}
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13239 | Error | train | func (h handler) Error(ctx *Context, err error) {
ctx.Error = err
h.next(ctx)
} | go | {
"resource": ""
} |
q13240 | Stop | train | func (h handler) Stop(ctx *Context) {
ctx.Stopped = true
h.next(ctx)
} | go | {
"resource": ""
} |
q13241 | once | train | func once(fn HandlerCtx) HandlerCtx {
called := false
return func(ctx *Context) {
if called {
return
}
called = true
fn(ctx)
}
} | go | {
"resource": ""
} |
q13242 | Set | train | func Set(servers map[string]string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
// Assert http.Transport to work with the instance
transport, ok := ctx.Client.Transport.(*http.Transport)
if !ok {
// If using a custom transport, just ignore it
h.Next(ctx)
return
}
// Define the proxy function to be used during the transport
transport.Proxy = func(req *http.Request) (*url.URL, error) {
if value, ok := servers[req.URL.Scheme]; ok {
return url.Parse(value)
}
return http.ProxyFromEnvironment(req)
}
// Override the transport
ctx.Client.Transport = transport
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13243 | Request | train | func (c *Client) Request() *Request {
req := NewRequest()
req.SetClient(c)
return req
} | go | {
"resource": ""
} |
q13244 | Get | train | func (c *Client) Get() *Request {
req := c.Request()
req.Method("GET")
return req
} | go | {
"resource": ""
} |
q13245 | Post | train | func (c *Client) Post() *Request {
req := c.Request()
req.Method("POST")
return req
} | go | {
"resource": ""
} |
q13246 | Put | train | func (c *Client) Put() *Request {
req := c.Request()
req.Method("PUT")
return req
} | go | {
"resource": ""
} |
q13247 | Delete | train | func (c *Client) Delete() *Request {
req := c.Request()
req.Method("DELETE")
return req
} | go | {
"resource": ""
} |
q13248 | Patch | train | func (c *Client) Patch() *Request {
req := c.Request()
req.Method("PATCH")
return req
} | go | {
"resource": ""
} |
q13249 | Head | train | func (c *Client) Head() *Request {
req := c.Request()
req.Method("HEAD")
return req
} | go | {
"resource": ""
} |
q13250 | Method | train | func (c *Client) Method(name string) *Client {
c.Middleware.UseRequest(func(ctx *context.Context, h context.Handler) {
ctx.Request.Method = name
h.Next(ctx)
})
return c
} | go | {
"resource": ""
} |
q13251 | URL | train | func (c *Client) URL(uri string) *Client {
c.Use(url.URL(uri))
return c
} | go | {
"resource": ""
} |
q13252 | BaseURL | train | func (c *Client) BaseURL(uri string) *Client {
c.Use(url.BaseURL(uri))
return c
} | go | {
"resource": ""
} |
q13253 | Path | train | func (c *Client) Path(path string) *Client {
c.Use(url.Path(path))
return c
} | go | {
"resource": ""
} |
q13254 | Use | train | func (c *Client) Use(p plugin.Plugin) *Client {
c.Middleware.Use(p)
return c
} | go | {
"resource": ""
} |
q13255 | UseRequest | train | func (c *Client) UseRequest(fn context.HandlerFunc) *Client {
c.Middleware.UseRequest(fn)
return c
} | go | {
"resource": ""
} |
q13256 | UseResponse | train | func (c *Client) UseResponse(fn context.HandlerFunc) *Client {
c.Middleware.UseResponse(fn)
return c
} | go | {
"resource": ""
} |
q13257 | UseError | train | func (c *Client) UseError(fn context.HandlerFunc) *Client {
c.Middleware.UseError(fn)
return c
} | go | {
"resource": ""
} |
q13258 | UseHandler | train | func (c *Client) UseHandler(phase string, fn context.HandlerFunc) *Client {
c.Middleware.UseHandler(phase, fn)
return c
} | go | {
"resource": ""
} |
q13259 | UseParent | train | func (c *Client) UseParent(parent *Client) *Client {
c.Parent = parent
c.Context.UseParent(parent.Context)
c.Middleware.UseParent(parent.Middleware)
return c
} | go | {
"resource": ""
} |
q13260 | File | train | func File(name string, reader io.Reader) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
file := FormFile{name, reader}
data := FormData{Files: []FormFile{file}}
handle(ctx, h, data)
})
} | go | {
"resource": ""
} |
q13261 | Files | train | func Files(files []FormFile) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
data := FormData{Files: files}
handle(ctx, h, data)
})
} | go | {
"resource": ""
} |
q13262 | Data | train | func Data(data FormData) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
handle(ctx, h, data)
})
} | go | {
"resource": ""
} |
q13263 | SetHandler | train | func (p *Layer) SetHandler(phase string, handler context.HandlerFunc) {
p.Handlers[phase] = handler
} | go | {
"resource": ""
} |
q13264 | Exec | train | func (p *Layer) Exec(phase string, ctx *context.Context, h context.Handler) {
if p.disabled || p.removed {
h.Next(ctx)
return
}
fn := p.Handlers[phase]
if fn == nil {
fn = p.DefaultHandler
}
if fn == nil {
h.Next(ctx)
return
}
fn(ctx, h)
} | go | {
"resource": ""
} |
q13265 | NewPhasePlugin | train | func NewPhasePlugin(phase string, handler context.HandlerFunc) Plugin {
return &Layer{Handlers: Handlers{phase: handler}}
} | go | {
"resource": ""
} |
q13266 | ReplyWithStatus | train | func ReplyWithStatus(res *http.Response, code int) {
res.StatusCode = code
res.Status = strconv.Itoa(code) + " " + http.StatusText(code)
} | go | {
"resource": ""
} |
q13267 | WriteBodyString | train | func WriteBodyString(res *http.Response, body string) {
res.Body = StringReader(body)
res.ContentLength = int64(len(body))
} | go | {
"resource": ""
} |
q13268 | StringReader | train | func StringReader(body string) io.ReadCloser {
b := bytes.NewReader([]byte(body))
rc, ok := io.Reader(b).(io.ReadCloser)
if !ok && b != nil {
rc = ioutil.NopCloser(b)
}
return rc
} | go | {
"resource": ""
} |
q13269 | SetMap | train | func SetMap(headers map[string]string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
for k, v := range headers {
ctx.Request.Header.Set(k, v)
}
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13270 | Set | train | func Set(name string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
defineType(name, ctx.Request)
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13271 | New | train | func New() *Context {
req := createRequest()
res := createResponse(req)
cli := &http.Client{Transport: http.DefaultTransport}
return &Context{Request: req, Response: res, Client: cli}
} | go | {
"resource": ""
} |
q13272 | getStore | train | func (c *Context) getStore() Store {
store, ok := c.Request.Context().Value(Key).(Store)
if !ok {
panic("invalid request context")
}
return store
} | go | {
"resource": ""
} |
q13273 | Set | train | func (c *Context) Set(key interface{}, value interface{}) {
store := c.getStore()
store[key] = value
} | go | {
"resource": ""
} |
q13274 | Get | train | func (c *Context) Get(key interface{}) interface{} {
store := c.getStore()
if store == nil {
return store
}
if value, ok := store[key]; ok {
return value
}
if c.Parent != nil {
return c.Parent.Get(key)
}
return nil
} | go | {
"resource": ""
} |
q13275 | GetInt | train | func (c *Context) GetInt(key interface{}) (int, bool) {
value, ok := c.GetOk(key)
if !ok {
if c.Parent != nil {
return c.Parent.GetInt(key)
}
}
if num, ok := value.(int); ok {
return num, ok
}
return 0, false
} | go | {
"resource": ""
} |
q13276 | GetString | train | func (c *Context) GetString(key interface{}) string {
store := c.getStore()
if value, ok := store[key]; ok {
if typed, ok := value.(string); ok {
return typed
}
}
if c.Parent != nil {
return c.Parent.GetString(key)
}
return ""
} | go | {
"resource": ""
} |
q13277 | GetAll | train | func (c *Context) GetAll() Store {
buf := Store{}
for key, value := range c.getStore() {
buf[key] = value
}
if c.Parent != nil {
for key, value := range c.Parent.GetAll() {
buf[key] = value
}
}
return buf
} | go | {
"resource": ""
} |
q13278 | Root | train | func (c *Context) Root() *Context {
if c.Parent != nil {
return c.Parent.Root()
}
return c
} | go | {
"resource": ""
} |
q13279 | SetRequest | train | func (c *Context) SetRequest(req *http.Request) {
c.Request = req.WithContext(c.Request.Context())
} | go | {
"resource": ""
} |
q13280 | Clone | train | func (c *Context) Clone() *Context {
ctx := new(Context)
*ctx = *c
req := new(http.Request)
*req = *c.Request
ctx.Request = req
c.CopyTo(ctx)
res := new(http.Response)
*res = *c.Response
ctx.Response = res
return ctx
} | go | {
"resource": ""
} |
q13281 | CopyTo | train | func (c *Context) CopyTo(newCtx *Context) {
store := Store{}
for key, value := range c.getStore() {
store[key] = value
}
ctx := context.WithValue(context.Background(), Key, store)
newCtx.Request = newCtx.Request.WithContext(ctx)
} | go | {
"resource": ""
} |
q13282 | createRequest | train | func createRequest() *http.Request {
// Create HTTP request
req := &http.Request{
Method: "GET",
URL: &url.URL{},
Host: "",
ProtoMajor: 1,
ProtoMinor: 1,
Proto: "HTTP/1.1",
Header: make(http.Header),
Body: utils.NopCloser(),
}
// Return shallow copy of Request with the new context
return req.WithContext(emptyContext())
} | go | {
"resource": ""
} |
q13283 | createResponse | train | func createResponse(req *http.Request) *http.Response {
return &http.Response{
ProtoMajor: 1,
ProtoMinor: 1,
Proto: "HTTP/1.1",
Request: req,
Header: make(http.Header),
Body: utils.NopCloser(),
}
} | go | {
"resource": ""
} |
q13284 | Set | train | func Set(key, value string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
query := ctx.Request.URL.Query()
query.Set(key, value)
ctx.Request.URL.RawQuery = query.Encode()
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13285 | DelAll | train | func DelAll() p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Request.URL.RawQuery = ""
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13286 | SetMap | train | func SetMap(params map[string]string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
query := ctx.Request.URL.Query()
for k, v := range params {
query.Set(k, v)
}
ctx.Request.URL.RawQuery = query.Encode()
h.Next(ctx)
})
} | go | {
"resource": ""
} |
q13287 | Close | train | func (r *Response) Close() error {
if r.Error != nil {
return r.Error
}
return r.RawResponse.Body.Close()
} | go | {
"resource": ""
} |
q13288 | XML | train | func (r *Response) XML(userStruct interface{}, charsetReader utils.XMLCharDecoder) error {
if r.Error != nil {
return r.Error
}
xmlDecoder := xml.NewDecoder(r.getInternalReader())
if charsetReader != nil {
xmlDecoder.CharsetReader = charsetReader
}
defer r.Close()
if err := xmlDecoder.Decode(&userStruct); err != nil && err != io.EOF {
return err
}
return nil
} | go | {
"resource": ""
} |
q13289 | Bytes | train | func (r *Response) Bytes() []byte {
if r.Error != nil {
return nil
}
r.populateResponseByteBuffer()
// Are we still empty?
if r.buffer.Len() == 0 {
return nil
}
return r.buffer.Bytes()
} | go | {
"resource": ""
} |
q13290 | String | train | func (r *Response) String() string {
if r.Error != nil {
return ""
}
r.populateResponseByteBuffer()
return r.buffer.String()
} | go | {
"resource": ""
} |
q13291 | isChunkedResponse | train | func isChunkedResponse(res *http.Response) bool {
for _, te := range res.TransferEncoding {
if te == "chunked" {
return true
}
}
return false
} | go | {
"resource": ""
} |
q13292 | sendSSF | train | func sendSSF(client *trace.Client, span *ssf.SSFSpan) error {
done := make(chan error)
err := trace.Record(client, span, done)
if err != nil {
return err
}
return <-done
} | go | {
"resource": ""
} |
q13293 | sendStatsd | train | func sendStatsd(addr string, span *ssf.SSFSpan) error {
client, err := statsd.New(addr)
if err != nil {
return err
}
// Report all the metrics in the span:
for _, metric := range span.Metrics {
tags := make([]string, 0, len(metric.Tags))
for name, val := range metric.Tags {
tags = append(tags, fmt.Sprintf("%s:%s", name, val))
}
switch metric.Metric {
case ssf.SSFSample_COUNTER:
err = client.Count(metric.Name, int64(metric.Value), tags, 1.0)
case ssf.SSFSample_GAUGE:
err = client.Gauge(metric.Name, float64(metric.Value), tags, 1.0)
case ssf.SSFSample_HISTOGRAM:
if metric.Unit == "ms" {
// Treating the "ms" unit special is a
// bit wonky, but it seems like the
// right tool for the job here:
err = client.TimeInMilliseconds(metric.Name, float64(metric.Value), tags, 1.0)
} else {
err = client.Histogram(metric.Name, float64(metric.Value), tags, 1.0)
}
case ssf.SSFSample_SET:
err = client.Set(metric.Name, metric.Message, tags, 1.0)
}
if err != nil {
return err
}
}
return nil
} | go | {
"resource": ""
} |
q13294 | SetPutObject | train | func (m *MockS3Client) SetPutObject(f func(*s3.PutObjectInput) (*s3.PutObjectOutput, error)) {
m.putObject = f
} | go | {
"resource": ""
} |
q13295 | SendSync | train | func (ds *streamBackend) SendSync(ctx context.Context, span *ssf.SSFSpan) error {
if ds.conn == nil {
if err := connect(ctx, ds); err != nil {
return err
}
}
_, err := protocol.WriteSSF(ds.output, span)
if err != nil {
if protocol.IsFramingError(err) {
_ = ds.conn.Close()
ds.conn = nil
}
}
return err
} | go | {
"resource": ""
} |
q13296 | FlushSync | train | func (ds *streamBackend) FlushSync(ctx context.Context) error {
if ds.buffer == nil {
return nil
}
if ds.conn == nil {
if err := connect(ctx, ds); err != nil {
return err
}
}
err := ds.buffer.Flush()
if err != nil {
// buffer is poisoned, and we have no idea if the
// connection is still valid. We better reconnect.
_ = ds.conn.Close()
ds.conn = nil
}
return err
} | go | {
"resource": ""
} |
q13297 | handleImport | train | func handleImport(s *Server) http.Handler {
return contextHandler(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
span, jsonMetrics, err := unmarshalMetricsFromHTTP(ctx, s.TraceClient, w, r)
if err != nil {
log.WithError(err).Error("Error unmarshalling metrics in global import")
span.Add(ssf.Count("import.unmarshal.errors_total", 1, nil))
return
}
// the server usually waits for this to return before finalizing the
// response, so this part must be done asynchronously
go s.ImportMetrics(span.Attach(ctx), jsonMetrics)
})
} | go | {
"resource": ""
} |
q13298 | nonEmpty | train | func nonEmpty(ctx context.Context, client *trace.Client, jsonMetrics []samplers.JSONMetric) bool {
span, _ := trace.StartSpanFromContext(ctx, "veneur.opentracing.import.nonEmpty")
defer span.ClientFinish(client)
sentinel := samplers.JSONMetric{}
for _, metric := range jsonMetrics {
if !reflect.DeepEqual(sentinel, metric) {
// we have found at least one entry that is properly formed
return true
}
}
return false
} | go | {
"resource": ""
} |
q13299 | RouteTo | train | func (ri RouteInformation) RouteTo(name string) bool {
if ri == nil {
return true
}
_, ok := ri[name]
return ok
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.