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
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,200 | h2non/gentleman | plugins/timeout/timeout.go | Dial | func Dial(timeout, keepAlive time.Duration) p.Plugin {
return All(Timeouts{Dial: timeout, KeepAlive: keepAlive})
} | go | func Dial(timeout, keepAlive time.Duration) p.Plugin {
return All(Timeouts{Dial: timeout, KeepAlive: keepAlive})
} | [
"func",
"Dial",
"(",
"timeout",
",",
"keepAlive",
"time",
".",
"Duration",
")",
"p",
".",
"Plugin",
"{",
"return",
"All",
"(",
"Timeouts",
"{",
"Dial",
":",
"timeout",
",",
"KeepAlive",
":",
"keepAlive",
"}",
")",
"\n",
"}"
]
| // Dial defines the maximum amount of time waiting for network dialing | [
"Dial",
"defines",
"the",
"maximum",
"amount",
"of",
"time",
"waiting",
"for",
"network",
"dialing"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/timeout/timeout.go#L42-L44 |
13,201 | h2non/gentleman | plugins/timeout/timeout.go | All | func All(timeouts Timeouts) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
defineTimeouts(timeouts, ctx)
h.Next(ctx)
})
} | go | func All(timeouts Timeouts) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
defineTimeouts(timeouts, ctx)
h.Next(ctx)
})
} | [
"func",
"All",
"(",
"timeouts",
"Timeouts",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"defineTimeouts",
"(",
"timeouts",
",",
"ctx",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // All defines all the timeout types for the outgoing request | [
"All",
"defines",
"all",
"the",
"timeout",
"types",
"for",
"the",
"outgoing",
"request"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/timeout/timeout.go#L47-L52 |
13,202 | h2non/gentleman | request.go | NewRequest | 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 | func NewRequest() *Request {
ctx := context.New()
ctx.Client.Transport = DefaultTransport
ctx.Request.Header.Set("User-Agent", UserAgent)
return &Request{
Context: ctx,
Middleware: middleware.New(),
}
} | [
"func",
"NewRequest",
"(",
")",
"*",
"Request",
"{",
"ctx",
":=",
"context",
".",
"New",
"(",
")",
"\n",
"ctx",
".",
"Client",
".",
"Transport",
"=",
"DefaultTransport",
"\n",
"ctx",
".",
"Request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"UserAgent",
")",
"\n",
"return",
"&",
"Request",
"{",
"Context",
":",
"ctx",
",",
"Middleware",
":",
"middleware",
".",
"New",
"(",
")",
",",
"}",
"\n",
"}"
]
| // NewRequest creates a new Request entity. | [
"NewRequest",
"creates",
"a",
"new",
"Request",
"entity",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L71-L79 |
13,203 | h2non/gentleman | request.go | SetClient | func (r *Request) SetClient(cli *Client) *Request {
r.Client = cli
r.Context.UseParent(cli.Context)
r.Middleware.UseParent(cli.Middleware)
return r
} | go | func (r *Request) SetClient(cli *Client) *Request {
r.Client = cli
r.Context.UseParent(cli.Context)
r.Middleware.UseParent(cli.Middleware)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"SetClient",
"(",
"cli",
"*",
"Client",
")",
"*",
"Request",
"{",
"r",
".",
"Client",
"=",
"cli",
"\n",
"r",
".",
"Context",
".",
"UseParent",
"(",
"cli",
".",
"Context",
")",
"\n",
"r",
".",
"Middleware",
".",
"UseParent",
"(",
"cli",
".",
"Middleware",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // SetClient Attach a client to the current Request
// This is mostly done internally. | [
"SetClient",
"Attach",
"a",
"client",
"to",
"the",
"current",
"Request",
"This",
"is",
"mostly",
"done",
"internally",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L83-L88 |
13,204 | h2non/gentleman | request.go | Mux | func (r *Request) Mux() *mux.Mux {
mx := mux.New()
r.Use(mx)
return mx
} | go | func (r *Request) Mux() *mux.Mux {
mx := mux.New()
r.Use(mx)
return mx
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Mux",
"(",
")",
"*",
"mux",
".",
"Mux",
"{",
"mx",
":=",
"mux",
".",
"New",
"(",
")",
"\n",
"r",
".",
"Use",
"(",
"mx",
")",
"\n",
"return",
"mx",
"\n",
"}"
]
| // Mux is a middleware multiplexer for easy plugin composition. | [
"Mux",
"is",
"a",
"middleware",
"multiplexer",
"for",
"easy",
"plugin",
"composition",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L91-L95 |
13,205 | h2non/gentleman | request.go | Method | 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 | 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
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Method",
"(",
"method",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Middleware",
".",
"UseRequest",
"(",
"func",
"(",
"ctx",
"*",
"context",
".",
"Context",
",",
"h",
"context",
".",
"Handler",
")",
"{",
"ctx",
".",
"Request",
".",
"Method",
"=",
"method",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // Method defines the HTTP verb to be used. | [
"Method",
"defines",
"the",
"HTTP",
"verb",
"to",
"be",
"used",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L98-L104 |
13,206 | h2non/gentleman | request.go | URL | func (r *Request) URL(uri string) *Request {
r.Use(url.URL(uri))
return r
} | go | func (r *Request) URL(uri string) *Request {
r.Use(url.URL(uri))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"URL",
"(",
"uri",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"url",
".",
"URL",
"(",
"uri",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // URL parses and defines the URL to be used in the outgoing request. | [
"URL",
"parses",
"and",
"defines",
"the",
"URL",
"to",
"be",
"used",
"in",
"the",
"outgoing",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L107-L110 |
13,207 | h2non/gentleman | request.go | BaseURL | func (r *Request) BaseURL(uri string) *Request {
r.Use(url.BaseURL(uri))
return r
} | go | func (r *Request) BaseURL(uri string) *Request {
r.Use(url.BaseURL(uri))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"BaseURL",
"(",
"uri",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"url",
".",
"BaseURL",
"(",
"uri",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // BaseURL parses the given URL and uses the URL schema and host in the outgoing request. | [
"BaseURL",
"parses",
"the",
"given",
"URL",
"and",
"uses",
"the",
"URL",
"schema",
"and",
"host",
"in",
"the",
"outgoing",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L113-L116 |
13,208 | h2non/gentleman | request.go | Path | func (r *Request) Path(path string) *Request {
r.Use(url.Path(path))
return r
} | go | func (r *Request) Path(path string) *Request {
r.Use(url.Path(path))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Path",
"(",
"path",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"url",
".",
"Path",
"(",
"path",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // Path defines the request URL path to be used in the outgoing request. | [
"Path",
"defines",
"the",
"request",
"URL",
"path",
"to",
"be",
"used",
"in",
"the",
"outgoing",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L119-L122 |
13,209 | h2non/gentleman | request.go | AddPath | func (r *Request) AddPath(path string) *Request {
r.Use(url.AddPath(path))
return r
} | go | func (r *Request) AddPath(path string) *Request {
r.Use(url.AddPath(path))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"AddPath",
"(",
"path",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"url",
".",
"AddPath",
"(",
"path",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // AddPath defines the request URL path to be used in the outgoing request. | [
"AddPath",
"defines",
"the",
"request",
"URL",
"path",
"to",
"be",
"used",
"in",
"the",
"outgoing",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L125-L128 |
13,210 | h2non/gentleman | request.go | SetQuery | func (r *Request) SetQuery(name, value string) *Request {
r.Use(query.Set(name, value))
return r
} | go | func (r *Request) SetQuery(name, value string) *Request {
r.Use(query.Set(name, value))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"SetQuery",
"(",
"name",
",",
"value",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"query",
".",
"Set",
"(",
"name",
",",
"value",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // SetQuery sets a new URL query param field.
// If another query param exists with the same key, it will be overwritten. | [
"SetQuery",
"sets",
"a",
"new",
"URL",
"query",
"param",
"field",
".",
"If",
"another",
"query",
"param",
"exists",
"with",
"the",
"same",
"key",
"it",
"will",
"be",
"overwritten",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L144-L147 |
13,211 | h2non/gentleman | request.go | AddQuery | func (r *Request) AddQuery(name, value string) *Request {
r.Use(query.Add(name, value))
return r
} | go | func (r *Request) AddQuery(name, value string) *Request {
r.Use(query.Add(name, value))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"AddQuery",
"(",
"name",
",",
"value",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"query",
".",
"Add",
"(",
"name",
",",
"value",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // AddQuery adds a new URL query param field
// without overwriting any existent query field. | [
"AddQuery",
"adds",
"a",
"new",
"URL",
"query",
"param",
"field",
"without",
"overwriting",
"any",
"existent",
"query",
"field",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L151-L154 |
13,212 | h2non/gentleman | request.go | SetQueryParams | func (r *Request) SetQueryParams(params map[string]string) *Request {
r.Use(query.SetMap(params))
return r
} | go | func (r *Request) SetQueryParams(params map[string]string) *Request {
r.Use(query.SetMap(params))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"SetQueryParams",
"(",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"query",
".",
"SetMap",
"(",
"params",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // SetQueryParams sets URL query params based on the given map. | [
"SetQueryParams",
"sets",
"URL",
"query",
"params",
"based",
"on",
"the",
"given",
"map",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L157-L160 |
13,213 | h2non/gentleman | request.go | DelHeader | func (r *Request) DelHeader(name string) *Request {
r.Use(headers.Del(name))
return r
} | go | func (r *Request) DelHeader(name string) *Request {
r.Use(headers.Del(name))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"DelHeader",
"(",
"name",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"headers",
".",
"Del",
"(",
"name",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // DelHeader deletes a header field by its name | [
"DelHeader",
"deletes",
"a",
"header",
"field",
"by",
"its",
"name"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L183-L186 |
13,214 | h2non/gentleman | request.go | Body | func (r *Request) Body(reader io.Reader) *Request {
r.Use(body.Reader(reader))
return r
} | go | func (r *Request) Body(reader io.Reader) *Request {
r.Use(body.Reader(reader))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Body",
"(",
"reader",
"io",
".",
"Reader",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"body",
".",
"Reader",
"(",
"reader",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // Body defines the request body based on a io.Reader stream. | [
"Body",
"defines",
"the",
"request",
"body",
"based",
"on",
"a",
"io",
".",
"Reader",
"stream",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L216-L219 |
13,215 | h2non/gentleman | request.go | BodyString | func (r *Request) BodyString(data string) *Request {
r.Use(body.String(data))
return r
} | go | func (r *Request) BodyString(data string) *Request {
r.Use(body.String(data))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"BodyString",
"(",
"data",
"string",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"body",
".",
"String",
"(",
"data",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // BodyString defines the request body based on the given string.
// If using this method, you should define the proper Content-Type header
// representing the real content MIME type. | [
"BodyString",
"defines",
"the",
"request",
"body",
"based",
"on",
"the",
"given",
"string",
".",
"If",
"using",
"this",
"method",
"you",
"should",
"define",
"the",
"proper",
"Content",
"-",
"Type",
"header",
"representing",
"the",
"real",
"content",
"MIME",
"type",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L224-L227 |
13,216 | h2non/gentleman | request.go | JSON | func (r *Request) JSON(data interface{}) *Request {
r.Use(body.JSON(data))
return r
} | go | func (r *Request) JSON(data interface{}) *Request {
r.Use(body.JSON(data))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"JSON",
"(",
"data",
"interface",
"{",
"}",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"body",
".",
"JSON",
"(",
"data",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // JSON serializes and defines as request body based on the given input.
// The proper Content-Type header will be transparently added for you. | [
"JSON",
"serializes",
"and",
"defines",
"as",
"request",
"body",
"based",
"on",
"the",
"given",
"input",
".",
"The",
"proper",
"Content",
"-",
"Type",
"header",
"will",
"be",
"transparently",
"added",
"for",
"you",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L231-L234 |
13,217 | h2non/gentleman | request.go | XML | func (r *Request) XML(data interface{}) *Request {
r.Use(body.XML(data))
return r
} | go | func (r *Request) XML(data interface{}) *Request {
r.Use(body.XML(data))
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"XML",
"(",
"data",
"interface",
"{",
"}",
")",
"*",
"Request",
"{",
"r",
".",
"Use",
"(",
"body",
".",
"XML",
"(",
"data",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // XML serializes and defines the request body based on the given input.
// The proper Content-Type header will be transparently added for you. | [
"XML",
"serializes",
"and",
"defines",
"the",
"request",
"body",
"based",
"on",
"the",
"given",
"input",
".",
"The",
"proper",
"Content",
"-",
"Type",
"header",
"will",
"be",
"transparently",
"added",
"for",
"you",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L238-L241 |
13,218 | h2non/gentleman | request.go | Do | 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 | 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)
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Do",
"(",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"if",
"r",
".",
"dispatched",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"r",
".",
"dispatched",
"=",
"true",
"\n",
"ctx",
":=",
"NewDispatcher",
"(",
"r",
")",
".",
"Dispatch",
"(",
")",
"\n\n",
"return",
"buildResponse",
"(",
"ctx",
")",
"\n",
"}"
]
| // Do performs the HTTP request and returns the HTTP response. | [
"Do",
"performs",
"the",
"HTTP",
"request",
"and",
"returns",
"the",
"HTTP",
"response",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L271-L280 |
13,219 | h2non/gentleman | request.go | Use | func (r *Request) Use(p plugin.Plugin) *Request {
r.Middleware.Use(p)
return r
} | go | func (r *Request) Use(p plugin.Plugin) *Request {
r.Middleware.Use(p)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Use",
"(",
"p",
"plugin",
".",
"Plugin",
")",
"*",
"Request",
"{",
"r",
".",
"Middleware",
".",
"Use",
"(",
"p",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // Use uses a new plugin in the middleware stack. | [
"Use",
"uses",
"a",
"new",
"plugin",
"in",
"the",
"middleware",
"stack",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L283-L286 |
13,220 | h2non/gentleman | request.go | UseRequest | func (r *Request) UseRequest(fn context.HandlerFunc) *Request {
r.Middleware.UseRequest(fn)
return r
} | go | func (r *Request) UseRequest(fn context.HandlerFunc) *Request {
r.Middleware.UseRequest(fn)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"UseRequest",
"(",
"fn",
"context",
".",
"HandlerFunc",
")",
"*",
"Request",
"{",
"r",
".",
"Middleware",
".",
"UseRequest",
"(",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // UseRequest uses a request middleware handler. | [
"UseRequest",
"uses",
"a",
"request",
"middleware",
"handler",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L289-L292 |
13,221 | h2non/gentleman | request.go | UseResponse | func (r *Request) UseResponse(fn context.HandlerFunc) *Request {
r.Middleware.UseResponse(fn)
return r
} | go | func (r *Request) UseResponse(fn context.HandlerFunc) *Request {
r.Middleware.UseResponse(fn)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"UseResponse",
"(",
"fn",
"context",
".",
"HandlerFunc",
")",
"*",
"Request",
"{",
"r",
".",
"Middleware",
".",
"UseResponse",
"(",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // UseResponse uses a response middleware handler. | [
"UseResponse",
"uses",
"a",
"response",
"middleware",
"handler",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L295-L298 |
13,222 | h2non/gentleman | request.go | UseError | func (r *Request) UseError(fn context.HandlerFunc) *Request {
r.Middleware.UseError(fn)
return r
} | go | func (r *Request) UseError(fn context.HandlerFunc) *Request {
r.Middleware.UseError(fn)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"UseError",
"(",
"fn",
"context",
".",
"HandlerFunc",
")",
"*",
"Request",
"{",
"r",
".",
"Middleware",
".",
"UseError",
"(",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // UseError uses an error middleware handler. | [
"UseError",
"uses",
"an",
"error",
"middleware",
"handler",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L301-L304 |
13,223 | h2non/gentleman | request.go | UseHandler | func (r *Request) UseHandler(phase string, fn context.HandlerFunc) *Request {
r.Middleware.UseHandler(phase, fn)
return r
} | go | func (r *Request) UseHandler(phase string, fn context.HandlerFunc) *Request {
r.Middleware.UseHandler(phase, fn)
return r
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"UseHandler",
"(",
"phase",
"string",
",",
"fn",
"context",
".",
"HandlerFunc",
")",
"*",
"Request",
"{",
"r",
".",
"Middleware",
".",
"UseHandler",
"(",
"phase",
",",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
]
| // UseHandler uses an new middleware handler for the given phase. | [
"UseHandler",
"uses",
"an",
"new",
"middleware",
"handler",
"for",
"the",
"given",
"phase",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L307-L310 |
13,224 | h2non/gentleman | request.go | Clone | func (r *Request) Clone() *Request {
req := NewRequest()
req.Client = r.Client
req.Context = r.Context.Clone()
req.Middleware = r.Middleware.Clone()
return req
} | go | func (r *Request) Clone() *Request {
req := NewRequest()
req.Client = r.Client
req.Context = r.Context.Clone()
req.Middleware = r.Middleware.Clone()
return req
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Clone",
"(",
")",
"*",
"Request",
"{",
"req",
":=",
"NewRequest",
"(",
")",
"\n",
"req",
".",
"Client",
"=",
"r",
".",
"Client",
"\n",
"req",
".",
"Context",
"=",
"r",
".",
"Context",
".",
"Clone",
"(",
")",
"\n",
"req",
".",
"Middleware",
"=",
"r",
".",
"Middleware",
".",
"Clone",
"(",
")",
"\n",
"return",
"req",
"\n",
"}"
]
| // Clone creates a new side-effects free Request based on the current one. | [
"Clone",
"creates",
"a",
"new",
"side",
"-",
"effects",
"free",
"Request",
"based",
"on",
"the",
"current",
"one",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L313-L319 |
13,225 | h2non/gentleman | request.go | NewDefaultTransport | func NewDefaultTransport(dialer *net.Dialer) *http.Transport {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: dialer.Dial,
TLSHandshakeTimeout: TLSHandshakeTimeout,
}
return transport
} | go | func NewDefaultTransport(dialer *net.Dialer) *http.Transport {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: dialer.Dial,
TLSHandshakeTimeout: TLSHandshakeTimeout,
}
return transport
} | [
"func",
"NewDefaultTransport",
"(",
"dialer",
"*",
"net",
".",
"Dialer",
")",
"*",
"http",
".",
"Transport",
"{",
"transport",
":=",
"&",
"http",
".",
"Transport",
"{",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"Dial",
":",
"dialer",
".",
"Dial",
",",
"TLSHandshakeTimeout",
":",
"TLSHandshakeTimeout",
",",
"}",
"\n",
"return",
"transport",
"\n",
"}"
]
| // NewDefaultTransport returns a new http.Transport with default values
// based on the given net.Dialer. | [
"NewDefaultTransport",
"returns",
"a",
"new",
"http",
".",
"Transport",
"with",
"default",
"values",
"based",
"on",
"the",
"given",
"net",
".",
"Dialer",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/request.go#L323-L330 |
13,226 | h2non/gentleman | plugins/auth/auth.go | Basic | 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 | 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)
})
} | [
"func",
"Basic",
"(",
"username",
",",
"password",
"string",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"ctx",
".",
"Request",
".",
"SetBasicAuth",
"(",
"username",
",",
"password",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Basic defines an authorization basic header in the outgoing request | [
"Basic",
"defines",
"an",
"authorization",
"basic",
"header",
"in",
"the",
"outgoing",
"request"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/auth/auth.go#L9-L14 |
13,227 | h2non/gentleman | plugins/auth/auth.go | Bearer | 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 | 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)
})
} | [
"func",
"Bearer",
"(",
"token",
"string",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"ctx",
".",
"Request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"token",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Bearer defines an authorization bearer token header in the outgoing request | [
"Bearer",
"defines",
"an",
"authorization",
"bearer",
"token",
"header",
"in",
"the",
"outgoing",
"request"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/auth/auth.go#L17-L22 |
13,228 | h2non/gentleman | plugins/auth/auth.go | Custom | 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 | 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)
})
} | [
"func",
"Custom",
"(",
"value",
"string",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"ctx",
".",
"Request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"value",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Custom defines a custom authorization header field in the outgoing request | [
"Custom",
"defines",
"a",
"custom",
"authorization",
"header",
"field",
"in",
"the",
"outgoing",
"request"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/auth/auth.go#L25-L30 |
13,229 | h2non/gentleman | plugins/compression/compression.go | Disable | 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 | 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)
})
} | [
"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",
")",
"\n",
"if",
"!",
"ok",
"{",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Override the http.Client transport",
"transport",
".",
"DisableCompression",
"=",
"true",
"\n",
"ctx",
".",
"Client",
".",
"Transport",
"=",
"transport",
"\n\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Disable disables the authorization basic header in the outgoing request | [
"Disable",
"disables",
"the",
"authorization",
"basic",
"header",
"in",
"the",
"outgoing",
"request"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/compression/compression.go#L10-L25 |
13,230 | h2non/gentleman | plugins/cookies/cookies.go | Add | 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 | func Add(cookie *http.Cookie) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Request.AddCookie(cookie)
h.Next(ctx)
})
} | [
"func",
"Add",
"(",
"cookie",
"*",
"http",
".",
"Cookie",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"ctx",
".",
"Request",
".",
"AddCookie",
"(",
"cookie",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Add adds a cookie to the request. Per RFC 6265 section 5.4, AddCookie does not
// attach more than one Cookie header field.
// That means all cookies, if any, are written into the same line, separated by semicolon. | [
"Add",
"adds",
"a",
"cookie",
"to",
"the",
"request",
".",
"Per",
"RFC",
"6265",
"section",
"5",
".",
"4",
"AddCookie",
"does",
"not",
"attach",
"more",
"than",
"one",
"Cookie",
"header",
"field",
".",
"That",
"means",
"all",
"cookies",
"if",
"any",
"are",
"written",
"into",
"the",
"same",
"line",
"separated",
"by",
"semicolon",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/cookies/cookies.go#L14-L19 |
13,231 | h2non/gentleman | plugins/cookies/cookies.go | Set | 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 | 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)
})
} | [
"func",
"Set",
"(",
"key",
",",
"value",
"string",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"cookie",
":=",
"&",
"http",
".",
"Cookie",
"{",
"Name",
":",
"key",
",",
"Value",
":",
"value",
"}",
"\n",
"ctx",
".",
"Request",
".",
"AddCookie",
"(",
"cookie",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Set sets a new cookie field by key and value. | [
"Set",
"sets",
"a",
"new",
"cookie",
"field",
"by",
"key",
"and",
"value",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/cookies/cookies.go#L22-L28 |
13,232 | h2non/gentleman | plugins/cookies/cookies.go | SetMap | 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 | 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)
})
} | [
"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",
"}",
"\n",
"ctx",
".",
"Request",
".",
"AddCookie",
"(",
"cookie",
")",
"\n",
"}",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // SetMap sets a map of cookies represented by key-value pair. | [
"SetMap",
"sets",
"a",
"map",
"of",
"cookies",
"represented",
"by",
"key",
"-",
"value",
"pair",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/cookies/cookies.go#L39-L47 |
13,233 | h2non/gentleman | plugins/cookies/cookies.go | AddMultiple | 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 | 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)
})
} | [
"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",
")",
"\n",
"}",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // AddMultiple adds a list of cookies. | [
"AddMultiple",
"adds",
"a",
"list",
"of",
"cookies",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/cookies/cookies.go#L50-L57 |
13,234 | h2non/gentleman | plugins/cookies/cookies.go | Jar | 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 | 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)
})
} | [
"func",
"Jar",
"(",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"jar",
",",
"_",
":=",
"cookiejar",
".",
"New",
"(",
"&",
"cookiejar",
".",
"Options",
"{",
"PublicSuffixList",
":",
"publicsuffix",
".",
"List",
"}",
")",
"\n",
"ctx",
".",
"Client",
".",
"Jar",
"=",
"jar",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Jar creates a cookie jar to store HTTP cookies when they are sent down. | [
"Jar",
"creates",
"a",
"cookie",
"jar",
"to",
"store",
"HTTP",
"cookies",
"when",
"they",
"are",
"sent",
"down",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/cookies/cookies.go#L60-L66 |
13,235 | h2non/gentleman | plugins/transport/transport.go | Set | 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 | 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)
})
} | [
"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",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Set sets a new HTTP transport for the outgoing request | [
"Set",
"sets",
"a",
"new",
"HTTP",
"transport",
"for",
"the",
"outgoing",
"request"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/transport/transport.go#L10-L16 |
13,236 | h2non/gentleman | plugins/tls/tls.go | Config | 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 | 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)
})
} | [
"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",
")",
"\n",
"if",
"!",
"ok",
"{",
"// If using a custom transport, just ignore it",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Override the http.Client transport",
"transport",
".",
"TLSClientConfig",
"=",
"config",
"\n",
"ctx",
".",
"Client",
".",
"Transport",
"=",
"transport",
"\n\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Config defines the request TLS connection config | [
"Config",
"defines",
"the",
"request",
"TLS",
"connection",
"config"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/tls/tls.go#L11-L27 |
13,237 | h2non/gentleman | plugins/redirect/redirect.go | Config | 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 | 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)
})
} | [
"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",
")",
"\n",
"}",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Config defines in the request http.Client the redirect
// policy based on the given options. | [
"Config",
"defines",
"in",
"the",
"request",
"http",
".",
"Client",
"the",
"redirect",
"policy",
"based",
"on",
"the",
"given",
"options",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/redirect/redirect.go#L48-L55 |
13,238 | h2non/gentleman | plugins/redirect/redirect.go | Limit | 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 | 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)
})
} | [
"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",
")",
"\n",
"}",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Limit defines in the maximum number of redirects that http.Client should follow. | [
"Limit",
"defines",
"in",
"the",
"maximum",
"number",
"of",
"redirects",
"that",
"http",
".",
"Client",
"should",
"follow",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/redirect/redirect.go#L58-L65 |
13,239 | h2non/gentleman | context/handler.go | Error | func (h handler) Error(ctx *Context, err error) {
ctx.Error = err
h.next(ctx)
} | go | func (h handler) Error(ctx *Context, err error) {
ctx.Error = err
h.next(ctx)
} | [
"func",
"(",
"h",
"handler",
")",
"Error",
"(",
"ctx",
"*",
"Context",
",",
"err",
"error",
")",
"{",
"ctx",
".",
"Error",
"=",
"err",
"\n",
"h",
".",
"next",
"(",
"ctx",
")",
"\n",
"}"
]
| // Error reports an error and stops the middleware call chain | [
"Error",
"reports",
"an",
"error",
"and",
"stops",
"the",
"middleware",
"call",
"chain"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/handler.go#L43-L46 |
13,240 | h2non/gentleman | context/handler.go | Stop | func (h handler) Stop(ctx *Context) {
ctx.Stopped = true
h.next(ctx)
} | go | func (h handler) Stop(ctx *Context) {
ctx.Stopped = true
h.next(ctx)
} | [
"func",
"(",
"h",
"handler",
")",
"Stop",
"(",
"ctx",
"*",
"Context",
")",
"{",
"ctx",
".",
"Stopped",
"=",
"true",
"\n",
"h",
".",
"next",
"(",
"ctx",
")",
"\n",
"}"
]
| // Stop stops the middleware call chain with a custom Context | [
"Stop",
"stops",
"the",
"middleware",
"call",
"chain",
"with",
"a",
"custom",
"Context"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/handler.go#L49-L52 |
13,241 | h2non/gentleman | context/handler.go | once | func once(fn HandlerCtx) HandlerCtx {
called := false
return func(ctx *Context) {
if called {
return
}
called = true
fn(ctx)
}
} | go | func once(fn HandlerCtx) HandlerCtx {
called := false
return func(ctx *Context) {
if called {
return
}
called = true
fn(ctx)
}
} | [
"func",
"once",
"(",
"fn",
"HandlerCtx",
")",
"HandlerCtx",
"{",
"called",
":=",
"false",
"\n",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"if",
"called",
"{",
"return",
"\n",
"}",
"\n",
"called",
"=",
"true",
"\n",
"fn",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"}"
]
| // once returns a function that can be executed once
// Subsequent calls will be no-op | [
"once",
"returns",
"a",
"function",
"that",
"can",
"be",
"executed",
"once",
"Subsequent",
"calls",
"will",
"be",
"no",
"-",
"op"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/handler.go#L56-L65 |
13,242 | h2non/gentleman | plugins/proxy/proxy.go | Set | 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 | 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)
})
} | [
"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",
")",
"\n",
"if",
"!",
"ok",
"{",
"// If using a custom transport, just ignore it",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// 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",
")",
"\n",
"}",
"\n",
"return",
"http",
".",
"ProxyFromEnvironment",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"// Override the transport",
"ctx",
".",
"Client",
".",
"Transport",
"=",
"transport",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Set defines the proxy servers to be used based on the transport scheme | [
"Set",
"defines",
"the",
"proxy",
"servers",
"to",
"be",
"used",
"based",
"on",
"the",
"transport",
"scheme"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/proxy/proxy.go#L11-L33 |
13,243 | h2non/gentleman | client.go | Request | func (c *Client) Request() *Request {
req := NewRequest()
req.SetClient(c)
return req
} | go | func (c *Client) Request() *Request {
req := NewRequest()
req.SetClient(c)
return req
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Request",
"(",
")",
"*",
"Request",
"{",
"req",
":=",
"NewRequest",
"(",
")",
"\n",
"req",
".",
"SetClient",
"(",
"c",
")",
"\n",
"return",
"req",
"\n",
"}"
]
| // Request creates a new Request based on the current Client | [
"Request",
"creates",
"a",
"new",
"Request",
"based",
"on",
"the",
"current",
"Client"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L46-L50 |
13,244 | h2non/gentleman | client.go | Get | func (c *Client) Get() *Request {
req := c.Request()
req.Method("GET")
return req
} | go | func (c *Client) Get() *Request {
req := c.Request()
req.Method("GET")
return req
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Get",
"(",
")",
"*",
"Request",
"{",
"req",
":=",
"c",
".",
"Request",
"(",
")",
"\n",
"req",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"req",
"\n",
"}"
]
| // Get creates a new GET request. | [
"Get",
"creates",
"a",
"new",
"GET",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L53-L57 |
13,245 | h2non/gentleman | client.go | Post | func (c *Client) Post() *Request {
req := c.Request()
req.Method("POST")
return req
} | go | func (c *Client) Post() *Request {
req := c.Request()
req.Method("POST")
return req
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Post",
"(",
")",
"*",
"Request",
"{",
"req",
":=",
"c",
".",
"Request",
"(",
")",
"\n",
"req",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"req",
"\n",
"}"
]
| // Post creates a new POST request. | [
"Post",
"creates",
"a",
"new",
"POST",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L60-L64 |
13,246 | h2non/gentleman | client.go | Put | func (c *Client) Put() *Request {
req := c.Request()
req.Method("PUT")
return req
} | go | func (c *Client) Put() *Request {
req := c.Request()
req.Method("PUT")
return req
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Put",
"(",
")",
"*",
"Request",
"{",
"req",
":=",
"c",
".",
"Request",
"(",
")",
"\n",
"req",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"req",
"\n",
"}"
]
| // Put creates a new PUT request. | [
"Put",
"creates",
"a",
"new",
"PUT",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L67-L71 |
13,247 | h2non/gentleman | client.go | Delete | func (c *Client) Delete() *Request {
req := c.Request()
req.Method("DELETE")
return req
} | go | func (c *Client) Delete() *Request {
req := c.Request()
req.Method("DELETE")
return req
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Delete",
"(",
")",
"*",
"Request",
"{",
"req",
":=",
"c",
".",
"Request",
"(",
")",
"\n",
"req",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"req",
"\n",
"}"
]
| // Delete creates a new DELETE request. | [
"Delete",
"creates",
"a",
"new",
"DELETE",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L74-L78 |
13,248 | h2non/gentleman | client.go | Patch | func (c *Client) Patch() *Request {
req := c.Request()
req.Method("PATCH")
return req
} | go | func (c *Client) Patch() *Request {
req := c.Request()
req.Method("PATCH")
return req
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Patch",
"(",
")",
"*",
"Request",
"{",
"req",
":=",
"c",
".",
"Request",
"(",
")",
"\n",
"req",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"req",
"\n",
"}"
]
| // Patch creates a new PATCH request. | [
"Patch",
"creates",
"a",
"new",
"PATCH",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L81-L85 |
13,249 | h2non/gentleman | client.go | Head | func (c *Client) Head() *Request {
req := c.Request()
req.Method("HEAD")
return req
} | go | func (c *Client) Head() *Request {
req := c.Request()
req.Method("HEAD")
return req
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Head",
"(",
")",
"*",
"Request",
"{",
"req",
":=",
"c",
".",
"Request",
"(",
")",
"\n",
"req",
".",
"Method",
"(",
"\"",
"\"",
")",
"\n",
"return",
"req",
"\n",
"}"
]
| // Head creates a new HEAD request. | [
"Head",
"creates",
"a",
"new",
"HEAD",
"request",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L88-L92 |
13,250 | h2non/gentleman | client.go | Method | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Method",
"(",
"name",
"string",
")",
"*",
"Client",
"{",
"c",
".",
"Middleware",
".",
"UseRequest",
"(",
"func",
"(",
"ctx",
"*",
"context",
".",
"Context",
",",
"h",
"context",
".",
"Handler",
")",
"{",
"ctx",
".",
"Request",
".",
"Method",
"=",
"name",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // Method defines a the default HTTP method used by outgoing client requests. | [
"Method",
"defines",
"a",
"the",
"default",
"HTTP",
"method",
"used",
"by",
"outgoing",
"client",
"requests",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L95-L101 |
13,251 | h2non/gentleman | client.go | URL | func (c *Client) URL(uri string) *Client {
c.Use(url.URL(uri))
return c
} | go | func (c *Client) URL(uri string) *Client {
c.Use(url.URL(uri))
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"URL",
"(",
"uri",
"string",
")",
"*",
"Client",
"{",
"c",
".",
"Use",
"(",
"url",
".",
"URL",
"(",
"uri",
")",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // URL defines the URL for client requests.
// Useful to define at client level the base URL and base path used by child requests. | [
"URL",
"defines",
"the",
"URL",
"for",
"client",
"requests",
".",
"Useful",
"to",
"define",
"at",
"client",
"level",
"the",
"base",
"URL",
"and",
"base",
"path",
"used",
"by",
"child",
"requests",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L105-L108 |
13,252 | h2non/gentleman | client.go | BaseURL | func (c *Client) BaseURL(uri string) *Client {
c.Use(url.BaseURL(uri))
return c
} | go | func (c *Client) BaseURL(uri string) *Client {
c.Use(url.BaseURL(uri))
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"BaseURL",
"(",
"uri",
"string",
")",
"*",
"Client",
"{",
"c",
".",
"Use",
"(",
"url",
".",
"BaseURL",
"(",
"uri",
")",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // BaseURL defines the URL schema and host for client requests.
// Useful to define at client level the base URL used by client child requests. | [
"BaseURL",
"defines",
"the",
"URL",
"schema",
"and",
"host",
"for",
"client",
"requests",
".",
"Useful",
"to",
"define",
"at",
"client",
"level",
"the",
"base",
"URL",
"used",
"by",
"client",
"child",
"requests",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L112-L115 |
13,253 | h2non/gentleman | client.go | Path | func (c *Client) Path(path string) *Client {
c.Use(url.Path(path))
return c
} | go | func (c *Client) Path(path string) *Client {
c.Use(url.Path(path))
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Path",
"(",
"path",
"string",
")",
"*",
"Client",
"{",
"c",
".",
"Use",
"(",
"url",
".",
"Path",
"(",
"path",
")",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // Path defines the URL base path for client requests. | [
"Path",
"defines",
"the",
"URL",
"base",
"path",
"for",
"client",
"requests",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L118-L121 |
13,254 | h2non/gentleman | client.go | Use | func (c *Client) Use(p plugin.Plugin) *Client {
c.Middleware.Use(p)
return c
} | go | func (c *Client) Use(p plugin.Plugin) *Client {
c.Middleware.Use(p)
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Use",
"(",
"p",
"plugin",
".",
"Plugin",
")",
"*",
"Client",
"{",
"c",
".",
"Middleware",
".",
"Use",
"(",
"p",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // Use uses a new plugin to the middleware stack. | [
"Use",
"uses",
"a",
"new",
"plugin",
"to",
"the",
"middleware",
"stack",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L176-L179 |
13,255 | h2non/gentleman | client.go | UseRequest | func (c *Client) UseRequest(fn context.HandlerFunc) *Client {
c.Middleware.UseRequest(fn)
return c
} | go | func (c *Client) UseRequest(fn context.HandlerFunc) *Client {
c.Middleware.UseRequest(fn)
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UseRequest",
"(",
"fn",
"context",
".",
"HandlerFunc",
")",
"*",
"Client",
"{",
"c",
".",
"Middleware",
".",
"UseRequest",
"(",
"fn",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // UseRequest uses a new middleware function for request phase. | [
"UseRequest",
"uses",
"a",
"new",
"middleware",
"function",
"for",
"request",
"phase",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L182-L185 |
13,256 | h2non/gentleman | client.go | UseResponse | func (c *Client) UseResponse(fn context.HandlerFunc) *Client {
c.Middleware.UseResponse(fn)
return c
} | go | func (c *Client) UseResponse(fn context.HandlerFunc) *Client {
c.Middleware.UseResponse(fn)
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UseResponse",
"(",
"fn",
"context",
".",
"HandlerFunc",
")",
"*",
"Client",
"{",
"c",
".",
"Middleware",
".",
"UseResponse",
"(",
"fn",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // UseResponse uses a new middleware function for response phase. | [
"UseResponse",
"uses",
"a",
"new",
"middleware",
"function",
"for",
"response",
"phase",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L188-L191 |
13,257 | h2non/gentleman | client.go | UseError | func (c *Client) UseError(fn context.HandlerFunc) *Client {
c.Middleware.UseError(fn)
return c
} | go | func (c *Client) UseError(fn context.HandlerFunc) *Client {
c.Middleware.UseError(fn)
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UseError",
"(",
"fn",
"context",
".",
"HandlerFunc",
")",
"*",
"Client",
"{",
"c",
".",
"Middleware",
".",
"UseError",
"(",
"fn",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // UseError uses a new middleware function for error phase. | [
"UseError",
"uses",
"a",
"new",
"middleware",
"function",
"for",
"error",
"phase",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L194-L197 |
13,258 | h2non/gentleman | client.go | UseHandler | func (c *Client) UseHandler(phase string, fn context.HandlerFunc) *Client {
c.Middleware.UseHandler(phase, fn)
return c
} | go | func (c *Client) UseHandler(phase string, fn context.HandlerFunc) *Client {
c.Middleware.UseHandler(phase, fn)
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UseHandler",
"(",
"phase",
"string",
",",
"fn",
"context",
".",
"HandlerFunc",
")",
"*",
"Client",
"{",
"c",
".",
"Middleware",
".",
"UseHandler",
"(",
"phase",
",",
"fn",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // UseHandler uses a new middleware function for the given phase. | [
"UseHandler",
"uses",
"a",
"new",
"middleware",
"function",
"for",
"the",
"given",
"phase",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L200-L203 |
13,259 | h2non/gentleman | client.go | UseParent | func (c *Client) UseParent(parent *Client) *Client {
c.Parent = parent
c.Context.UseParent(parent.Context)
c.Middleware.UseParent(parent.Middleware)
return c
} | go | func (c *Client) UseParent(parent *Client) *Client {
c.Parent = parent
c.Context.UseParent(parent.Context)
c.Middleware.UseParent(parent.Middleware)
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UseParent",
"(",
"parent",
"*",
"Client",
")",
"*",
"Client",
"{",
"c",
".",
"Parent",
"=",
"parent",
"\n",
"c",
".",
"Context",
".",
"UseParent",
"(",
"parent",
".",
"Context",
")",
"\n",
"c",
".",
"Middleware",
".",
"UseParent",
"(",
"parent",
".",
"Middleware",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // UseParent uses another Client as parent
// inheriting its middleware stack and configuration. | [
"UseParent",
"uses",
"another",
"Client",
"as",
"parent",
"inheriting",
"its",
"middleware",
"stack",
"and",
"configuration",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/client.go#L207-L212 |
13,260 | h2non/gentleman | plugins/multipart/multipart.go | File | 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 | 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)
})
} | [
"func",
"File",
"(",
"name",
"string",
",",
"reader",
"io",
".",
"Reader",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"file",
":=",
"FormFile",
"{",
"name",
",",
"reader",
"}",
"\n",
"data",
":=",
"FormData",
"{",
"Files",
":",
"[",
"]",
"FormFile",
"{",
"file",
"}",
"}",
"\n",
"handle",
"(",
"ctx",
",",
"h",
",",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // File creates a new multipart form based on a unique file field
// from the given io.ReadCloser stream. | [
"File",
"creates",
"a",
"new",
"multipart",
"form",
"based",
"on",
"a",
"unique",
"file",
"field",
"from",
"the",
"given",
"io",
".",
"ReadCloser",
"stream",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/multipart/multipart.go#L36-L42 |
13,261 | h2non/gentleman | plugins/multipart/multipart.go | Files | 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 | func Files(files []FormFile) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
data := FormData{Files: files}
handle(ctx, h, data)
})
} | [
"func",
"Files",
"(",
"files",
"[",
"]",
"FormFile",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"data",
":=",
"FormData",
"{",
"Files",
":",
"files",
"}",
"\n",
"handle",
"(",
"ctx",
",",
"h",
",",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Files creates a multipart form based on files fields. | [
"Files",
"creates",
"a",
"multipart",
"form",
"based",
"on",
"files",
"fields",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/multipart/multipart.go#L45-L50 |
13,262 | h2non/gentleman | plugins/multipart/multipart.go | Data | func Data(data FormData) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
handle(ctx, h, data)
})
} | go | func Data(data FormData) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
handle(ctx, h, data)
})
} | [
"func",
"Data",
"(",
"data",
"FormData",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"handle",
"(",
"ctx",
",",
"h",
",",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Data creates custom form based on the given form data
// who can have files and string based fields. | [
"Data",
"creates",
"custom",
"form",
"based",
"on",
"the",
"given",
"form",
"data",
"who",
"can",
"have",
"files",
"and",
"string",
"based",
"fields",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/multipart/multipart.go#L62-L66 |
13,263 | h2non/gentleman | plugin/plugin.go | SetHandler | func (p *Layer) SetHandler(phase string, handler context.HandlerFunc) {
p.Handlers[phase] = handler
} | go | func (p *Layer) SetHandler(phase string, handler context.HandlerFunc) {
p.Handlers[phase] = handler
} | [
"func",
"(",
"p",
"*",
"Layer",
")",
"SetHandler",
"(",
"phase",
"string",
",",
"handler",
"context",
".",
"HandlerFunc",
")",
"{",
"p",
".",
"Handlers",
"[",
"phase",
"]",
"=",
"handler",
"\n",
"}"
]
| // SetHandler uses a new handler function for the given middleware phase. | [
"SetHandler",
"uses",
"a",
"new",
"handler",
"function",
"for",
"the",
"given",
"middleware",
"phase",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugin/plugin.go#L85-L87 |
13,264 | h2non/gentleman | plugin/plugin.go | Exec | 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 | 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)
} | [
"func",
"(",
"p",
"*",
"Layer",
")",
"Exec",
"(",
"phase",
"string",
",",
"ctx",
"*",
"context",
".",
"Context",
",",
"h",
"context",
".",
"Handler",
")",
"{",
"if",
"p",
".",
"disabled",
"||",
"p",
".",
"removed",
"{",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"fn",
":=",
"p",
".",
"Handlers",
"[",
"phase",
"]",
"\n",
"if",
"fn",
"==",
"nil",
"{",
"fn",
"=",
"p",
".",
"DefaultHandler",
"\n",
"}",
"\n",
"if",
"fn",
"==",
"nil",
"{",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"fn",
"(",
"ctx",
",",
"h",
")",
"\n",
"}"
]
| // Exec executes the plugin handler for the given middleware phase passing the given context. | [
"Exec",
"executes",
"the",
"plugin",
"handler",
"for",
"the",
"given",
"middleware",
"phase",
"passing",
"the",
"given",
"context",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugin/plugin.go#L95-L111 |
13,265 | h2non/gentleman | plugin/plugin.go | NewPhasePlugin | func NewPhasePlugin(phase string, handler context.HandlerFunc) Plugin {
return &Layer{Handlers: Handlers{phase: handler}}
} | go | func NewPhasePlugin(phase string, handler context.HandlerFunc) Plugin {
return &Layer{Handlers: Handlers{phase: handler}}
} | [
"func",
"NewPhasePlugin",
"(",
"phase",
"string",
",",
"handler",
"context",
".",
"HandlerFunc",
")",
"Plugin",
"{",
"return",
"&",
"Layer",
"{",
"Handlers",
":",
"Handlers",
"{",
"phase",
":",
"handler",
"}",
"}",
"\n",
"}"
]
| // NewPhasePlugin creates a new plugin layer
// to handle a given middleware phase. | [
"NewPhasePlugin",
"creates",
"a",
"new",
"plugin",
"layer",
"to",
"handle",
"a",
"given",
"middleware",
"phase",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugin/plugin.go#L115-L117 |
13,266 | h2non/gentleman | utils/utils.go | ReplyWithStatus | func ReplyWithStatus(res *http.Response, code int) {
res.StatusCode = code
res.Status = strconv.Itoa(code) + " " + http.StatusText(code)
} | go | func ReplyWithStatus(res *http.Response, code int) {
res.StatusCode = code
res.Status = strconv.Itoa(code) + " " + http.StatusText(code)
} | [
"func",
"ReplyWithStatus",
"(",
"res",
"*",
"http",
".",
"Response",
",",
"code",
"int",
")",
"{",
"res",
".",
"StatusCode",
"=",
"code",
"\n",
"res",
".",
"Status",
"=",
"strconv",
".",
"Itoa",
"(",
"code",
")",
"+",
"\"",
"\"",
"+",
"http",
".",
"StatusText",
"(",
"code",
")",
"\n",
"}"
]
| // ReplyWithStatus helper to write the http.Response status code and text. | [
"ReplyWithStatus",
"helper",
"to",
"write",
"the",
"http",
".",
"Response",
"status",
"code",
"and",
"text",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/utils/utils.go#L19-L22 |
13,267 | h2non/gentleman | utils/utils.go | WriteBodyString | func WriteBodyString(res *http.Response, body string) {
res.Body = StringReader(body)
res.ContentLength = int64(len(body))
} | go | func WriteBodyString(res *http.Response, body string) {
res.Body = StringReader(body)
res.ContentLength = int64(len(body))
} | [
"func",
"WriteBodyString",
"(",
"res",
"*",
"http",
".",
"Response",
",",
"body",
"string",
")",
"{",
"res",
".",
"Body",
"=",
"StringReader",
"(",
"body",
")",
"\n",
"res",
".",
"ContentLength",
"=",
"int64",
"(",
"len",
"(",
"body",
")",
")",
"\n",
"}"
]
| // WriteBodyString writes a string based body in a given http.Response. | [
"WriteBodyString",
"writes",
"a",
"string",
"based",
"body",
"in",
"a",
"given",
"http",
".",
"Response",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/utils/utils.go#L25-L28 |
13,268 | h2non/gentleman | utils/utils.go | StringReader | 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 | 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
} | [
"func",
"StringReader",
"(",
"body",
"string",
")",
"io",
".",
"ReadCloser",
"{",
"b",
":=",
"bytes",
".",
"NewReader",
"(",
"[",
"]",
"byte",
"(",
"body",
")",
")",
"\n\n",
"rc",
",",
"ok",
":=",
"io",
".",
"Reader",
"(",
"b",
")",
".",
"(",
"io",
".",
"ReadCloser",
")",
"\n",
"if",
"!",
"ok",
"&&",
"b",
"!=",
"nil",
"{",
"rc",
"=",
"ioutil",
".",
"NopCloser",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"return",
"rc",
"\n",
"}"
]
| // StringReader creates an io.ReadCloser interface from a string. | [
"StringReader",
"creates",
"an",
"io",
".",
"ReadCloser",
"interface",
"from",
"a",
"string",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/utils/utils.go#L31-L40 |
13,269 | h2non/gentleman | plugins/headers/headers.go | SetMap | 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 | 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)
})
} | [
"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",
")",
"\n",
"}",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // SetMap sets a map of headers represented by key-value pair. | [
"SetMap",
"sets",
"a",
"map",
"of",
"headers",
"represented",
"by",
"key",
"-",
"value",
"pair",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/headers/headers.go#L35-L42 |
13,270 | h2non/gentleman | plugins/bodytype/bodytype.go | Set | func Set(name string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
defineType(name, ctx.Request)
h.Next(ctx)
})
} | go | func Set(name string) p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
defineType(name, ctx.Request)
h.Next(ctx)
})
} | [
"func",
"Set",
"(",
"name",
"string",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"defineType",
"(",
"name",
",",
"ctx",
".",
"Request",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Set sets the Content Type header value, optionally based on a MIME type alias. | [
"Set",
"sets",
"the",
"Content",
"Type",
"header",
"value",
"optionally",
"based",
"on",
"a",
"MIME",
"type",
"alias",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/bodytype/bodytype.go#L21-L26 |
13,271 | h2non/gentleman | context/context.go | New | func New() *Context {
req := createRequest()
res := createResponse(req)
cli := &http.Client{Transport: http.DefaultTransport}
return &Context{Request: req, Response: res, Client: cli}
} | go | func New() *Context {
req := createRequest()
res := createResponse(req)
cli := &http.Client{Transport: http.DefaultTransport}
return &Context{Request: req, Response: res, Client: cli}
} | [
"func",
"New",
"(",
")",
"*",
"Context",
"{",
"req",
":=",
"createRequest",
"(",
")",
"\n",
"res",
":=",
"createResponse",
"(",
"req",
")",
"\n",
"cli",
":=",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"http",
".",
"DefaultTransport",
"}",
"\n",
"return",
"&",
"Context",
"{",
"Request",
":",
"req",
",",
"Response",
":",
"res",
",",
"Client",
":",
"cli",
"}",
"\n",
"}"
]
| // New creates an empty default Context | [
"New",
"creates",
"an",
"empty",
"default",
"Context"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L50-L55 |
13,272 | h2non/gentleman | context/context.go | getStore | func (c *Context) getStore() Store {
store, ok := c.Request.Context().Value(Key).(Store)
if !ok {
panic("invalid request context")
}
return store
} | go | func (c *Context) getStore() Store {
store, ok := c.Request.Context().Value(Key).(Store)
if !ok {
panic("invalid request context")
}
return store
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"getStore",
"(",
")",
"Store",
"{",
"store",
",",
"ok",
":=",
"c",
".",
"Request",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"Key",
")",
".",
"(",
"Store",
")",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"store",
"\n",
"}"
]
| // getStore retrieves the current request context data store. | [
"getStore",
"retrieves",
"the",
"current",
"request",
"context",
"data",
"store",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L58-L64 |
13,273 | h2non/gentleman | context/context.go | Set | func (c *Context) Set(key interface{}, value interface{}) {
store := c.getStore()
store[key] = value
} | go | func (c *Context) Set(key interface{}, value interface{}) {
store := c.getStore()
store[key] = value
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"Set",
"(",
"key",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"store",
":=",
"c",
".",
"getStore",
"(",
")",
"\n",
"store",
"[",
"key",
"]",
"=",
"value",
"\n",
"}"
]
| // Set sets a value on the current store | [
"Set",
"sets",
"a",
"value",
"on",
"the",
"current",
"store"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L67-L70 |
13,274 | h2non/gentleman | context/context.go | Get | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"Get",
"(",
"key",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"store",
":=",
"c",
".",
"getStore",
"(",
")",
"\n",
"if",
"store",
"==",
"nil",
"{",
"return",
"store",
"\n",
"}",
"\n",
"if",
"value",
",",
"ok",
":=",
"store",
"[",
"key",
"]",
";",
"ok",
"{",
"return",
"value",
"\n",
"}",
"\n",
"if",
"c",
".",
"Parent",
"!=",
"nil",
"{",
"return",
"c",
".",
"Parent",
".",
"Get",
"(",
"key",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Get gets a value by key in the current or parent context | [
"Get",
"gets",
"a",
"value",
"by",
"key",
"in",
"the",
"current",
"or",
"parent",
"context"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L73-L85 |
13,275 | h2non/gentleman | context/context.go | GetInt | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"GetInt",
"(",
"key",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"bool",
")",
"{",
"value",
",",
"ok",
":=",
"c",
".",
"GetOk",
"(",
"key",
")",
"\n",
"if",
"!",
"ok",
"{",
"if",
"c",
".",
"Parent",
"!=",
"nil",
"{",
"return",
"c",
".",
"Parent",
".",
"GetInt",
"(",
"key",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"num",
",",
"ok",
":=",
"value",
".",
"(",
"int",
")",
";",
"ok",
"{",
"return",
"num",
",",
"ok",
"\n",
"}",
"\n",
"return",
"0",
",",
"false",
"\n",
"}"
]
| // GetInt gets an int context value from req.
// Returns an empty string if key not found in the request context,
// or the value does not evaluate to a string | [
"GetInt",
"gets",
"an",
"int",
"context",
"value",
"from",
"req",
".",
"Returns",
"an",
"empty",
"string",
"if",
"key",
"not",
"found",
"in",
"the",
"request",
"context",
"or",
"the",
"value",
"does",
"not",
"evaluate",
"to",
"a",
"string"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L103-L114 |
13,276 | h2non/gentleman | context/context.go | GetString | 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 | 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 ""
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"GetString",
"(",
"key",
"interface",
"{",
"}",
")",
"string",
"{",
"store",
":=",
"c",
".",
"getStore",
"(",
")",
"\n",
"if",
"value",
",",
"ok",
":=",
"store",
"[",
"key",
"]",
";",
"ok",
"{",
"if",
"typed",
",",
"ok",
":=",
"value",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"typed",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"c",
".",
"Parent",
"!=",
"nil",
"{",
"return",
"c",
".",
"Parent",
".",
"GetString",
"(",
"key",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // GetString gets a string context value from req.
// Returns an empty string if key not found in the request context,
// or the value does not evaluate to a string | [
"GetString",
"gets",
"a",
"string",
"context",
"value",
"from",
"req",
".",
"Returns",
"an",
"empty",
"string",
"if",
"key",
"not",
"found",
"in",
"the",
"request",
"context",
"or",
"the",
"value",
"does",
"not",
"evaluate",
"to",
"a",
"string"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L119-L130 |
13,277 | h2non/gentleman | context/context.go | GetAll | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"GetAll",
"(",
")",
"Store",
"{",
"buf",
":=",
"Store",
"{",
"}",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"c",
".",
"getStore",
"(",
")",
"{",
"buf",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"if",
"c",
".",
"Parent",
"!=",
"nil",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"c",
".",
"Parent",
".",
"GetAll",
"(",
")",
"{",
"buf",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"buf",
"\n",
"}"
]
| // GetAll returns all stored context values for a request.
// Will always return a valid map. Returns an empty map for
// requests context data previously set | [
"GetAll",
"returns",
"all",
"stored",
"context",
"values",
"for",
"a",
"request",
".",
"Will",
"always",
"return",
"a",
"valid",
"map",
".",
"Returns",
"an",
"empty",
"map",
"for",
"requests",
"context",
"data",
"previously",
"set"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L135-L146 |
13,278 | h2non/gentleman | context/context.go | Root | func (c *Context) Root() *Context {
if c.Parent != nil {
return c.Parent.Root()
}
return c
} | go | func (c *Context) Root() *Context {
if c.Parent != nil {
return c.Parent.Root()
}
return c
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"Root",
"(",
")",
"*",
"Context",
"{",
"if",
"c",
".",
"Parent",
"!=",
"nil",
"{",
"return",
"c",
".",
"Parent",
".",
"Root",
"(",
")",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
]
| // Root returns the root Context looking in the parent contexts recursively.
// If the current context has no parent context, it will return the Context itself. | [
"Root",
"returns",
"the",
"root",
"Context",
"looking",
"in",
"the",
"parent",
"contexts",
"recursively",
".",
"If",
"the",
"current",
"context",
"has",
"no",
"parent",
"context",
"it",
"will",
"return",
"the",
"Context",
"itself",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L169-L174 |
13,279 | h2non/gentleman | context/context.go | SetRequest | func (c *Context) SetRequest(req *http.Request) {
c.Request = req.WithContext(c.Request.Context())
} | go | func (c *Context) SetRequest(req *http.Request) {
c.Request = req.WithContext(c.Request.Context())
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"SetRequest",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"c",
".",
"Request",
"=",
"req",
".",
"WithContext",
"(",
"c",
".",
"Request",
".",
"Context",
"(",
")",
")",
"\n",
"}"
]
| // SetRequest replaces the context http.Request | [
"SetRequest",
"replaces",
"the",
"context",
"http",
".",
"Request"
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L177-L179 |
13,280 | h2non/gentleman | context/context.go | Clone | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"Clone",
"(",
")",
"*",
"Context",
"{",
"ctx",
":=",
"new",
"(",
"Context",
")",
"\n",
"*",
"ctx",
"=",
"*",
"c",
"\n\n",
"req",
":=",
"new",
"(",
"http",
".",
"Request",
")",
"\n",
"*",
"req",
"=",
"*",
"c",
".",
"Request",
"\n",
"ctx",
".",
"Request",
"=",
"req",
"\n",
"c",
".",
"CopyTo",
"(",
"ctx",
")",
"\n\n",
"res",
":=",
"new",
"(",
"http",
".",
"Response",
")",
"\n",
"*",
"res",
"=",
"*",
"c",
".",
"Response",
"\n",
"ctx",
".",
"Response",
"=",
"res",
"\n\n",
"return",
"ctx",
"\n",
"}"
]
| // Clone returns a clone of the current context. | [
"Clone",
"returns",
"a",
"clone",
"of",
"the",
"current",
"context",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L182-L196 |
13,281 | h2non/gentleman | context/context.go | CopyTo | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"CopyTo",
"(",
"newCtx",
"*",
"Context",
")",
"{",
"store",
":=",
"Store",
"{",
"}",
"\n\n",
"for",
"key",
",",
"value",
":=",
"range",
"c",
".",
"getStore",
"(",
")",
"{",
"store",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n\n",
"ctx",
":=",
"context",
".",
"WithValue",
"(",
"context",
".",
"Background",
"(",
")",
",",
"Key",
",",
"store",
")",
"\n",
"newCtx",
".",
"Request",
"=",
"newCtx",
".",
"Request",
".",
"WithContext",
"(",
"ctx",
")",
"\n",
"}"
]
| // CopyTo copies the current context store into a new Context. | [
"CopyTo",
"copies",
"the",
"current",
"context",
"store",
"into",
"a",
"new",
"Context",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L199-L208 |
13,282 | h2non/gentleman | context/context.go | createRequest | 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 | 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())
} | [
"func",
"createRequest",
"(",
")",
"*",
"http",
".",
"Request",
"{",
"// Create HTTP request",
"req",
":=",
"&",
"http",
".",
"Request",
"{",
"Method",
":",
"\"",
"\"",
",",
"URL",
":",
"&",
"url",
".",
"URL",
"{",
"}",
",",
"Host",
":",
"\"",
"\"",
",",
"ProtoMajor",
":",
"1",
",",
"ProtoMinor",
":",
"1",
",",
"Proto",
":",
"\"",
"\"",
",",
"Header",
":",
"make",
"(",
"http",
".",
"Header",
")",
",",
"Body",
":",
"utils",
".",
"NopCloser",
"(",
")",
",",
"}",
"\n",
"// Return shallow copy of Request with the new context",
"return",
"req",
".",
"WithContext",
"(",
"emptyContext",
"(",
")",
")",
"\n",
"}"
]
| // createRequest creates a default http.Request instance. | [
"createRequest",
"creates",
"a",
"default",
"http",
".",
"Request",
"instance",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L313-L327 |
13,283 | h2non/gentleman | context/context.go | createResponse | 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 | 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(),
}
} | [
"func",
"createResponse",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"*",
"http",
".",
"Response",
"{",
"return",
"&",
"http",
".",
"Response",
"{",
"ProtoMajor",
":",
"1",
",",
"ProtoMinor",
":",
"1",
",",
"Proto",
":",
"\"",
"\"",
",",
"Request",
":",
"req",
",",
"Header",
":",
"make",
"(",
"http",
".",
"Header",
")",
",",
"Body",
":",
"utils",
".",
"NopCloser",
"(",
")",
",",
"}",
"\n",
"}"
]
| // createResponse creates a default http.Response instance. | [
"createResponse",
"creates",
"a",
"default",
"http",
".",
"Response",
"instance",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/context/context.go#L330-L339 |
13,284 | h2non/gentleman | plugins/query/query.go | Set | 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 | 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)
})
} | [
"func",
"Set",
"(",
"key",
",",
"value",
"string",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"query",
":=",
"ctx",
".",
"Request",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"query",
".",
"Set",
"(",
"key",
",",
"value",
")",
"\n",
"ctx",
".",
"Request",
".",
"URL",
".",
"RawQuery",
"=",
"query",
".",
"Encode",
"(",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // Set sets the query param key and value.
// It replaces any existing values. | [
"Set",
"sets",
"the",
"query",
"param",
"key",
"and",
"value",
".",
"It",
"replaces",
"any",
"existing",
"values",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/query/query.go#L10-L17 |
13,285 | h2non/gentleman | plugins/query/query.go | DelAll | func DelAll() p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Request.URL.RawQuery = ""
h.Next(ctx)
})
} | go | func DelAll() p.Plugin {
return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
ctx.Request.URL.RawQuery = ""
h.Next(ctx)
})
} | [
"func",
"DelAll",
"(",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"ctx",
".",
"Request",
".",
"URL",
".",
"RawQuery",
"=",
"\"",
"\"",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // DelAll deletes all the query params. | [
"DelAll",
"deletes",
"all",
"the",
"query",
"params",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/query/query.go#L41-L46 |
13,286 | h2non/gentleman | plugins/query/query.go | SetMap | 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 | 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)
})
} | [
"func",
"SetMap",
"(",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"p",
".",
"Plugin",
"{",
"return",
"p",
".",
"NewRequestPlugin",
"(",
"func",
"(",
"ctx",
"*",
"c",
".",
"Context",
",",
"h",
"c",
".",
"Handler",
")",
"{",
"query",
":=",
"ctx",
".",
"Request",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"params",
"{",
"query",
".",
"Set",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"ctx",
".",
"Request",
".",
"URL",
".",
"RawQuery",
"=",
"query",
".",
"Encode",
"(",
")",
"\n",
"h",
".",
"Next",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // SetMap sets a map of query params by key-value pair. | [
"SetMap",
"sets",
"a",
"map",
"of",
"query",
"params",
"by",
"key",
"-",
"value",
"pair",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/plugins/query/query.go#L49-L58 |
13,287 | h2non/gentleman | response.go | Close | func (r *Response) Close() error {
if r.Error != nil {
return r.Error
}
return r.RawResponse.Body.Close()
} | go | func (r *Response) Close() error {
if r.Error != nil {
return r.Error
}
return r.RawResponse.Body.Close()
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"r",
".",
"Error",
"\n",
"}",
"\n",
"return",
"r",
".",
"RawResponse",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"}"
]
| // Close is part of our ability to support io.ReadCloser if
// someone wants to make use of the raw body. | [
"Close",
"is",
"part",
"of",
"our",
"ability",
"to",
"support",
"io",
".",
"ReadCloser",
"if",
"someone",
"wants",
"to",
"make",
"use",
"of",
"the",
"raw",
"body",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/response.go#L88-L93 |
13,288 | h2non/gentleman | response.go | XML | 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 | 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
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"XML",
"(",
"userStruct",
"interface",
"{",
"}",
",",
"charsetReader",
"utils",
".",
"XMLCharDecoder",
")",
"error",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"r",
".",
"Error",
"\n",
"}",
"\n\n",
"xmlDecoder",
":=",
"xml",
".",
"NewDecoder",
"(",
"r",
".",
"getInternalReader",
"(",
")",
")",
"\n",
"if",
"charsetReader",
"!=",
"nil",
"{",
"xmlDecoder",
".",
"CharsetReader",
"=",
"charsetReader",
"\n",
"}",
"\n\n",
"defer",
"r",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"xmlDecoder",
".",
"Decode",
"(",
"&",
"userStruct",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"io",
".",
"EOF",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // XML is a method that will populate a struct that is provided
// `userStruct` with the XML returned within the response body. | [
"XML",
"is",
"a",
"method",
"that",
"will",
"populate",
"a",
"struct",
"that",
"is",
"provided",
"userStruct",
"with",
"the",
"XML",
"returned",
"within",
"the",
"response",
"body",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/response.go#L138-L154 |
13,289 | h2non/gentleman | response.go | Bytes | 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 | 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()
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Bytes",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"r",
".",
"populateResponseByteBuffer",
"(",
")",
"\n\n",
"// Are we still empty?",
"if",
"r",
".",
"buffer",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"r",
".",
"buffer",
".",
"Bytes",
"(",
")",
"\n",
"}"
]
| // Bytes returns the response as a byte array. | [
"Bytes",
"returns",
"the",
"response",
"as",
"a",
"byte",
"array",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/response.go#L157-L169 |
13,290 | h2non/gentleman | response.go | String | func (r *Response) String() string {
if r.Error != nil {
return ""
}
r.populateResponseByteBuffer()
return r.buffer.String()
} | go | func (r *Response) String() string {
if r.Error != nil {
return ""
}
r.populateResponseByteBuffer()
return r.buffer.String()
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"String",
"(",
")",
"string",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"r",
".",
"populateResponseByteBuffer",
"(",
")",
"\n",
"return",
"r",
".",
"buffer",
".",
"String",
"(",
")",
"\n",
"}"
]
| // String returns the response as a string. | [
"String",
"returns",
"the",
"response",
"as",
"a",
"string",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/response.go#L172-L179 |
13,291 | h2non/gentleman | response.go | isChunkedResponse | func isChunkedResponse(res *http.Response) bool {
for _, te := range res.TransferEncoding {
if te == "chunked" {
return true
}
}
return false
} | go | func isChunkedResponse(res *http.Response) bool {
for _, te := range res.TransferEncoding {
if te == "chunked" {
return true
}
}
return false
} | [
"func",
"isChunkedResponse",
"(",
"res",
"*",
"http",
".",
"Response",
")",
"bool",
"{",
"for",
"_",
",",
"te",
":=",
"range",
"res",
".",
"TransferEncoding",
"{",
"if",
"te",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
]
| // isChunkedResponse iterates over the response's transfer encodings
// and returns either true whether 'chunked' is found, or false, otherwise. | [
"isChunkedResponse",
"iterates",
"over",
"the",
"response",
"s",
"transfer",
"encodings",
"and",
"returns",
"either",
"true",
"whether",
"chunked",
"is",
"found",
"or",
"false",
"otherwise",
"."
]
| c4d45b509aa1d29d813abbb19203887071efe506 | https://github.com/h2non/gentleman/blob/c4d45b509aa1d29d813abbb19203887071efe506/response.go#L229-L236 |
13,292 | stripe/veneur | cmd/veneur-emit/main.go | sendSSF | 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 | 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
} | [
"func",
"sendSSF",
"(",
"client",
"*",
"trace",
".",
"Client",
",",
"span",
"*",
"ssf",
".",
"SSFSpan",
")",
"error",
"{",
"done",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"err",
":=",
"trace",
".",
"Record",
"(",
"client",
",",
"span",
",",
"done",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"<-",
"done",
"\n",
"}"
]
| // sendSSF sends a whole span to an SSF receiver. | [
"sendSSF",
"sends",
"a",
"whole",
"span",
"to",
"an",
"SSF",
"receiver",
"."
]
| 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/cmd/veneur-emit/main.go#L557-L564 |
13,293 | stripe/veneur | cmd/veneur-emit/main.go | sendStatsd | 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 | 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
} | [
"func",
"sendStatsd",
"(",
"addr",
"string",
",",
"span",
"*",
"ssf",
".",
"SSFSpan",
")",
"error",
"{",
"client",
",",
"err",
":=",
"statsd",
".",
"New",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Report all the metrics in the span:",
"for",
"_",
",",
"metric",
":=",
"range",
"span",
".",
"Metrics",
"{",
"tags",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"metric",
".",
"Tags",
")",
")",
"\n",
"for",
"name",
",",
"val",
":=",
"range",
"metric",
".",
"Tags",
"{",
"tags",
"=",
"append",
"(",
"tags",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
",",
"val",
")",
")",
"\n",
"}",
"\n",
"switch",
"metric",
".",
"Metric",
"{",
"case",
"ssf",
".",
"SSFSample_COUNTER",
":",
"err",
"=",
"client",
".",
"Count",
"(",
"metric",
".",
"Name",
",",
"int64",
"(",
"metric",
".",
"Value",
")",
",",
"tags",
",",
"1.0",
")",
"\n",
"case",
"ssf",
".",
"SSFSample_GAUGE",
":",
"err",
"=",
"client",
".",
"Gauge",
"(",
"metric",
".",
"Name",
",",
"float64",
"(",
"metric",
".",
"Value",
")",
",",
"tags",
",",
"1.0",
")",
"\n",
"case",
"ssf",
".",
"SSFSample_HISTOGRAM",
":",
"if",
"metric",
".",
"Unit",
"==",
"\"",
"\"",
"{",
"// 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",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"client",
".",
"Histogram",
"(",
"metric",
".",
"Name",
",",
"float64",
"(",
"metric",
".",
"Value",
")",
",",
"tags",
",",
"1.0",
")",
"\n",
"}",
"\n",
"case",
"ssf",
".",
"SSFSample_SET",
":",
"err",
"=",
"client",
".",
"Set",
"(",
"metric",
".",
"Name",
",",
"metric",
".",
"Message",
",",
"tags",
",",
"1.0",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // sendStatsd sends the metrics gathered in a span to a dogstatsd
// endpoint. | [
"sendStatsd",
"sends",
"the",
"metrics",
"gathered",
"in",
"a",
"span",
"to",
"a",
"dogstatsd",
"endpoint",
"."
]
| 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/cmd/veneur-emit/main.go#L568-L601 |
13,294 | stripe/veneur | plugins/s3/mock/s3.go | SetPutObject | func (m *MockS3Client) SetPutObject(f func(*s3.PutObjectInput) (*s3.PutObjectOutput, error)) {
m.putObject = f
} | go | func (m *MockS3Client) SetPutObject(f func(*s3.PutObjectInput) (*s3.PutObjectOutput, error)) {
m.putObject = f
} | [
"func",
"(",
"m",
"*",
"MockS3Client",
")",
"SetPutObject",
"(",
"f",
"func",
"(",
"*",
"s3",
".",
"PutObjectInput",
")",
"(",
"*",
"s3",
".",
"PutObjectOutput",
",",
"error",
")",
")",
"{",
"m",
".",
"putObject",
"=",
"f",
"\n",
"}"
]
| // SetPutObject sets the function that acts as the PutObject handler | [
"SetPutObject",
"sets",
"the",
"function",
"that",
"acts",
"as",
"the",
"PutObject",
"handler"
]
| 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/plugins/s3/mock/s3.go#L14-L16 |
13,295 | stripe/veneur | trace/backend.go | SendSync | 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 | 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
} | [
"func",
"(",
"ds",
"*",
"streamBackend",
")",
"SendSync",
"(",
"ctx",
"context",
".",
"Context",
",",
"span",
"*",
"ssf",
".",
"SSFSpan",
")",
"error",
"{",
"if",
"ds",
".",
"conn",
"==",
"nil",
"{",
"if",
"err",
":=",
"connect",
"(",
"ctx",
",",
"ds",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"protocol",
".",
"WriteSSF",
"(",
"ds",
".",
"output",
",",
"span",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"protocol",
".",
"IsFramingError",
"(",
"err",
")",
"{",
"_",
"=",
"ds",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"ds",
".",
"conn",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
]
| // SendSync on a streamBackend attempts to write the packet on the
// connection to the upstream veneur directly. If it encounters a
// protocol error, SendSync will return the original protocol error once
// the connection is re-established. | [
"SendSync",
"on",
"a",
"streamBackend",
"attempts",
"to",
"write",
"the",
"packet",
"on",
"the",
"connection",
"to",
"the",
"upstream",
"veneur",
"directly",
".",
"If",
"it",
"encounters",
"a",
"protocol",
"error",
"SendSync",
"will",
"return",
"the",
"original",
"protocol",
"error",
"once",
"the",
"connection",
"is",
"re",
"-",
"established",
"."
]
| 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/backend.go#L195-L209 |
13,296 | stripe/veneur | trace/backend.go | FlushSync | 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 | 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
} | [
"func",
"(",
"ds",
"*",
"streamBackend",
")",
"FlushSync",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"ds",
".",
"buffer",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"ds",
".",
"conn",
"==",
"nil",
"{",
"if",
"err",
":=",
"connect",
"(",
"ctx",
",",
"ds",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"err",
":=",
"ds",
".",
"buffer",
".",
"Flush",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// buffer is poisoned, and we have no idea if the",
"// connection is still valid. We better reconnect.",
"_",
"=",
"ds",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"ds",
".",
"conn",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
]
| // FlushSync on a streamBackend flushes the buffer if one exists. If the
// connection was disconnected prior to flushing, FlushSync re-establishes
// it and discards the buffer. | [
"FlushSync",
"on",
"a",
"streamBackend",
"flushes",
"the",
"buffer",
"if",
"one",
"exists",
".",
"If",
"the",
"connection",
"was",
"disconnected",
"prior",
"to",
"flushing",
"FlushSync",
"re",
"-",
"establishes",
"it",
"and",
"discards",
"the",
"buffer",
"."
]
| 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/backend.go#L221-L238 |
13,297 | stripe/veneur | handlers_global.go | handleImport | 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 | 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)
})
} | [
"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",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"span",
".",
"Add",
"(",
"ssf",
".",
"Count",
"(",
"\"",
"\"",
",",
"1",
",",
"nil",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// 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",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // handleImport generates the handler that responds to POST requests submitting
// metrics to the global veneur instance. | [
"handleImport",
"generates",
"the",
"handler",
"that",
"responds",
"to",
"POST",
"requests",
"submitting",
"metrics",
"to",
"the",
"global",
"veneur",
"instance",
"."
]
| 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/handlers_global.go#L60-L72 |
13,298 | stripe/veneur | handlers_global.go | nonEmpty | 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 | 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
} | [
"func",
"nonEmpty",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"trace",
".",
"Client",
",",
"jsonMetrics",
"[",
"]",
"samplers",
".",
"JSONMetric",
")",
"bool",
"{",
"span",
",",
"_",
":=",
"trace",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"span",
".",
"ClientFinish",
"(",
"client",
")",
"\n\n",
"sentinel",
":=",
"samplers",
".",
"JSONMetric",
"{",
"}",
"\n",
"for",
"_",
",",
"metric",
":=",
"range",
"jsonMetrics",
"{",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"sentinel",
",",
"metric",
")",
"{",
"// we have found at least one entry that is properly formed",
"return",
"true",
"\n\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
]
| // nonEmpty returns true if there is at least one non-empty
// metric | [
"nonEmpty",
"returns",
"true",
"if",
"there",
"is",
"at",
"least",
"one",
"non",
"-",
"empty",
"metric"
]
| 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/handlers_global.go#L200-L214 |
13,299 | stripe/veneur | samplers/samplers.go | RouteTo | func (ri RouteInformation) RouteTo(name string) bool {
if ri == nil {
return true
}
_, ok := ri[name]
return ok
} | go | func (ri RouteInformation) RouteTo(name string) bool {
if ri == nil {
return true
}
_, ok := ri[name]
return ok
} | [
"func",
"(",
"ri",
"RouteInformation",
")",
"RouteTo",
"(",
"name",
"string",
")",
"bool",
"{",
"if",
"ri",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"_",
",",
"ok",
":=",
"ri",
"[",
"name",
"]",
"\n",
"return",
"ok",
"\n",
"}"
]
| // RouteTo returns true if the named sink should receive a metric
// according to the route table. A nil route table causes any sink to
// be eligible for the metric. | [
"RouteTo",
"returns",
"true",
"if",
"the",
"named",
"sink",
"should",
"receive",
"a",
"metric",
"according",
"to",
"the",
"route",
"table",
".",
"A",
"nil",
"route",
"table",
"causes",
"any",
"sink",
"to",
"be",
"eligible",
"for",
"the",
"metric",
"."
]
| 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L38-L44 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.