id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
27,600 | btcsuite/btcutil | txsort/txsort.go | Sort | func Sort(tx *wire.MsgTx) *wire.MsgTx {
txCopy := tx.Copy()
sort.Sort(sortableInputSlice(txCopy.TxIn))
sort.Sort(sortableOutputSlice(txCopy.TxOut))
return txCopy
} | go | func Sort(tx *wire.MsgTx) *wire.MsgTx {
txCopy := tx.Copy()
sort.Sort(sortableInputSlice(txCopy.TxIn))
sort.Sort(sortableOutputSlice(txCopy.TxOut))
return txCopy
} | [
"func",
"Sort",
"(",
"tx",
"*",
"wire",
".",
"MsgTx",
")",
"*",
"wire",
".",
"MsgTx",
"{",
"txCopy",
":=",
"tx",
".",
"Copy",
"(",
")",
"\n",
"sort",
".",
"Sort",
"(",
"sortableInputSlice",
"(",
"txCopy",
".",
"TxIn",
")",
")",
"\n",
"sort",
".",... | // Sort returns a new transaction with the inputs and outputs sorted based on
// BIP 69. The passed transaction is not modified and the new transaction
// might have a different hash if any sorting was done. | [
"Sort",
"returns",
"a",
"new",
"transaction",
"with",
"the",
"inputs",
"and",
"outputs",
"sorted",
"based",
"on",
"BIP",
"69",
".",
"The",
"passed",
"transaction",
"is",
"not",
"modified",
"and",
"the",
"new",
"transaction",
"might",
"have",
"a",
"different"... | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/txsort/txsort.go#L38-L43 |
27,601 | btcsuite/btcutil | txsort/txsort.go | IsSorted | func IsSorted(tx *wire.MsgTx) bool {
if !sort.IsSorted(sortableInputSlice(tx.TxIn)) {
return false
}
if !sort.IsSorted(sortableOutputSlice(tx.TxOut)) {
return false
}
return true
} | go | func IsSorted(tx *wire.MsgTx) bool {
if !sort.IsSorted(sortableInputSlice(tx.TxIn)) {
return false
}
if !sort.IsSorted(sortableOutputSlice(tx.TxOut)) {
return false
}
return true
} | [
"func",
"IsSorted",
"(",
"tx",
"*",
"wire",
".",
"MsgTx",
")",
"bool",
"{",
"if",
"!",
"sort",
".",
"IsSorted",
"(",
"sortableInputSlice",
"(",
"tx",
".",
"TxIn",
")",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"sort",
".",
"IsSorted"... | // IsSorted checks whether tx has inputs and outputs sorted according to BIP
// 69. | [
"IsSorted",
"checks",
"whether",
"tx",
"has",
"inputs",
"and",
"outputs",
"sorted",
"according",
"to",
"BIP",
"69",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/txsort/txsort.go#L47-L55 |
27,602 | logpacker/PayPal-Go-SDK | types.go | MarshalJSON | func (t JSONTime) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
return []byte(stamp), nil
} | go | func (t JSONTime) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
return []byte(stamp), nil
} | [
"func",
"(",
"t",
"JSONTime",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"stamp",
":=",
"fmt",
".",
"Sprintf",
"(",
"`\"%s\"`",
",",
"time",
".",
"Time",
"(",
"t",
")",
".",
"UTC",
"(",
")",
".",
"Format",
"(",... | // MarshalJSON for JSONTime | [
"MarshalJSON",
"for",
"JSONTime"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/types.go#L607-L610 |
27,603 | logpacker/PayPal-Go-SDK | client.go | NewClient | func NewClient(clientID string, secret string, APIBase string) (*Client, error) {
if clientID == "" || secret == "" || APIBase == "" {
return nil, errors.New("ClientID, Secret and APIBase are required to create a Client")
}
return &Client{
Client: &http.Client{},
ClientID: clientID,
Secret: secret,
AP... | go | func NewClient(clientID string, secret string, APIBase string) (*Client, error) {
if clientID == "" || secret == "" || APIBase == "" {
return nil, errors.New("ClientID, Secret and APIBase are required to create a Client")
}
return &Client{
Client: &http.Client{},
ClientID: clientID,
Secret: secret,
AP... | [
"func",
"NewClient",
"(",
"clientID",
"string",
",",
"secret",
"string",
",",
"APIBase",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"clientID",
"==",
"\"",
"\"",
"||",
"secret",
"==",
"\"",
"\"",
"||",
"APIBase",
"==",
"\"",
"\"... | // NewClient returns new Client struct
// APIBase is a base API URL, for testing you can use paypalsdk.APIBaseSandBox | [
"NewClient",
"returns",
"new",
"Client",
"struct",
"APIBase",
"is",
"a",
"base",
"API",
"URL",
"for",
"testing",
"you",
"can",
"use",
"paypalsdk",
".",
"APIBaseSandBox"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L17-L28 |
27,604 | logpacker/PayPal-Go-SDK | client.go | SetAccessToken | func (c *Client) SetAccessToken(token string) {
c.Token = &TokenResponse{
Token: token,
}
c.tokenExpiresAt = time.Time{}
} | go | func (c *Client) SetAccessToken(token string) {
c.Token = &TokenResponse{
Token: token,
}
c.tokenExpiresAt = time.Time{}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetAccessToken",
"(",
"token",
"string",
")",
"{",
"c",
".",
"Token",
"=",
"&",
"TokenResponse",
"{",
"Token",
":",
"token",
",",
"}",
"\n",
"c",
".",
"tokenExpiresAt",
"=",
"time",
".",
"Time",
"{",
"}",
"\n"... | // SetAccessToken sets saved token to current client | [
"SetAccessToken",
"sets",
"saved",
"token",
"to",
"current",
"client"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L60-L65 |
27,605 | logpacker/PayPal-Go-SDK | client.go | Send | func (c *Client) Send(req *http.Request, v interface{}) error {
var (
err error
resp *http.Response
data []byte
)
// Set default headers
req.Header.Set("Accept", "application/json")
req.Header.Set("Accept-Language", "en_US")
// Default values for headers
if req.Header.Get("Content-type") == "" {
req.H... | go | func (c *Client) Send(req *http.Request, v interface{}) error {
var (
err error
resp *http.Response
data []byte
)
// Set default headers
req.Header.Set("Accept", "application/json")
req.Header.Set("Accept-Language", "en_US")
// Default values for headers
if req.Header.Get("Content-type") == "" {
req.H... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Send",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"(",
"err",
"error",
"\n",
"resp",
"*",
"http",
".",
"Response",
"\n",
"data",
"[",
"]",
"byte",
"... | // Send makes a request to the API, the response body will be
// unmarshaled into v, or if v is an io.Writer, the response will
// be written to it without decoding | [
"Send",
"makes",
"a",
"request",
"to",
"the",
"API",
"the",
"response",
"body",
"will",
"be",
"unmarshaled",
"into",
"v",
"or",
"if",
"v",
"is",
"an",
"io",
".",
"Writer",
"the",
"response",
"will",
"be",
"written",
"to",
"it",
"without",
"decoding"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L76-L121 |
27,606 | logpacker/PayPal-Go-SDK | client.go | SendWithAuth | func (c *Client) SendWithAuth(req *http.Request, v interface{}) error {
c.Lock()
// Note: Here we do not want to `defer c.Unlock()` because we need `c.Send(...)`
// to happen outside of the locked section.
if c.Token != nil {
if !c.tokenExpiresAt.IsZero() && c.tokenExpiresAt.Sub(time.Now()) < RequestNewTokenBefo... | go | func (c *Client) SendWithAuth(req *http.Request, v interface{}) error {
c.Lock()
// Note: Here we do not want to `defer c.Unlock()` because we need `c.Send(...)`
// to happen outside of the locked section.
if c.Token != nil {
if !c.tokenExpiresAt.IsZero() && c.tokenExpiresAt.Sub(time.Now()) < RequestNewTokenBefo... | [
"func",
"(",
"c",
"*",
"Client",
")",
"SendWithAuth",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"// Note: Here we do not want to `defer c.Unlock()` because we need `c.Send(...)`... | // SendWithAuth makes a request to the API and apply OAuth2 header automatically.
// If the access token soon to be expired or already expired, it will try to get a new one before
// making the main request
// client.Token will be updated when changed | [
"SendWithAuth",
"makes",
"a",
"request",
"to",
"the",
"API",
"and",
"apply",
"OAuth2",
"header",
"automatically",
".",
"If",
"the",
"access",
"token",
"soon",
"to",
"be",
"expired",
"or",
"already",
"expired",
"it",
"will",
"try",
"to",
"get",
"a",
"new",
... | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L127-L148 |
27,607 | logpacker/PayPal-Go-SDK | client.go | NewRequest | func (c *Client) NewRequest(method, url string, payload interface{}) (*http.Request, error) {
var buf io.Reader
if payload != nil {
var b []byte
b, err := json.Marshal(&payload)
if err != nil {
return nil, err
}
buf = bytes.NewBuffer(b)
}
return http.NewRequest(method, url, buf)
} | go | func (c *Client) NewRequest(method, url string, payload interface{}) (*http.Request, error) {
var buf io.Reader
if payload != nil {
var b []byte
b, err := json.Marshal(&payload)
if err != nil {
return nil, err
}
buf = bytes.NewBuffer(b)
}
return http.NewRequest(method, url, buf)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"NewRequest",
"(",
"method",
",",
"url",
"string",
",",
"payload",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"var",
"buf",
"io",
".",
"Reader",
"\n",
"if",
"payload",... | // NewRequest constructs a request
// Convert payload to a JSON | [
"NewRequest",
"constructs",
"a",
"request",
"Convert",
"payload",
"to",
"a",
"JSON"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L159-L170 |
27,608 | logpacker/PayPal-Go-SDK | client.go | log | func (c *Client) log(r *http.Request, resp *http.Response) {
if c.Log != nil {
var (
reqDump string
respDump []byte
)
if r != nil {
reqDump = fmt.Sprintf("%s %s. Data: %s", r.Method, r.URL.String(), r.Form.Encode())
}
if resp != nil {
respDump, _ = httputil.DumpResponse(resp, true)
}
c.Log... | go | func (c *Client) log(r *http.Request, resp *http.Response) {
if c.Log != nil {
var (
reqDump string
respDump []byte
)
if r != nil {
reqDump = fmt.Sprintf("%s %s. Data: %s", r.Method, r.URL.String(), r.Form.Encode())
}
if resp != nil {
respDump, _ = httputil.DumpResponse(resp, true)
}
c.Log... | [
"func",
"(",
"c",
"*",
"Client",
")",
"log",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"resp",
"*",
"http",
".",
"Response",
")",
"{",
"if",
"c",
".",
"Log",
"!=",
"nil",
"{",
"var",
"(",
"reqDump",
"string",
"\n",
"respDump",
"[",
"]",
"byte... | // log will dump request and response to the log file | [
"log",
"will",
"dump",
"request",
"and",
"response",
"to",
"the",
"log",
"file"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L173-L189 |
27,609 | didip/tollbooth | libstring/libstring.go | StringInSlice | func StringInSlice(sliceString []string, needle string) bool {
for _, b := range sliceString {
if b == needle {
return true
}
}
return false
} | go | func StringInSlice(sliceString []string, needle string) bool {
for _, b := range sliceString {
if b == needle {
return true
}
}
return false
} | [
"func",
"StringInSlice",
"(",
"sliceString",
"[",
"]",
"string",
",",
"needle",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"b",
":=",
"range",
"sliceString",
"{",
"if",
"b",
"==",
"needle",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return... | // StringInSlice finds needle in a slice of strings. | [
"StringInSlice",
"finds",
"needle",
"in",
"a",
"slice",
"of",
"strings",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/libstring/libstring.go#L11-L18 |
27,610 | didip/tollbooth | tollbooth.go | setResponseHeaders | func setResponseHeaders(lmt *limiter.Limiter, w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Rate-Limit-Limit", fmt.Sprintf("%.2f", lmt.GetMax()))
w.Header().Add("X-Rate-Limit-Duration", "1")
w.Header().Add("X-Rate-Limit-Request-Forwarded-For", r.Header.Get("X-Forwarded-For"))
w.Header().Add("X-Rate-Li... | go | func setResponseHeaders(lmt *limiter.Limiter, w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Rate-Limit-Limit", fmt.Sprintf("%.2f", lmt.GetMax()))
w.Header().Add("X-Rate-Limit-Duration", "1")
w.Header().Add("X-Rate-Limit-Request-Forwarded-For", r.Header.Get("X-Forwarded-For"))
w.Header().Add("X-Rate-Li... | [
"func",
"setResponseHeaders",
"(",
"lmt",
"*",
"limiter",
".",
"Limiter",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Add",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf... | // setResponseHeaders configures X-Rate-Limit-Limit and X-Rate-Limit-Duration | [
"setResponseHeaders",
"configures",
"X",
"-",
"Rate",
"-",
"Limit",
"-",
"Limit",
"and",
"X",
"-",
"Rate",
"-",
"Limit",
"-",
"Duration"
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/tollbooth.go#L16-L21 |
27,611 | didip/tollbooth | tollbooth.go | NewLimiter | func NewLimiter(max float64, tbOptions *limiter.ExpirableOptions) *limiter.Limiter {
return limiter.New(tbOptions).SetMax(max).SetBurst(int(math.Max(1, max)))
} | go | func NewLimiter(max float64, tbOptions *limiter.ExpirableOptions) *limiter.Limiter {
return limiter.New(tbOptions).SetMax(max).SetBurst(int(math.Max(1, max)))
} | [
"func",
"NewLimiter",
"(",
"max",
"float64",
",",
"tbOptions",
"*",
"limiter",
".",
"ExpirableOptions",
")",
"*",
"limiter",
".",
"Limiter",
"{",
"return",
"limiter",
".",
"New",
"(",
"tbOptions",
")",
".",
"SetMax",
"(",
"max",
")",
".",
"SetBurst",
"("... | // NewLimiter is a convenience function to limiter.New. | [
"NewLimiter",
"is",
"a",
"convenience",
"function",
"to",
"limiter",
".",
"New",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/tollbooth.go#L24-L26 |
27,612 | didip/tollbooth | tollbooth.go | LimitHandler | func LimitHandler(lmt *limiter.Limiter, next http.Handler) http.Handler {
middle := func(w http.ResponseWriter, r *http.Request) {
httpError := LimitByRequest(lmt, w, r)
if httpError != nil {
lmt.ExecOnLimitReached(w, r)
w.Header().Add("Content-Type", lmt.GetMessageContentType())
w.WriteHeader(httpError.S... | go | func LimitHandler(lmt *limiter.Limiter, next http.Handler) http.Handler {
middle := func(w http.ResponseWriter, r *http.Request) {
httpError := LimitByRequest(lmt, w, r)
if httpError != nil {
lmt.ExecOnLimitReached(w, r)
w.Header().Add("Content-Type", lmt.GetMessageContentType())
w.WriteHeader(httpError.S... | [
"func",
"LimitHandler",
"(",
"lmt",
"*",
"limiter",
".",
"Limiter",
",",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"middle",
":=",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{... | // LimitHandler is a middleware that performs rate-limiting given http.Handler struct. | [
"LimitHandler",
"is",
"a",
"middleware",
"that",
"performs",
"rate",
"-",
"limiting",
"given",
"http",
".",
"Handler",
"struct",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/tollbooth.go#L159-L175 |
27,613 | didip/tollbooth | tollbooth.go | LimitFuncHandler | func LimitFuncHandler(lmt *limiter.Limiter, nextFunc func(http.ResponseWriter, *http.Request)) http.Handler {
return LimitHandler(lmt, http.HandlerFunc(nextFunc))
} | go | func LimitFuncHandler(lmt *limiter.Limiter, nextFunc func(http.ResponseWriter, *http.Request)) http.Handler {
return LimitHandler(lmt, http.HandlerFunc(nextFunc))
} | [
"func",
"LimitFuncHandler",
"(",
"lmt",
"*",
"limiter",
".",
"Limiter",
",",
"nextFunc",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
")",
"http",
".",
"Handler",
"{",
"return",
"LimitHandler",
"(",
"lmt",
",",
"http... | // LimitFuncHandler is a middleware that performs rate-limiting given request handler function. | [
"LimitFuncHandler",
"is",
"a",
"middleware",
"that",
"performs",
"rate",
"-",
"limiting",
"given",
"request",
"handler",
"function",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/tollbooth.go#L178-L180 |
27,614 | didip/tollbooth | errors/errors.go | Error | func (httperror *HTTPError) Error() string {
return fmt.Sprintf("%v: %v", httperror.StatusCode, httperror.Message)
} | go | func (httperror *HTTPError) Error() string {
return fmt.Sprintf("%v: %v", httperror.StatusCode, httperror.Message)
} | [
"func",
"(",
"httperror",
"*",
"HTTPError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"httperror",
".",
"StatusCode",
",",
"httperror",
".",
"Message",
")",
"\n",
"}"
] | // Error returns error message. | [
"Error",
"returns",
"error",
"message",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/errors/errors.go#L13-L15 |
27,615 | didip/tollbooth | limiter/limiter.go | New | func New(generalExpirableOptions *ExpirableOptions) *Limiter {
lmt := &Limiter{}
lmt.SetMessageContentType("text/plain; charset=utf-8").
SetMessage("You have reached maximum request limit.").
SetStatusCode(429).
SetOnLimitReached(nil).
SetIPLookups([]string{"RemoteAddr", "X-Forwarded-For", "X-Real-IP"}).
S... | go | func New(generalExpirableOptions *ExpirableOptions) *Limiter {
lmt := &Limiter{}
lmt.SetMessageContentType("text/plain; charset=utf-8").
SetMessage("You have reached maximum request limit.").
SetStatusCode(429).
SetOnLimitReached(nil).
SetIPLookups([]string{"RemoteAddr", "X-Forwarded-For", "X-Real-IP"}).
S... | [
"func",
"New",
"(",
"generalExpirableOptions",
"*",
"ExpirableOptions",
")",
"*",
"Limiter",
"{",
"lmt",
":=",
"&",
"Limiter",
"{",
"}",
"\n\n",
"lmt",
".",
"SetMessageContentType",
"(",
"\"",
"\"",
")",
".",
"SetMessage",
"(",
"\"",
"\"",
")",
".",
"Set... | // New is a constructor for Limiter. | [
"New",
"is",
"a",
"constructor",
"for",
"Limiter",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L14-L52 |
27,616 | didip/tollbooth | limiter/limiter.go | SetTokenBucketExpirationTTL | func (l *Limiter) SetTokenBucketExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.tokenBucketExpirationTTL = ttl
l.Unlock()
return l
} | go | func (l *Limiter) SetTokenBucketExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.tokenBucketExpirationTTL = ttl
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetTokenBucketExpirationTTL",
"(",
"ttl",
"time",
".",
"Duration",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"tokenBucketExpirationTTL",
"=",
"ttl",
"\n",
"l",
".",
"Unlock",
"(",
")",... | // SetTokenBucketExpirationTTL is thread-safe way of setting custom token bucket expiration TTL. | [
"SetTokenBucketExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"custom",
"token",
"bucket",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L106-L112 |
27,617 | didip/tollbooth | limiter/limiter.go | GetTokenBucketExpirationTTL | func (l *Limiter) GetTokenBucketExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.tokenBucketExpirationTTL
} | go | func (l *Limiter) GetTokenBucketExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.tokenBucketExpirationTTL
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetTokenBucketExpirationTTL",
"(",
")",
"time",
".",
"Duration",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"tokenBucketExpirationTTL",
"\n",
"}"
] | // GettokenBucketExpirationTTL is thread-safe way of getting custom token bucket expiration TTL. | [
"GettokenBucketExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"custom",
"token",
"bucket",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L115-L119 |
27,618 | didip/tollbooth | limiter/limiter.go | SetBasicAuthExpirationTTL | func (l *Limiter) SetBasicAuthExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.basicAuthExpirationTTL = ttl
l.Unlock()
return l
} | go | func (l *Limiter) SetBasicAuthExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.basicAuthExpirationTTL = ttl
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetBasicAuthExpirationTTL",
"(",
"ttl",
"time",
".",
"Duration",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"basicAuthExpirationTTL",
"=",
"ttl",
"\n",
"l",
".",
"Unlock",
"(",
")",
"... | // SetBasicAuthExpirationTTL is thread-safe way of setting custom basic auth expiration TTL. | [
"SetBasicAuthExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"custom",
"basic",
"auth",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L122-L128 |
27,619 | didip/tollbooth | limiter/limiter.go | GetBasicAuthExpirationTTL | func (l *Limiter) GetBasicAuthExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.basicAuthExpirationTTL
} | go | func (l *Limiter) GetBasicAuthExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.basicAuthExpirationTTL
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetBasicAuthExpirationTTL",
"(",
")",
"time",
".",
"Duration",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"basicAuthExpirationTTL",
"\n",
"}"
] | // GetBasicAuthExpirationTTL is thread-safe way of getting custom basic auth expiration TTL. | [
"GetBasicAuthExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"custom",
"basic",
"auth",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L131-L135 |
27,620 | didip/tollbooth | limiter/limiter.go | SetHeaderEntryExpirationTTL | func (l *Limiter) SetHeaderEntryExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.headerEntryExpirationTTL = ttl
l.Unlock()
return l
} | go | func (l *Limiter) SetHeaderEntryExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.headerEntryExpirationTTL = ttl
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetHeaderEntryExpirationTTL",
"(",
"ttl",
"time",
".",
"Duration",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"headerEntryExpirationTTL",
"=",
"ttl",
"\n",
"l",
".",
"Unlock",
"(",
")",... | // SetHeaderEntryExpirationTTL is thread-safe way of setting custom basic auth expiration TTL. | [
"SetHeaderEntryExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"custom",
"basic",
"auth",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L138-L144 |
27,621 | didip/tollbooth | limiter/limiter.go | GetHeaderEntryExpirationTTL | func (l *Limiter) GetHeaderEntryExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.headerEntryExpirationTTL
} | go | func (l *Limiter) GetHeaderEntryExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.headerEntryExpirationTTL
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetHeaderEntryExpirationTTL",
"(",
")",
"time",
".",
"Duration",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"headerEntryExpirationTTL",
"\n",
"}"
] | // GetHeaderEntryExpirationTTL is thread-safe way of getting custom basic auth expiration TTL. | [
"GetHeaderEntryExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"custom",
"basic",
"auth",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L147-L151 |
27,622 | didip/tollbooth | limiter/limiter.go | SetMax | func (l *Limiter) SetMax(max float64) *Limiter {
l.Lock()
l.max = max
l.Unlock()
return l
} | go | func (l *Limiter) SetMax(max float64) *Limiter {
l.Lock()
l.max = max
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetMax",
"(",
"max",
"float64",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"max",
"=",
"max",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"l",
"\n",
"}"
] | // SetMax is thread-safe way of setting maximum number of requests to limit per duration. | [
"SetMax",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"maximum",
"number",
"of",
"requests",
"to",
"limit",
"per",
"duration",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L154-L160 |
27,623 | didip/tollbooth | limiter/limiter.go | GetMax | func (l *Limiter) GetMax() float64 {
l.RLock()
defer l.RUnlock()
return l.max
} | go | func (l *Limiter) GetMax() float64 {
l.RLock()
defer l.RUnlock()
return l.max
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetMax",
"(",
")",
"float64",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"max",
"\n",
"}"
] | // GetMax is thread-safe way of getting maximum number of requests to limit per duration. | [
"GetMax",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"maximum",
"number",
"of",
"requests",
"to",
"limit",
"per",
"duration",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L163-L167 |
27,624 | didip/tollbooth | limiter/limiter.go | SetBurst | func (l *Limiter) SetBurst(burst int) *Limiter {
l.Lock()
l.burst = burst
l.Unlock()
return l
} | go | func (l *Limiter) SetBurst(burst int) *Limiter {
l.Lock()
l.burst = burst
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetBurst",
"(",
"burst",
"int",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"burst",
"=",
"burst",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"l",
"\n",
"}"
] | // SetBurst is thread-safe way of setting maximum burst size. | [
"SetBurst",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"maximum",
"burst",
"size",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L170-L176 |
27,625 | didip/tollbooth | limiter/limiter.go | GetBurst | func (l *Limiter) GetBurst() int {
l.RLock()
defer l.RUnlock()
return l.burst
} | go | func (l *Limiter) GetBurst() int {
l.RLock()
defer l.RUnlock()
return l.burst
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetBurst",
"(",
")",
"int",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"l",
".",
"burst",
"\n",
"}"
] | // GetBurst is thread-safe way of setting maximum burst size. | [
"GetBurst",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"maximum",
"burst",
"size",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L179-L184 |
27,626 | didip/tollbooth | limiter/limiter.go | SetMessage | func (l *Limiter) SetMessage(msg string) *Limiter {
l.Lock()
l.message = msg
l.Unlock()
return l
} | go | func (l *Limiter) SetMessage(msg string) *Limiter {
l.Lock()
l.message = msg
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetMessage",
"(",
"msg",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"message",
"=",
"msg",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"l",
"\n",
"}"
] | // SetMessage is thread-safe way of setting HTTP message when limit is reached. | [
"SetMessage",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"HTTP",
"message",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L187-L193 |
27,627 | didip/tollbooth | limiter/limiter.go | GetMessage | func (l *Limiter) GetMessage() string {
l.RLock()
defer l.RUnlock()
return l.message
} | go | func (l *Limiter) GetMessage() string {
l.RLock()
defer l.RUnlock()
return l.message
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetMessage",
"(",
")",
"string",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"message",
"\n",
"}"
] | // GetMessage is thread-safe way of getting HTTP message when limit is reached. | [
"GetMessage",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"HTTP",
"message",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L196-L200 |
27,628 | didip/tollbooth | limiter/limiter.go | SetMessageContentType | func (l *Limiter) SetMessageContentType(contentType string) *Limiter {
l.Lock()
l.messageContentType = contentType
l.Unlock()
return l
} | go | func (l *Limiter) SetMessageContentType(contentType string) *Limiter {
l.Lock()
l.messageContentType = contentType
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetMessageContentType",
"(",
"contentType",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"messageContentType",
"=",
"contentType",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"r... | // SetMessageContentType is thread-safe way of setting HTTP message Content-Type when limit is reached. | [
"SetMessageContentType",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"HTTP",
"message",
"Content",
"-",
"Type",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L203-L209 |
27,629 | didip/tollbooth | limiter/limiter.go | GetMessageContentType | func (l *Limiter) GetMessageContentType() string {
l.RLock()
defer l.RUnlock()
return l.messageContentType
} | go | func (l *Limiter) GetMessageContentType() string {
l.RLock()
defer l.RUnlock()
return l.messageContentType
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetMessageContentType",
"(",
")",
"string",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"messageContentType",
"\n",
"}"
] | // GetMessageContentType is thread-safe way of getting HTTP message Content-Type when limit is reached. | [
"GetMessageContentType",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"HTTP",
"message",
"Content",
"-",
"Type",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L212-L216 |
27,630 | didip/tollbooth | limiter/limiter.go | SetStatusCode | func (l *Limiter) SetStatusCode(statusCode int) *Limiter {
l.Lock()
l.statusCode = statusCode
l.Unlock()
return l
} | go | func (l *Limiter) SetStatusCode(statusCode int) *Limiter {
l.Lock()
l.statusCode = statusCode
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetStatusCode",
"(",
"statusCode",
"int",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"statusCode",
"=",
"statusCode",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"l",
"\n"... | // SetStatusCode is thread-safe way of setting HTTP status code when limit is reached. | [
"SetStatusCode",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"HTTP",
"status",
"code",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L219-L225 |
27,631 | didip/tollbooth | limiter/limiter.go | GetStatusCode | func (l *Limiter) GetStatusCode() int {
l.RLock()
defer l.RUnlock()
return l.statusCode
} | go | func (l *Limiter) GetStatusCode() int {
l.RLock()
defer l.RUnlock()
return l.statusCode
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetStatusCode",
"(",
")",
"int",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"statusCode",
"\n",
"}"
] | // GetStatusCode is thread-safe way of getting HTTP status code when limit is reached. | [
"GetStatusCode",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"HTTP",
"status",
"code",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L228-L232 |
27,632 | didip/tollbooth | limiter/limiter.go | SetOnLimitReached | func (l *Limiter) SetOnLimitReached(fn func(w http.ResponseWriter, r *http.Request)) *Limiter {
l.Lock()
l.onLimitReached = fn
l.Unlock()
return l
} | go | func (l *Limiter) SetOnLimitReached(fn func(w http.ResponseWriter, r *http.Request)) *Limiter {
l.Lock()
l.onLimitReached = fn
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetOnLimitReached",
"(",
"fn",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"onLimitReache... | // SetOnLimitReached is thread-safe way of setting after-rejection function when limit is reached. | [
"SetOnLimitReached",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"after",
"-",
"rejection",
"function",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L235-L241 |
27,633 | didip/tollbooth | limiter/limiter.go | ExecOnLimitReached | func (l *Limiter) ExecOnLimitReached(w http.ResponseWriter, r *http.Request) {
l.RLock()
defer l.RUnlock()
fn := l.onLimitReached
if fn != nil {
fn(w, r)
}
} | go | func (l *Limiter) ExecOnLimitReached(w http.ResponseWriter, r *http.Request) {
l.RLock()
defer l.RUnlock()
fn := l.onLimitReached
if fn != nil {
fn(w, r)
}
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"ExecOnLimitReached",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n\n",
"fn",
":=",
... | // ExecOnLimitReached is thread-safe way of executing after-rejection function when limit is reached. | [
"ExecOnLimitReached",
"is",
"thread",
"-",
"safe",
"way",
"of",
"executing",
"after",
"-",
"rejection",
"function",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L244-L252 |
27,634 | didip/tollbooth | limiter/limiter.go | SetIPLookups | func (l *Limiter) SetIPLookups(ipLookups []string) *Limiter {
l.Lock()
l.ipLookups = ipLookups
l.Unlock()
return l
} | go | func (l *Limiter) SetIPLookups(ipLookups []string) *Limiter {
l.Lock()
l.ipLookups = ipLookups
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetIPLookups",
"(",
"ipLookups",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"ipLookups",
"=",
"ipLookups",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
... | // SetIPLookups is thread-safe way of setting list of places to look up IP address. | [
"SetIPLookups",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"list",
"of",
"places",
"to",
"look",
"up",
"IP",
"address",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L255-L261 |
27,635 | didip/tollbooth | limiter/limiter.go | GetIPLookups | func (l *Limiter) GetIPLookups() []string {
l.RLock()
defer l.RUnlock()
return l.ipLookups
} | go | func (l *Limiter) GetIPLookups() []string {
l.RLock()
defer l.RUnlock()
return l.ipLookups
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetIPLookups",
"(",
")",
"[",
"]",
"string",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"ipLookups",
"\n",
"}"
] | // GetIPLookups is thread-safe way of getting list of places to look up IP address. | [
"GetIPLookups",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"list",
"of",
"places",
"to",
"look",
"up",
"IP",
"address",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L264-L268 |
27,636 | didip/tollbooth | limiter/limiter.go | SetForwardedForIndexFromBehind | func (l *Limiter) SetForwardedForIndexFromBehind(forwardedForIndex int) *Limiter {
l.Lock()
l.forwardedForIndex = forwardedForIndex
l.Unlock()
return l
} | go | func (l *Limiter) SetForwardedForIndexFromBehind(forwardedForIndex int) *Limiter {
l.Lock()
l.forwardedForIndex = forwardedForIndex
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetForwardedForIndexFromBehind",
"(",
"forwardedForIndex",
"int",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"forwardedForIndex",
"=",
"forwardedForIndex",
"\n",
"l",
".",
"Unlock",
"(",
")... | // SetForwardedForIndexFromBehind is thread-safe way of setting which X-Forwarded-For index to choose. | [
"SetForwardedForIndexFromBehind",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"which",
"X",
"-",
"Forwarded",
"-",
"For",
"index",
"to",
"choose",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L271-L277 |
27,637 | didip/tollbooth | limiter/limiter.go | GetForwardedForIndexFromBehind | func (l *Limiter) GetForwardedForIndexFromBehind() int {
l.RLock()
defer l.RUnlock()
return l.forwardedForIndex
} | go | func (l *Limiter) GetForwardedForIndexFromBehind() int {
l.RLock()
defer l.RUnlock()
return l.forwardedForIndex
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetForwardedForIndexFromBehind",
"(",
")",
"int",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"forwardedForIndex",
"\n",
"}"
] | // GetForwardedForIndexFromBehind is thread-safe way of getting which X-Forwarded-For index to choose. | [
"GetForwardedForIndexFromBehind",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"which",
"X",
"-",
"Forwarded",
"-",
"For",
"index",
"to",
"choose",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L280-L284 |
27,638 | didip/tollbooth | limiter/limiter.go | SetBasicAuthUsers | func (l *Limiter) SetBasicAuthUsers(basicAuthUsers []string) *Limiter {
ttl := l.GetBasicAuthExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
for _, basicAuthUser := range basicAuthUsers {
l.basicAuthUsers.Set(basicAuthUser, true, ttl)
}
return l
} | go | func (l *Limiter) SetBasicAuthUsers(basicAuthUsers []string) *Limiter {
ttl := l.GetBasicAuthExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
for _, basicAuthUser := range basicAuthUsers {
l.basicAuthUsers.Set(basicAuthUser, true, ttl)
}
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetBasicAuthUsers",
"(",
"basicAuthUsers",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"ttl",
":=",
"l",
".",
"GetBasicAuthExpirationTTL",
"(",
")",
"\n",
"if",
"ttl",
"<=",
"0",
"{",
"ttl",
"=",
"l",
".",
"g... | // SetBasicAuthUsers is thread-safe way of setting list of basic auth usernames to limit. | [
"SetBasicAuthUsers",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"list",
"of",
"basic",
"auth",
"usernames",
"to",
"limit",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L303-L314 |
27,639 | didip/tollbooth | limiter/limiter.go | GetBasicAuthUsers | func (l *Limiter) GetBasicAuthUsers() []string {
asMap := l.basicAuthUsers.Items()
var basicAuthUsers []string
for basicAuthUser, _ := range asMap {
basicAuthUsers = append(basicAuthUsers, basicAuthUser)
}
return basicAuthUsers
} | go | func (l *Limiter) GetBasicAuthUsers() []string {
asMap := l.basicAuthUsers.Items()
var basicAuthUsers []string
for basicAuthUser, _ := range asMap {
basicAuthUsers = append(basicAuthUsers, basicAuthUser)
}
return basicAuthUsers
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetBasicAuthUsers",
"(",
")",
"[",
"]",
"string",
"{",
"asMap",
":=",
"l",
".",
"basicAuthUsers",
".",
"Items",
"(",
")",
"\n\n",
"var",
"basicAuthUsers",
"[",
"]",
"string",
"\n",
"for",
"basicAuthUser",
",",
"_... | // GetBasicAuthUsers is thread-safe way of getting list of basic auth usernames to limit. | [
"GetBasicAuthUsers",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"list",
"of",
"basic",
"auth",
"usernames",
"to",
"limit",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L317-L326 |
27,640 | didip/tollbooth | limiter/limiter.go | RemoveBasicAuthUsers | func (l *Limiter) RemoveBasicAuthUsers(basicAuthUsers []string) *Limiter {
for _, toBeRemoved := range basicAuthUsers {
l.basicAuthUsers.Delete(toBeRemoved)
}
return l
} | go | func (l *Limiter) RemoveBasicAuthUsers(basicAuthUsers []string) *Limiter {
for _, toBeRemoved := range basicAuthUsers {
l.basicAuthUsers.Delete(toBeRemoved)
}
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"RemoveBasicAuthUsers",
"(",
"basicAuthUsers",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"for",
"_",
",",
"toBeRemoved",
":=",
"range",
"basicAuthUsers",
"{",
"l",
".",
"basicAuthUsers",
".",
"Delete",
"(",
"toBeR... | // RemoveBasicAuthUsers is thread-safe way of removing basic auth usernames from existing list. | [
"RemoveBasicAuthUsers",
"is",
"thread",
"-",
"safe",
"way",
"of",
"removing",
"basic",
"auth",
"usernames",
"from",
"existing",
"list",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L329-L335 |
27,641 | didip/tollbooth | limiter/limiter.go | SetHeaders | func (l *Limiter) SetHeaders(headers map[string][]string) *Limiter {
if l.headers == nil {
l.headers = make(map[string]*gocache.Cache)
}
for header, entries := range headers {
l.SetHeader(header, entries)
}
return l
} | go | func (l *Limiter) SetHeaders(headers map[string][]string) *Limiter {
if l.headers == nil {
l.headers = make(map[string]*gocache.Cache)
}
for header, entries := range headers {
l.SetHeader(header, entries)
}
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetHeaders",
"(",
"headers",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"if",
"l",
".",
"headers",
"==",
"nil",
"{",
"l",
".",
"headers",
"=",
"make",
"(",
"map",
"[",
"string"... | // SetHeaders is thread-safe way of setting map of HTTP headers to limit. | [
"SetHeaders",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"map",
"of",
"HTTP",
"headers",
"to",
"limit",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L338-L348 |
27,642 | didip/tollbooth | limiter/limiter.go | GetHeaders | func (l *Limiter) GetHeaders() map[string][]string {
results := make(map[string][]string)
l.RLock()
defer l.RUnlock()
for header, entriesAsGoCache := range l.headers {
entries := make([]string, 0)
for entry, _ := range entriesAsGoCache.Items() {
entries = append(entries, entry)
}
results[header] = en... | go | func (l *Limiter) GetHeaders() map[string][]string {
results := make(map[string][]string)
l.RLock()
defer l.RUnlock()
for header, entriesAsGoCache := range l.headers {
entries := make([]string, 0)
for entry, _ := range entriesAsGoCache.Items() {
entries = append(entries, entry)
}
results[header] = en... | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetHeaders",
"(",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"results",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"\n\n",
"l",
".",
"RLock",
"(",
")",
"\n",
"def... | // GetHeaders is thread-safe way of getting map of HTTP headers to limit. | [
"GetHeaders",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"map",
"of",
"HTTP",
"headers",
"to",
"limit",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L351-L368 |
27,643 | didip/tollbooth | limiter/limiter.go | SetHeader | func (l *Limiter) SetHeader(header string, entries []string) *Limiter {
l.RLock()
existing, found := l.headers[header]
l.RUnlock()
ttl := l.GetHeaderEntryExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
if !found {
existing = gocache.New(ttl, l.generalExpirableOptions.Ex... | go | func (l *Limiter) SetHeader(header string, entries []string) *Limiter {
l.RLock()
existing, found := l.headers[header]
l.RUnlock()
ttl := l.GetHeaderEntryExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
if !found {
existing = gocache.New(ttl, l.generalExpirableOptions.Ex... | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetHeader",
"(",
"header",
"string",
",",
"entries",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"existing",
",",
"found",
":=",
"l",
".",
"headers",
"[",
"header",
"]",
... | // SetHeader is thread-safe way of setting entries of 1 HTTP header. | [
"SetHeader",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"entries",
"of",
"1",
"HTTP",
"header",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L371-L394 |
27,644 | didip/tollbooth | limiter/limiter.go | GetHeader | func (l *Limiter) GetHeader(header string) []string {
l.RLock()
entriesAsGoCache := l.headers[header]
l.RUnlock()
entriesAsMap := entriesAsGoCache.Items()
entries := make([]string, 0)
for entry, _ := range entriesAsMap {
entries = append(entries, entry)
}
return entries
} | go | func (l *Limiter) GetHeader(header string) []string {
l.RLock()
entriesAsGoCache := l.headers[header]
l.RUnlock()
entriesAsMap := entriesAsGoCache.Items()
entries := make([]string, 0)
for entry, _ := range entriesAsMap {
entries = append(entries, entry)
}
return entries
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetHeader",
"(",
"header",
"string",
")",
"[",
"]",
"string",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"entriesAsGoCache",
":=",
"l",
".",
"headers",
"[",
"header",
"]",
"\n",
"l",
".",
"RUnlock",
"(",
")",
... | // GetHeader is thread-safe way of getting entries of 1 HTTP header. | [
"GetHeader",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"entries",
"of",
"1",
"HTTP",
"header",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L397-L410 |
27,645 | didip/tollbooth | limiter/limiter.go | RemoveHeader | func (l *Limiter) RemoveHeader(header string) *Limiter {
ttl := l.GetHeaderEntryExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
l.Lock()
l.headers[header] = gocache.New(ttl, l.generalExpirableOptions.ExpireJobInterval)
l.Unlock()
return l
} | go | func (l *Limiter) RemoveHeader(header string) *Limiter {
ttl := l.GetHeaderEntryExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
l.Lock()
l.headers[header] = gocache.New(ttl, l.generalExpirableOptions.ExpireJobInterval)
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"RemoveHeader",
"(",
"header",
"string",
")",
"*",
"Limiter",
"{",
"ttl",
":=",
"l",
".",
"GetHeaderEntryExpirationTTL",
"(",
")",
"\n",
"if",
"ttl",
"<=",
"0",
"{",
"ttl",
"=",
"l",
".",
"generalExpirableOptions",
... | // RemoveHeader is thread-safe way of removing entries of 1 HTTP header. | [
"RemoveHeader",
"is",
"thread",
"-",
"safe",
"way",
"of",
"removing",
"entries",
"of",
"1",
"HTTP",
"header",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L413-L424 |
27,646 | didip/tollbooth | limiter/limiter.go | RemoveHeaderEntries | func (l *Limiter) RemoveHeaderEntries(header string, entriesForRemoval []string) *Limiter {
l.RLock()
entries, found := l.headers[header]
l.RUnlock()
if !found {
return l
}
for _, toBeRemoved := range entriesForRemoval {
entries.Delete(toBeRemoved)
}
return l
} | go | func (l *Limiter) RemoveHeaderEntries(header string, entriesForRemoval []string) *Limiter {
l.RLock()
entries, found := l.headers[header]
l.RUnlock()
if !found {
return l
}
for _, toBeRemoved := range entriesForRemoval {
entries.Delete(toBeRemoved)
}
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"RemoveHeaderEntries",
"(",
"header",
"string",
",",
"entriesForRemoval",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"entries",
",",
"found",
":=",
"l",
".",
"headers",
"[",
... | // RemoveHeaderEntries is thread-safe way of adding new entries to 1 HTTP header rule. | [
"RemoveHeaderEntries",
"is",
"thread",
"-",
"safe",
"way",
"of",
"adding",
"new",
"entries",
"to",
"1",
"HTTP",
"header",
"rule",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L427-L441 |
27,647 | AlecAivazis/survey | survey.go | WithStdio | func WithStdio(in terminal.FileReader, out terminal.FileWriter, err io.Writer) AskOpt {
return func(options *AskOptions) error {
options.Stdio.In = in
options.Stdio.Out = out
options.Stdio.Err = err
return nil
}
} | go | func WithStdio(in terminal.FileReader, out terminal.FileWriter, err io.Writer) AskOpt {
return func(options *AskOptions) error {
options.Stdio.In = in
options.Stdio.Out = out
options.Stdio.Err = err
return nil
}
} | [
"func",
"WithStdio",
"(",
"in",
"terminal",
".",
"FileReader",
",",
"out",
"terminal",
".",
"FileWriter",
",",
"err",
"io",
".",
"Writer",
")",
"AskOpt",
"{",
"return",
"func",
"(",
"options",
"*",
"AskOptions",
")",
"error",
"{",
"options",
".",
"Stdio"... | // WithStdio specifies the standard input, output and error files survey
// interacts with. By default, these are os.Stdin, os.Stdout, and os.Stderr. | [
"WithStdio",
"specifies",
"the",
"standard",
"input",
"output",
"and",
"error",
"files",
"survey",
"interacts",
"with",
".",
"By",
"default",
"these",
"are",
"os",
".",
"Stdin",
"os",
".",
"Stdout",
"and",
"os",
".",
"Stderr",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/survey.go#L67-L74 |
27,648 | AlecAivazis/survey | survey.go | paginate | func paginate(page int, choices []string, sel int) ([]string, int) {
// the number of elements to show in a single page
var pageSize int
// if the select has a specific page size
if page != 0 {
// use the specified one
pageSize = page
// otherwise the select does not have a page size
} else {
// use the pa... | go | func paginate(page int, choices []string, sel int) ([]string, int) {
// the number of elements to show in a single page
var pageSize int
// if the select has a specific page size
if page != 0 {
// use the specified one
pageSize = page
// otherwise the select does not have a page size
} else {
// use the pa... | [
"func",
"paginate",
"(",
"page",
"int",
",",
"choices",
"[",
"]",
"string",
",",
"sel",
"int",
")",
"(",
"[",
"]",
"string",
",",
"int",
")",
"{",
"// the number of elements to show in a single page",
"var",
"pageSize",
"int",
"\n",
"// if the select has a speci... | // paginate returns a single page of choices given the page size, the total list of
// possible choices, and the current selected index in the total list. | [
"paginate",
"returns",
"a",
"single",
"page",
"of",
"choices",
"given",
"the",
"page",
"size",
"the",
"total",
"list",
"of",
"possible",
"choices",
"and",
"the",
"current",
"selected",
"index",
"in",
"the",
"total",
"list",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/survey.go#L210-L255 |
27,649 | AlecAivazis/survey | transform.go | ComposeTransformers | func ComposeTransformers(transformers ...Transformer) Transformer {
// return a transformer that calls each one sequentially
return func(ans interface{}) interface{} {
// execute each transformer
for _, t := range transformers {
ans = t(ans)
}
return ans
}
} | go | func ComposeTransformers(transformers ...Transformer) Transformer {
// return a transformer that calls each one sequentially
return func(ans interface{}) interface{} {
// execute each transformer
for _, t := range transformers {
ans = t(ans)
}
return ans
}
} | [
"func",
"ComposeTransformers",
"(",
"transformers",
"...",
"Transformer",
")",
"Transformer",
"{",
"// return a transformer that calls each one sequentially",
"return",
"func",
"(",
"ans",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"// execute each transforme... | // ComposeTransformers is a variadic function used to create one transformer from many. | [
"ComposeTransformers",
"is",
"a",
"variadic",
"function",
"used",
"to",
"create",
"one",
"transformer",
"from",
"many",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/transform.go#L67-L76 |
27,650 | AlecAivazis/survey | validate.go | Required | func Required(val interface{}) error {
// the reflect value of the result
value := reflect.ValueOf(val)
// if the value passed in is the zero value of the appropriate type
if isZero(value) && value.Kind() != reflect.Bool {
return errors.New("Value is required")
}
return nil
} | go | func Required(val interface{}) error {
// the reflect value of the result
value := reflect.ValueOf(val)
// if the value passed in is the zero value of the appropriate type
if isZero(value) && value.Kind() != reflect.Bool {
return errors.New("Value is required")
}
return nil
} | [
"func",
"Required",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"// the reflect value of the result",
"value",
":=",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
"\n\n",
"// if the value passed in is the zero value of the appropriate type",
"if",
"isZero",
"(",... | // Required does not allow an empty value | [
"Required",
"does",
"not",
"allow",
"an",
"empty",
"value"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/validate.go#L10-L19 |
27,651 | AlecAivazis/survey | validate.go | MaxLength | func MaxLength(length int) Validator {
// return a validator that checks the length of the string
return func(val interface{}) error {
if str, ok := val.(string); ok {
// if the string is longer than the given value
if len([]rune(str)) > length {
// yell loudly
return fmt.Errorf("value is too long. Ma... | go | func MaxLength(length int) Validator {
// return a validator that checks the length of the string
return func(val interface{}) error {
if str, ok := val.(string); ok {
// if the string is longer than the given value
if len([]rune(str)) > length {
// yell loudly
return fmt.Errorf("value is too long. Ma... | [
"func",
"MaxLength",
"(",
"length",
"int",
")",
"Validator",
"{",
"// return a validator that checks the length of the string",
"return",
"func",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"str",
",",
"ok",
":=",
"val",
".",
"(",
"string",
")"... | // MaxLength requires that the string is no longer than the specified value | [
"MaxLength",
"requires",
"that",
"the",
"string",
"is",
"no",
"longer",
"than",
"the",
"specified",
"value"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/validate.go#L22-L39 |
27,652 | AlecAivazis/survey | validate.go | ComposeValidators | func ComposeValidators(validators ...Validator) Validator {
// return a validator that calls each one sequentially
return func(val interface{}) error {
// execute each validator
for _, validator := range validators {
// if the answer's value is not valid
if err := validator(val); err != nil {
// return ... | go | func ComposeValidators(validators ...Validator) Validator {
// return a validator that calls each one sequentially
return func(val interface{}) error {
// execute each validator
for _, validator := range validators {
// if the answer's value is not valid
if err := validator(val); err != nil {
// return ... | [
"func",
"ComposeValidators",
"(",
"validators",
"...",
"Validator",
")",
"Validator",
"{",
"// return a validator that calls each one sequentially",
"return",
"func",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"// execute each validator",
"for",
"_",
",",
"... | // ComposeValidators is a variadic function used to create one validator from many. | [
"ComposeValidators",
"is",
"a",
"variadic",
"function",
"used",
"to",
"create",
"one",
"validator",
"from",
"many",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/validate.go#L62-L76 |
27,653 | AlecAivazis/survey | validate.go | isZero | func isZero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Slice, reflect.Map:
return v.Len() == 0
}
// compare the types directly with more general coverage
return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface())
} | go | func isZero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Slice, reflect.Map:
return v.Len() == 0
}
// compare the types directly with more general coverage
return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface())
} | [
"func",
"isZero",
"(",
"v",
"reflect",
".",
"Value",
")",
"bool",
"{",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Map",
":",
"return",
"v",
".",
"Len",
"(",
")",
"==",
"0",
"\n",
"}",
"\n\n... | // isZero returns true if the passed value is the zero object | [
"isZero",
"returns",
"true",
"if",
"the",
"passed",
"value",
"is",
"the",
"zero",
"object"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/validate.go#L79-L87 |
27,654 | AlecAivazis/survey | terminal/cursor.go | Up | func (c *Cursor) Up(n int) {
fmt.Fprintf(c.Out, "\x1b[%dA", n)
} | go | func (c *Cursor) Up(n int) {
fmt.Fprintf(c.Out, "\x1b[%dA", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Up",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // Up moves the cursor n cells to up. | [
"Up",
"moves",
"the",
"cursor",
"n",
"cells",
"to",
"up",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L23-L25 |
27,655 | AlecAivazis/survey | terminal/cursor.go | Down | func (c *Cursor) Down(n int) {
fmt.Fprintf(c.Out, "\x1b[%dB", n)
} | go | func (c *Cursor) Down(n int) {
fmt.Fprintf(c.Out, "\x1b[%dB", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Down",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // Down moves the cursor n cells to down. | [
"Down",
"moves",
"the",
"cursor",
"n",
"cells",
"to",
"down",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L28-L30 |
27,656 | AlecAivazis/survey | terminal/cursor.go | Forward | func (c *Cursor) Forward(n int) {
fmt.Fprintf(c.Out, "\x1b[%dC", n)
} | go | func (c *Cursor) Forward(n int) {
fmt.Fprintf(c.Out, "\x1b[%dC", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Forward",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // Forward moves the cursor n cells to right. | [
"Forward",
"moves",
"the",
"cursor",
"n",
"cells",
"to",
"right",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L33-L35 |
27,657 | AlecAivazis/survey | terminal/cursor.go | Back | func (c *Cursor) Back(n int) {
fmt.Fprintf(c.Out, "\x1b[%dD", n)
} | go | func (c *Cursor) Back(n int) {
fmt.Fprintf(c.Out, "\x1b[%dD", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Back",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // Back moves the cursor n cells to left. | [
"Back",
"moves",
"the",
"cursor",
"n",
"cells",
"to",
"left",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L38-L40 |
27,658 | AlecAivazis/survey | terminal/cursor.go | NextLine | func (c *Cursor) NextLine(n int) {
fmt.Fprintf(c.Out, "\x1b[%dE", n)
} | go | func (c *Cursor) NextLine(n int) {
fmt.Fprintf(c.Out, "\x1b[%dE", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"NextLine",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // NextLine moves cursor to beginning of the line n lines down. | [
"NextLine",
"moves",
"cursor",
"to",
"beginning",
"of",
"the",
"line",
"n",
"lines",
"down",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L43-L45 |
27,659 | AlecAivazis/survey | terminal/cursor.go | PreviousLine | func (c *Cursor) PreviousLine(n int) {
fmt.Fprintf(c.Out, "\x1b[%dF", n)
} | go | func (c *Cursor) PreviousLine(n int) {
fmt.Fprintf(c.Out, "\x1b[%dF", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"PreviousLine",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // PreviousLine moves cursor to beginning of the line n lines up. | [
"PreviousLine",
"moves",
"cursor",
"to",
"beginning",
"of",
"the",
"line",
"n",
"lines",
"up",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L48-L50 |
27,660 | AlecAivazis/survey | terminal/cursor.go | HorizontalAbsolute | func (c *Cursor) HorizontalAbsolute(x int) {
fmt.Fprintf(c.Out, "\x1b[%dG", x)
} | go | func (c *Cursor) HorizontalAbsolute(x int) {
fmt.Fprintf(c.Out, "\x1b[%dG", x)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"HorizontalAbsolute",
"(",
"x",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"x",
")",
"\n",
"}"
] | // HorizontalAbsolute moves cursor horizontally to x. | [
"HorizontalAbsolute",
"moves",
"cursor",
"horizontally",
"to",
"x",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L53-L55 |
27,661 | AlecAivazis/survey | terminal/cursor.go | Move | func (c *Cursor) Move(x int, y int) {
fmt.Fprintf(c.Out, "\x1b[%d;%df", x, y)
} | go | func (c *Cursor) Move(x int, y int) {
fmt.Fprintf(c.Out, "\x1b[%d;%df", x, y)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Move",
"(",
"x",
"int",
",",
"y",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"x",
",",
"y",
")",
"\n",
"}"
] | // Move moves the cursor to a specific x,y location. | [
"Move",
"moves",
"the",
"cursor",
"to",
"a",
"specific",
"x",
"y",
"location",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L68-L70 |
27,662 | AlecAivazis/survey | terminal/cursor.go | MoveNextLine | func (c *Cursor) MoveNextLine(cur *Coord, terminalSize *Coord) {
if cur.Y == terminalSize.Y {
fmt.Fprintln(c.Out)
}
c.NextLine(1)
} | go | func (c *Cursor) MoveNextLine(cur *Coord, terminalSize *Coord) {
if cur.Y == terminalSize.Y {
fmt.Fprintln(c.Out)
}
c.NextLine(1)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"MoveNextLine",
"(",
"cur",
"*",
"Coord",
",",
"terminalSize",
"*",
"Coord",
")",
"{",
"if",
"cur",
".",
"Y",
"==",
"terminalSize",
".",
"Y",
"{",
"fmt",
".",
"Fprintln",
"(",
"c",
".",
"Out",
")",
"\n",
"}",... | // for comparability purposes between windows
// in unix we need to print out a new line on some terminals | [
"for",
"comparability",
"purposes",
"between",
"windows",
"in",
"unix",
"we",
"need",
"to",
"print",
"out",
"a",
"new",
"line",
"on",
"some",
"terminals"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L84-L89 |
27,663 | AlecAivazis/survey | terminal/cursor.go | Location | func (c *Cursor) Location(buf *bytes.Buffer) (*Coord, error) {
// ANSI escape sequence for DSR - Device Status Report
// https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
fmt.Fprint(c.Out, "\x1b[6n")
// There may be input in Stdin prior to CursorLocation so make sure we don't
// drop those bytes.
var ... | go | func (c *Cursor) Location(buf *bytes.Buffer) (*Coord, error) {
// ANSI escape sequence for DSR - Device Status Report
// https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
fmt.Fprint(c.Out, "\x1b[6n")
// There may be input in Stdin prior to CursorLocation so make sure we don't
// drop those bytes.
var ... | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Location",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"(",
"*",
"Coord",
",",
"error",
")",
"{",
"// ANSI escape sequence for DSR - Device Status Report",
"// https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences",
"fmt",... | // Location returns the current location of the cursor in the terminal | [
"Location",
"returns",
"the",
"current",
"location",
"of",
"the",
"cursor",
"in",
"the",
"terminal"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L92-L136 |
27,664 | AlecAivazis/survey | terminal/cursor.go | Size | func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error) {
// the general approach here is to move the cursor to the very bottom
// of the terminal, ask for the current location and then move the
// cursor back where we started
// hide the cursor (so it doesn't blink when getting the size of the terminal)
c.Hide(... | go | func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error) {
// the general approach here is to move the cursor to the very bottom
// of the terminal, ask for the current location and then move the
// cursor back where we started
// hide the cursor (so it doesn't blink when getting the size of the terminal)
c.Hide(... | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Size",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"(",
"*",
"Coord",
",",
"error",
")",
"{",
"// the general approach here is to move the cursor to the very bottom",
"// of the terminal, ask for the current location and then move ... | // Size returns the height and width of the terminal. | [
"Size",
"returns",
"the",
"height",
"and",
"width",
"of",
"the",
"terminal",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L147-L174 |
27,665 | AlecAivazis/survey | multiselect.go | Cleanup | func (m *MultiSelect) Cleanup(val interface{}) error {
// execute the output summary template with the answer
return m.Render(
MultiSelectQuestionTemplate,
MultiSelectTemplateData{
MultiSelect: *m,
SelectedIndex: m.selectedIndex,
Checked: m.checked,
Answer: strings.Join(val.([]string), ... | go | func (m *MultiSelect) Cleanup(val interface{}) error {
// execute the output summary template with the answer
return m.Render(
MultiSelectQuestionTemplate,
MultiSelectTemplateData{
MultiSelect: *m,
SelectedIndex: m.selectedIndex,
Checked: m.checked,
Answer: strings.Join(val.([]string), ... | [
"func",
"(",
"m",
"*",
"MultiSelect",
")",
"Cleanup",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"// execute the output summary template with the answer",
"return",
"m",
".",
"Render",
"(",
"MultiSelectQuestionTemplate",
",",
"MultiSelectTemplateData",
"{",... | // Cleanup removes the options section, and renders the ask like a normal question. | [
"Cleanup",
"removes",
"the",
"options",
"section",
"and",
"renders",
"the",
"ask",
"like",
"a",
"normal",
"question",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/multiselect.go#L236-L248 |
27,666 | AlecAivazis/survey | terminal/runereader_posix.go | SetTermMode | func (rr *RuneReader) SetTermMode() error {
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(rr.stdio.In.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&rr.state.term)), 0, 0, 0); err != 0 {
return err
}
newState := rr.state.term
newState.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON | sys... | go | func (rr *RuneReader) SetTermMode() error {
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(rr.stdio.In.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&rr.state.term)), 0, 0, 0); err != 0 {
return err
}
newState := rr.state.term
newState.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON | sys... | [
"func",
"(",
"rr",
"*",
"RuneReader",
")",
"SetTermMode",
"(",
")",
"error",
"{",
"if",
"_",
",",
"_",
",",
"err",
":=",
"syscall",
".",
"Syscall6",
"(",
"syscall",
".",
"SYS_IOCTL",
",",
"uintptr",
"(",
"rr",
".",
"stdio",
".",
"In",
".",
"Fd",
... | // For reading runes we just want to disable echo. | [
"For",
"reading",
"runes",
"we",
"just",
"want",
"to",
"disable",
"echo",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/runereader_posix.go#L41-L54 |
27,667 | AlecAivazis/survey | confirm.go | Cleanup | func (c *Confirm) Cleanup(val interface{}) error {
// if the value was previously true
ans := yesNo(val.(bool))
// render the template
return c.Render(
ConfirmQuestionTemplate,
ConfirmTemplateData{Confirm: *c, Answer: ans},
)
} | go | func (c *Confirm) Cleanup(val interface{}) error {
// if the value was previously true
ans := yesNo(val.(bool))
// render the template
return c.Render(
ConfirmQuestionTemplate,
ConfirmTemplateData{Confirm: *c, Answer: ans},
)
} | [
"func",
"(",
"c",
"*",
"Confirm",
")",
"Cleanup",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"// if the value was previously true",
"ans",
":=",
"yesNo",
"(",
"val",
".",
"(",
"bool",
")",
")",
"\n",
"// render the template",
"return",
"c",
".",... | // Cleanup overwrite the line with the finalized formatted version | [
"Cleanup",
"overwrite",
"the",
"line",
"with",
"the",
"finalized",
"formatted",
"version"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/confirm.go#L130-L138 |
27,668 | golang/gddo | httputil/respbuf.go | Write | func (rb *ResponseBuffer) Write(p []byte) (int, error) {
return rb.buf.Write(p)
} | go | func (rb *ResponseBuffer) Write(p []byte) (int, error) {
return rb.buf.Write(p)
} | [
"func",
"(",
"rb",
"*",
"ResponseBuffer",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"rb",
".",
"buf",
".",
"Write",
"(",
"p",
")",
"\n",
"}"
] | // Write implements the http.ResponseWriter interface. | [
"Write",
"implements",
"the",
"http",
".",
"ResponseWriter",
"interface",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/respbuf.go#L24-L26 |
27,669 | golang/gddo | httputil/respbuf.go | Header | func (rb *ResponseBuffer) Header() http.Header {
if rb.header == nil {
rb.header = make(http.Header)
}
return rb.header
} | go | func (rb *ResponseBuffer) Header() http.Header {
if rb.header == nil {
rb.header = make(http.Header)
}
return rb.header
} | [
"func",
"(",
"rb",
"*",
"ResponseBuffer",
")",
"Header",
"(",
")",
"http",
".",
"Header",
"{",
"if",
"rb",
".",
"header",
"==",
"nil",
"{",
"rb",
".",
"header",
"=",
"make",
"(",
"http",
".",
"Header",
")",
"\n",
"}",
"\n",
"return",
"rb",
".",
... | // Header implements the http.ResponseWriter interface. | [
"Header",
"implements",
"the",
"http",
".",
"ResponseWriter",
"interface",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/respbuf.go#L34-L39 |
27,670 | golang/gddo | httputil/httputil.go | StripPort | func StripPort(s string) string {
if h, _, err := net.SplitHostPort(s); err == nil {
s = h
}
return s
} | go | func StripPort(s string) string {
if h, _, err := net.SplitHostPort(s); err == nil {
s = h
}
return s
} | [
"func",
"StripPort",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"h",
",",
"_",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"s",
")",
";",
"err",
"==",
"nil",
"{",
"s",
"=",
"h",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // StripPort removes the port specification from an address. | [
"StripPort",
"removes",
"the",
"port",
"specification",
"from",
"an",
"address",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/httputil.go#L16-L21 |
27,671 | golang/gddo | doc/builder.go | synopsis | func synopsis(s string) string {
parts := strings.SplitN(s, "\n\n", 2)
s = parts[0]
var buf []byte
const (
other = iota
period
space
)
last := space
Loop:
for i := 0; i < len(s); i++ {
b := s[i]
switch b {
case ' ', '\t', '\r', '\n':
switch last {
case period:
break Loop
case other:
... | go | func synopsis(s string) string {
parts := strings.SplitN(s, "\n\n", 2)
s = parts[0]
var buf []byte
const (
other = iota
period
space
)
last := space
Loop:
for i := 0; i < len(s); i++ {
b := s[i]
switch b {
case ' ', '\t', '\r', '\n':
switch last {
case period:
break Loop
case other:
... | [
"func",
"synopsis",
"(",
"s",
"string",
")",
"string",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"s",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"2",
")",
"\n",
"s",
"=",
"parts",
"[",
"0",
"]",
"\n\n",
"var",
"buf",
"[",
"]",
"byte",
"\n",
... | // synopsis extracts the first sentence from s. All runs of whitespace are
// replaced by a single space. | [
"synopsis",
"extracts",
"the",
"first",
"sentence",
"from",
"s",
".",
"All",
"runs",
"of",
"whitespace",
"are",
"replaced",
"by",
"a",
"single",
"space",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/doc/builder.go#L46-L105 |
27,672 | golang/gddo | doc/builder.go | addReferences | func addReferences(references map[string]bool, s []byte) {
for _, pat := range referencesPats {
for _, m := range pat.FindAllSubmatch(s, -1) {
p := string(m[1])
if gosrc.IsValidRemotePath(p) {
references[p] = true
}
}
}
} | go | func addReferences(references map[string]bool, s []byte) {
for _, pat := range referencesPats {
for _, m := range pat.FindAllSubmatch(s, -1) {
p := string(m[1])
if gosrc.IsValidRemotePath(p) {
references[p] = true
}
}
}
} | [
"func",
"addReferences",
"(",
"references",
"map",
"[",
"string",
"]",
"bool",
",",
"s",
"[",
"]",
"byte",
")",
"{",
"for",
"_",
",",
"pat",
":=",
"range",
"referencesPats",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"pat",
".",
"FindAllSubmatch",
"("... | // addReferences adds packages referenced in plain text s. | [
"addReferences",
"adds",
"packages",
"referenced",
"in",
"plain",
"text",
"s",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/doc/builder.go#L121-L130 |
27,673 | golang/gddo | doc/builder.go | SetDefaultGOOS | func SetDefaultGOOS(goos string) {
if goos == "" {
return
}
var i int
for ; i < len(goEnvs); i++ {
if goEnvs[i].GOOS == goos {
break
}
}
switch i {
case 0:
return
case len(goEnvs):
env := goEnvs[0]
env.GOOS = goos
goEnvs = append(goEnvs, env)
}
goEnvs[0], goEnvs[i] = goEnvs[i], goEnvs[0]
} | go | func SetDefaultGOOS(goos string) {
if goos == "" {
return
}
var i int
for ; i < len(goEnvs); i++ {
if goEnvs[i].GOOS == goos {
break
}
}
switch i {
case 0:
return
case len(goEnvs):
env := goEnvs[0]
env.GOOS = goos
goEnvs = append(goEnvs, env)
}
goEnvs[0], goEnvs[i] = goEnvs[i], goEnvs[0]
} | [
"func",
"SetDefaultGOOS",
"(",
"goos",
"string",
")",
"{",
"if",
"goos",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"var",
"i",
"int",
"\n",
"for",
";",
"i",
"<",
"len",
"(",
"goEnvs",
")",
";",
"i",
"++",
"{",
"if",
"goEnvs",
"[",
"i",
... | // SetDefaultGOOS sets given GOOS value as default one to use when building
// package documents. SetDefaultGOOS has no effect on some windows-only
// packages. | [
"SetDefaultGOOS",
"sets",
"given",
"GOOS",
"value",
"as",
"default",
"one",
"to",
"use",
"when",
"building",
"package",
"documents",
".",
"SetDefaultGOOS",
"has",
"no",
"effect",
"on",
"some",
"windows",
"-",
"only",
"packages",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/doc/builder.go#L475-L494 |
27,674 | golang/gddo | httputil/header/header.go | Copy | func Copy(header http.Header) http.Header {
h := make(http.Header)
for k, vs := range header {
h[k] = vs
}
return h
} | go | func Copy(header http.Header) http.Header {
h := make(http.Header)
for k, vs := range header {
h[k] = vs
}
return h
} | [
"func",
"Copy",
"(",
"header",
"http",
".",
"Header",
")",
"http",
".",
"Header",
"{",
"h",
":=",
"make",
"(",
"http",
".",
"Header",
")",
"\n",
"for",
"k",
",",
"vs",
":=",
"range",
"header",
"{",
"h",
"[",
"k",
"]",
"=",
"vs",
"\n",
"}",
"\... | // Copy returns a shallow copy of the header. | [
"Copy",
"returns",
"a",
"shallow",
"copy",
"of",
"the",
"header",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/header/header.go#L59-L65 |
27,675 | golang/gddo | httputil/header/header.go | ParseTime | func ParseTime(header http.Header, key string) time.Time {
if s := header.Get(key); s != "" {
for _, layout := range timeLayouts {
if t, err := time.Parse(layout, s); err == nil {
return t.UTC()
}
}
}
return time.Time{}
} | go | func ParseTime(header http.Header, key string) time.Time {
if s := header.Get(key); s != "" {
for _, layout := range timeLayouts {
if t, err := time.Parse(layout, s); err == nil {
return t.UTC()
}
}
}
return time.Time{}
} | [
"func",
"ParseTime",
"(",
"header",
"http",
".",
"Header",
",",
"key",
"string",
")",
"time",
".",
"Time",
"{",
"if",
"s",
":=",
"header",
".",
"Get",
"(",
"key",
")",
";",
"s",
"!=",
"\"",
"\"",
"{",
"for",
"_",
",",
"layout",
":=",
"range",
"... | // ParseTime parses the header as time. The zero value is returned if the
// header is not present or there is an error parsing the
// header. | [
"ParseTime",
"parses",
"the",
"header",
"as",
"time",
".",
"The",
"zero",
"value",
"is",
"returned",
"if",
"the",
"header",
"is",
"not",
"present",
"or",
"there",
"is",
"an",
"error",
"parsing",
"the",
"header",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/header/header.go#L72-L81 |
27,676 | golang/gddo | httputil/header/header.go | ParseList | func ParseList(header http.Header, key string) []string {
var result []string
for _, s := range header[http.CanonicalHeaderKey(key)] {
begin := 0
end := 0
escape := false
quote := false
for i := 0; i < len(s); i++ {
b := s[i]
switch {
case escape:
escape = false
end = i + 1
case quote:
... | go | func ParseList(header http.Header, key string) []string {
var result []string
for _, s := range header[http.CanonicalHeaderKey(key)] {
begin := 0
end := 0
escape := false
quote := false
for i := 0; i < len(s); i++ {
b := s[i]
switch {
case escape:
escape = false
end = i + 1
case quote:
... | [
"func",
"ParseList",
"(",
"header",
"http",
".",
"Header",
",",
"key",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"result",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"header",
"[",
"http",
".",
"CanonicalHeaderKey",
"(",
"key... | // ParseList parses a comma separated list of values. Commas are ignored in
// quoted strings. Quoted values are not unescaped or unquoted. Whitespace is
// trimmed. | [
"ParseList",
"parses",
"a",
"comma",
"separated",
"list",
"of",
"values",
".",
"Commas",
"are",
"ignored",
"in",
"quoted",
"strings",
".",
"Quoted",
"values",
"are",
"not",
"unescaped",
"or",
"unquoted",
".",
"Whitespace",
"is",
"trimmed",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/header/header.go#L86-L130 |
27,677 | golang/gddo | httputil/static.go | FileHandler | func (ss *StaticServer) FileHandler(fileName string) http.Handler {
id := fileName
fileName = ss.resolve(fileName)
return &staticHandler{
ss: ss,
id: func(_ string) string { return id },
open: func(_ string) (io.ReadCloser, int64, string, error) { return ss.openFile(fileName) },
}
} | go | func (ss *StaticServer) FileHandler(fileName string) http.Handler {
id := fileName
fileName = ss.resolve(fileName)
return &staticHandler{
ss: ss,
id: func(_ string) string { return id },
open: func(_ string) (io.ReadCloser, int64, string, error) { return ss.openFile(fileName) },
}
} | [
"func",
"(",
"ss",
"*",
"StaticServer",
")",
"FileHandler",
"(",
"fileName",
"string",
")",
"http",
".",
"Handler",
"{",
"id",
":=",
"fileName",
"\n",
"fileName",
"=",
"ss",
".",
"resolve",
"(",
"fileName",
")",
"\n",
"return",
"&",
"staticHandler",
"{",... | // FileHandler returns a handler that serves a single file. The file is
// specified by a slash separated path relative to the static server's Dir
// field. | [
"FileHandler",
"returns",
"a",
"handler",
"that",
"serves",
"a",
"single",
"file",
".",
"The",
"file",
"is",
"specified",
"by",
"a",
"slash",
"separated",
"path",
"relative",
"to",
"the",
"static",
"server",
"s",
"Dir",
"field",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/static.go#L96-L104 |
27,678 | golang/gddo | httputil/static.go | DirectoryHandler | func (ss *StaticServer) DirectoryHandler(prefix, dirName string) http.Handler {
if !strings.HasSuffix(prefix, "/") {
prefix += "/"
}
idBase := dirName
dirName = ss.resolve(dirName)
return &staticHandler{
ss: ss,
id: func(p string) string {
if !strings.HasPrefix(p, prefix) {
return "."
}
return p... | go | func (ss *StaticServer) DirectoryHandler(prefix, dirName string) http.Handler {
if !strings.HasSuffix(prefix, "/") {
prefix += "/"
}
idBase := dirName
dirName = ss.resolve(dirName)
return &staticHandler{
ss: ss,
id: func(p string) string {
if !strings.HasPrefix(p, prefix) {
return "."
}
return p... | [
"func",
"(",
"ss",
"*",
"StaticServer",
")",
"DirectoryHandler",
"(",
"prefix",
",",
"dirName",
"string",
")",
"http",
".",
"Handler",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"prefix",
",",
"\"",
"\"",
")",
"{",
"prefix",
"+=",
"\"",
"\"",
... | // DirectoryHandler returns a handler that serves files from a directory tree.
// The directory is specified by a slash separated path relative to the static
// server's Dir field. | [
"DirectoryHandler",
"returns",
"a",
"handler",
"that",
"serves",
"files",
"from",
"a",
"directory",
"tree",
".",
"The",
"directory",
"is",
"specified",
"by",
"a",
"slash",
"separated",
"path",
"relative",
"to",
"the",
"static",
"server",
"s",
"Dir",
"field",
... | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/static.go#L109-L131 |
27,679 | golang/gddo | httputil/static.go | FilesHandler | func (ss *StaticServer) FilesHandler(fileNames ...string) http.Handler {
// todo: cache concatenated files on disk and serve from there.
mimeType := ss.mimeType(fileNames[0])
var buf []byte
var openErr error
for _, fileName := range fileNames {
p, err := ioutil.ReadFile(ss.resolve(fileName))
if err != nil {... | go | func (ss *StaticServer) FilesHandler(fileNames ...string) http.Handler {
// todo: cache concatenated files on disk and serve from there.
mimeType := ss.mimeType(fileNames[0])
var buf []byte
var openErr error
for _, fileName := range fileNames {
p, err := ioutil.ReadFile(ss.resolve(fileName))
if err != nil {... | [
"func",
"(",
"ss",
"*",
"StaticServer",
")",
"FilesHandler",
"(",
"fileNames",
"...",
"string",
")",
"http",
".",
"Handler",
"{",
"// todo: cache concatenated files on disk and serve from there.",
"mimeType",
":=",
"ss",
".",
"mimeType",
"(",
"fileNames",
"[",
"0",
... | // FilesHandler returns a handler that serves the concatentation of the
// specified files. The files are specified by slash separated paths relative
// to the static server's Dir field. | [
"FilesHandler",
"returns",
"a",
"handler",
"that",
"serves",
"the",
"concatentation",
"of",
"the",
"specified",
"files",
".",
"The",
"files",
"are",
"specified",
"by",
"slash",
"separated",
"paths",
"relative",
"to",
"the",
"static",
"server",
"s",
"Dir",
"fie... | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/static.go#L136-L163 |
27,680 | golang/gddo | database/database.go | New | func New(serverURI string, idleTimeout time.Duration, logConn bool, gaeEndpoint string) (*Database, error) {
pool := &redis.Pool{
Dial: newDBDialer(serverURI, logConn),
MaxIdle: 10,
IdleTimeout: idleTimeout,
}
var rc *remote_api.Client
if gaeEndpoint != "" {
var err error
if rc, err = newRemot... | go | func New(serverURI string, idleTimeout time.Duration, logConn bool, gaeEndpoint string) (*Database, error) {
pool := &redis.Pool{
Dial: newDBDialer(serverURI, logConn),
MaxIdle: 10,
IdleTimeout: idleTimeout,
}
var rc *remote_api.Client
if gaeEndpoint != "" {
var err error
if rc, err = newRemot... | [
"func",
"New",
"(",
"serverURI",
"string",
",",
"idleTimeout",
"time",
".",
"Duration",
",",
"logConn",
"bool",
",",
"gaeEndpoint",
"string",
")",
"(",
"*",
"Database",
",",
"error",
")",
"{",
"pool",
":=",
"&",
"redis",
".",
"Pool",
"{",
"Dial",
":",
... | // New creates a gddo database. serverURI, idleTimeout, and logConn configure
// the use of redis. gaeEndpoint is the target of the App Engine remoteapi
// endpoint. | [
"New",
"creates",
"a",
"gddo",
"database",
".",
"serverURI",
"idleTimeout",
"and",
"logConn",
"configure",
"the",
"use",
"of",
"redis",
".",
"gaeEndpoint",
"is",
"the",
"target",
"of",
"the",
"App",
"Engine",
"remoteapi",
"endpoint",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L140-L158 |
27,681 | golang/gddo | database/database.go | pkgIDAndImportCount | func pkgIDAndImportCount(c redis.Conn, path string) (id string, numImported int, err error) {
numImported, err = redis.Int(c.Do("SCARD", "index:import:"+path))
if err != nil {
return
}
id, err = redis.String(c.Do("HGET", "ids", path))
if err == redis.ErrNil {
return "", 0, nil
} else if err != nil {
return ... | go | func pkgIDAndImportCount(c redis.Conn, path string) (id string, numImported int, err error) {
numImported, err = redis.Int(c.Do("SCARD", "index:import:"+path))
if err != nil {
return
}
id, err = redis.String(c.Do("HGET", "ids", path))
if err == redis.ErrNil {
return "", 0, nil
} else if err != nil {
return ... | [
"func",
"pkgIDAndImportCount",
"(",
"c",
"redis",
".",
"Conn",
",",
"path",
"string",
")",
"(",
"id",
"string",
",",
"numImported",
"int",
",",
"err",
"error",
")",
"{",
"numImported",
",",
"err",
"=",
"redis",
".",
"Int",
"(",
"c",
".",
"Do",
"(",
... | // pkgIDAndImportCount returns the ID and import count of a specified package. | [
"pkgIDAndImportCount",
"returns",
"the",
"ID",
"and",
"import",
"count",
"of",
"a",
"specified",
"package",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L363-L375 |
27,682 | golang/gddo | database/database.go | SetNextCrawl | func (db *Database) SetNextCrawl(path string, t time.Time) error {
c := db.Pool.Get()
defer c.Close()
_, err := setNextCrawlScript.Do(c, path, t.Unix())
return err
} | go | func (db *Database) SetNextCrawl(path string, t time.Time) error {
c := db.Pool.Get()
defer c.Close()
_, err := setNextCrawlScript.Do(c, path, t.Unix())
return err
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"SetNextCrawl",
"(",
"path",
"string",
",",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"c",
":=",
"db",
".",
"Pool",
".",
"Get",
"(",
")",
"\n",
"defer",
"c",
".",
"Close",
"(",
")",
"\n",
"_",
",",
... | // SetNextCrawl sets the next crawl time for a package. | [
"SetNextCrawl",
"sets",
"the",
"next",
"crawl",
"time",
"for",
"a",
"package",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L422-L427 |
27,683 | golang/gddo | database/database.go | Get | func (db *Database) Get(ctx context.Context, path string) (*doc.Package, []Package, time.Time, error) {
c := db.Pool.Get()
defer c.Close()
pdoc, nextCrawl, err := db.getDoc(ctx, c, path)
if err != nil {
return nil, nil, time.Time{}, err
}
if pdoc != nil {
// fixup for speclal "-" path.
path = pdoc.ImportP... | go | func (db *Database) Get(ctx context.Context, path string) (*doc.Package, []Package, time.Time, error) {
c := db.Pool.Get()
defer c.Close()
pdoc, nextCrawl, err := db.getDoc(ctx, c, path)
if err != nil {
return nil, nil, time.Time{}, err
}
if pdoc != nil {
// fixup for speclal "-" path.
path = pdoc.ImportP... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
")",
"(",
"*",
"doc",
".",
"Package",
",",
"[",
"]",
"Package",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"c",
":=",
"db",
"."... | // Get gets the package documentation and sub-directories for the the given
// import path. | [
"Get",
"gets",
"the",
"package",
"documentation",
"and",
"sub",
"-",
"directories",
"for",
"the",
"the",
"given",
"import",
"path",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L588-L607 |
27,684 | golang/gddo | database/database.go | Delete | func (db *Database) Delete(ctx context.Context, path string) error {
c := db.Pool.Get()
defer c.Close()
id, err := redis.String(c.Do("HGET", "ids", path))
if err == redis.ErrNil {
return nil
}
if err != nil {
return err
}
if err := db.DeleteIndex(ctx, id); err != nil {
return err
}
_, err = deleteScri... | go | func (db *Database) Delete(ctx context.Context, path string) error {
c := db.Pool.Get()
defer c.Close()
id, err := redis.String(c.Do("HGET", "ids", path))
if err == redis.ErrNil {
return nil
}
if err != nil {
return err
}
if err := db.DeleteIndex(ctx, id); err != nil {
return err
}
_, err = deleteScri... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
")",
"error",
"{",
"c",
":=",
"db",
".",
"Pool",
".",
"Get",
"(",
")",
"\n",
"defer",
"c",
".",
"Close",
"(",
")",
"\n\n",
"id",
",... | // Delete deletes the documentation for the given import path. | [
"Delete",
"deletes",
"the",
"documentation",
"for",
"the",
"given",
"import",
"path",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L635-L652 |
27,685 | golang/gddo | database/database.go | Block | func (db *Database) Block(root string) error {
c := db.Pool.Get()
defer c.Close()
if _, err := c.Do("SADD", "block", root); err != nil {
return err
}
// Remove all packages under the project root.
keys, err := redis.Strings(c.Do("HKEYS", "ids"))
if err != nil {
return err
}
ctx := context.Background()
fo... | go | func (db *Database) Block(root string) error {
c := db.Pool.Get()
defer c.Close()
if _, err := c.Do("SADD", "block", root); err != nil {
return err
}
// Remove all packages under the project root.
keys, err := redis.Strings(c.Do("HKEYS", "ids"))
if err != nil {
return err
}
ctx := context.Background()
fo... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Block",
"(",
"root",
"string",
")",
"error",
"{",
"c",
":=",
"db",
".",
"Pool",
".",
"Get",
"(",
")",
"\n",
"defer",
"c",
".",
"Close",
"(",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"c",
".",
"Do",
"... | // Block puts a domain, repo or package into the block set, removes all the
// packages under it from the database and prevents future crawling from it. | [
"Block",
"puts",
"a",
"domain",
"repo",
"or",
"package",
"into",
"the",
"block",
"set",
"removes",
"all",
"the",
"packages",
"under",
"it",
"from",
"the",
"database",
"and",
"prevents",
"future",
"crawling",
"from",
"it",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L773-L814 |
27,686 | golang/gddo | database/database.go | Do | func (db *Database) Do(f func(*PackageInfo) error) error {
c := db.Pool.Get()
defer c.Close()
cursor := 0
c.Send("SCAN", cursor, "MATCH", "pkg:*")
c.Flush()
for {
// Receive previous SCAN.
values, err := redis.Values(c.Receive())
if err != nil {
return err
}
var keys [][]byte
if _, err := redis.Sca... | go | func (db *Database) Do(f func(*PackageInfo) error) error {
c := db.Pool.Get()
defer c.Close()
cursor := 0
c.Send("SCAN", cursor, "MATCH", "pkg:*")
c.Flush()
for {
// Receive previous SCAN.
values, err := redis.Values(c.Receive())
if err != nil {
return err
}
var keys [][]byte
if _, err := redis.Sca... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Do",
"(",
"f",
"func",
"(",
"*",
"PackageInfo",
")",
"error",
")",
"error",
"{",
"c",
":=",
"db",
".",
"Pool",
".",
"Get",
"(",
")",
"\n",
"defer",
"c",
".",
"Close",
"(",
")",
"\n",
"cursor",
":=",
"... | // Do executes function f for each document in the database. | [
"Do",
"executes",
"function",
"f",
"for",
"each",
"document",
"in",
"the",
"database",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L927-L989 |
27,687 | golang/gddo | database/database.go | Reindex | func (db *Database) Reindex(ctx context.Context) error {
if db.RemoteClient == nil {
return errors.New("database.Reindex: no App Engine endpoint given")
}
c := db.Pool.Get()
defer c.Close()
idx, err := search.Open("packages")
if err != nil {
return fmt.Errorf("database: failed to open packages: %v", err)
}... | go | func (db *Database) Reindex(ctx context.Context) error {
if db.RemoteClient == nil {
return errors.New("database.Reindex: no App Engine endpoint given")
}
c := db.Pool.Get()
defer c.Close()
idx, err := search.Open("packages")
if err != nil {
return fmt.Errorf("database: failed to open packages: %v", err)
}... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Reindex",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"db",
".",
"RemoteClient",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
":=",
"... | // Reindex gets all the packages in database and put them into the search index.
// This will update the search index with the path, synopsis, score, import counts
// of all the packages in the database. | [
"Reindex",
"gets",
"all",
"the",
"packages",
"in",
"database",
"and",
"put",
"them",
"into",
"the",
"search",
"index",
".",
"This",
"will",
"update",
"the",
"search",
"index",
"with",
"the",
"path",
"synopsis",
"score",
"import",
"counts",
"of",
"all",
"th... | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L1238-L1305 |
27,688 | golang/gddo | database/database.go | PutIndex | func (db *Database) PutIndex(ctx context.Context, pdoc *doc.Package, id string, score float64, importCount int) error {
if db.RemoteClient == nil {
return nil
}
return putIndex(db.RemoteClient.NewContext(ctx), pdoc, id, score, importCount)
} | go | func (db *Database) PutIndex(ctx context.Context, pdoc *doc.Package, id string, score float64, importCount int) error {
if db.RemoteClient == nil {
return nil
}
return putIndex(db.RemoteClient.NewContext(ctx), pdoc, id, score, importCount)
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"PutIndex",
"(",
"ctx",
"context",
".",
"Context",
",",
"pdoc",
"*",
"doc",
".",
"Package",
",",
"id",
"string",
",",
"score",
"float64",
",",
"importCount",
"int",
")",
"error",
"{",
"if",
"db",
".",
"RemoteC... | // PutIndex puts a package into App Engine search index. ID is the package ID in the database.
// It is no-op when running locally without setting up remote_api. | [
"PutIndex",
"puts",
"a",
"package",
"into",
"App",
"Engine",
"search",
"index",
".",
"ID",
"is",
"the",
"package",
"ID",
"in",
"the",
"database",
".",
"It",
"is",
"no",
"-",
"op",
"when",
"running",
"locally",
"without",
"setting",
"up",
"remote_api",
".... | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L1316-L1321 |
27,689 | golang/gddo | database/database.go | DeleteIndex | func (db *Database) DeleteIndex(ctx context.Context, id string) error {
if db.RemoteClient == nil {
return nil
}
return deleteIndex(db.RemoteClient.NewContext(ctx), id)
} | go | func (db *Database) DeleteIndex(ctx context.Context, id string) error {
if db.RemoteClient == nil {
return nil
}
return deleteIndex(db.RemoteClient.NewContext(ctx), id)
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"DeleteIndex",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"error",
"{",
"if",
"db",
".",
"RemoteClient",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"deleteIndex",
"(",
... | // DeleteIndex deletes a package from App Engine search index. ID is the package ID in the database.
// It is no-op when running locally without setting up remote_api. | [
"DeleteIndex",
"deletes",
"a",
"package",
"from",
"App",
"Engine",
"search",
"index",
".",
"ID",
"is",
"the",
"package",
"ID",
"in",
"the",
"database",
".",
"It",
"is",
"no",
"-",
"op",
"when",
"running",
"locally",
"without",
"setting",
"up",
"remote_api"... | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L1325-L1330 |
27,690 | golang/gddo | gosrc/gosrc.go | GetPresentation | func GetPresentation(ctx context.Context, client *http.Client, importPath string) (*Presentation, error) {
ext := path.Ext(importPath)
if ext != ".slide" && ext != ".article" {
return nil, NotFoundError{Message: "unknown file extension."}
}
importPath, file := path.Split(importPath)
importPath = strings.TrimSuf... | go | func GetPresentation(ctx context.Context, client *http.Client, importPath string) (*Presentation, error) {
ext := path.Ext(importPath)
if ext != ".slide" && ext != ".article" {
return nil, NotFoundError{Message: "unknown file extension."}
}
importPath, file := path.Split(importPath)
importPath = strings.TrimSuf... | [
"func",
"GetPresentation",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"http",
".",
"Client",
",",
"importPath",
"string",
")",
"(",
"*",
"Presentation",
",",
"error",
")",
"{",
"ext",
":=",
"path",
".",
"Ext",
"(",
"importPath",
")",
"\... | // GetPresentation gets a presentation from the the given path. | [
"GetPresentation",
"gets",
"a",
"presentation",
"from",
"the",
"the",
"given",
"path",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gosrc/gosrc.go#L503-L525 |
27,691 | golang/gddo | gosrc/gosrc.go | GetProject | func GetProject(ctx context.Context, client *http.Client, importPath string) (*Project, error) {
for _, s := range services {
if s.getProject == nil {
continue
}
match, err := s.match(importPath)
if err != nil {
return nil, err
}
if match != nil {
return s.getProject(ctx, client, match)
}
}
re... | go | func GetProject(ctx context.Context, client *http.Client, importPath string) (*Project, error) {
for _, s := range services {
if s.getProject == nil {
continue
}
match, err := s.match(importPath)
if err != nil {
return nil, err
}
if match != nil {
return s.getProject(ctx, client, match)
}
}
re... | [
"func",
"GetProject",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"http",
".",
"Client",
",",
"importPath",
"string",
")",
"(",
"*",
"Project",
",",
"error",
")",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"services",
"{",
"if",
"s",
... | // GetProject gets information about a repository. | [
"GetProject",
"gets",
"information",
"about",
"a",
"repository",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gosrc/gosrc.go#L528-L542 |
27,692 | golang/gddo | gosrc/gosrc.go | MaybeRedirect | func MaybeRedirect(importPath, importComment, resolvedGitHubPath string) error {
switch {
case importComment != "":
// Redirect to import comment, if not already there.
if importPath != importComment {
return NotFoundError{
Message: "not at canonical import path",
Redirect: importComment,
}
}
/... | go | func MaybeRedirect(importPath, importComment, resolvedGitHubPath string) error {
switch {
case importComment != "":
// Redirect to import comment, if not already there.
if importPath != importComment {
return NotFoundError{
Message: "not at canonical import path",
Redirect: importComment,
}
}
/... | [
"func",
"MaybeRedirect",
"(",
"importPath",
",",
"importComment",
",",
"resolvedGitHubPath",
"string",
")",
"error",
"{",
"switch",
"{",
"case",
"importComment",
"!=",
"\"",
"\"",
":",
"// Redirect to import comment, if not already there.",
"if",
"importPath",
"!=",
"... | // MaybeRedirect uses the provided import path, import comment, and resolved GitHub path
// to make a decision of whether to redirect to another, more canonical import path.
// It returns nil error to indicate no redirect, or a NotFoundError error to redirect. | [
"MaybeRedirect",
"uses",
"the",
"provided",
"import",
"path",
"import",
"comment",
"and",
"resolved",
"GitHub",
"path",
"to",
"make",
"a",
"decision",
"of",
"whether",
"to",
"redirect",
"to",
"another",
"more",
"canonical",
"import",
"path",
".",
"It",
"return... | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gosrc/gosrc.go#L547-L574 |
27,693 | golang/gddo | gosrc/build.go | Import | func (dir *Directory) Import(ctx *build.Context, mode build.ImportMode) (*build.Package, error) {
safeCopy := *ctx
ctx = &safeCopy
ctx.JoinPath = path.Join
ctx.IsAbsPath = path.IsAbs
ctx.SplitPathList = func(list string) []string { return strings.Split(list, ":") }
ctx.IsDir = func(path string) bool { return path... | go | func (dir *Directory) Import(ctx *build.Context, mode build.ImportMode) (*build.Package, error) {
safeCopy := *ctx
ctx = &safeCopy
ctx.JoinPath = path.Join
ctx.IsAbsPath = path.IsAbs
ctx.SplitPathList = func(list string) []string { return strings.Split(list, ":") }
ctx.IsDir = func(path string) bool { return path... | [
"func",
"(",
"dir",
"*",
"Directory",
")",
"Import",
"(",
"ctx",
"*",
"build",
".",
"Context",
",",
"mode",
"build",
".",
"ImportMode",
")",
"(",
"*",
"build",
".",
"Package",
",",
"error",
")",
"{",
"safeCopy",
":=",
"*",
"ctx",
"\n",
"ctx",
"=",
... | // Import returns details about the package in the directory. | [
"Import",
"returns",
"details",
"about",
"the",
"package",
"in",
"the",
"directory",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gosrc/build.go#L21-L32 |
27,694 | golang/gddo | gddo-server/template.go | getFlashMessages | func getFlashMessages(resp http.ResponseWriter, req *http.Request) []flashMessage {
c, err := req.Cookie("flash")
if err == http.ErrNoCookie {
return nil
}
http.SetCookie(resp, &http.Cookie{Name: "flash", Path: "/", MaxAge: -1, Expires: time.Now().Add(-100 * 24 * time.Hour)})
if err != nil {
return nil
}
p, ... | go | func getFlashMessages(resp http.ResponseWriter, req *http.Request) []flashMessage {
c, err := req.Cookie("flash")
if err == http.ErrNoCookie {
return nil
}
http.SetCookie(resp, &http.Cookie{Name: "flash", Path: "/", MaxAge: -1, Expires: time.Now().Add(-100 * 24 * time.Hour)})
if err != nil {
return nil
}
p, ... | [
"func",
"getFlashMessages",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"[",
"]",
"flashMessage",
"{",
"c",
",",
"err",
":=",
"req",
".",
"Cookie",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"http",
... | // getFlashMessages retrieves flash messages from the request and clears the flash cookie if needed. | [
"getFlashMessages",
"retrieves",
"flash",
"messages",
"from",
"the",
"request",
"and",
"clears",
"the",
"flash",
"cookie",
"if",
"needed",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gddo-server/template.go#L41-L60 |
27,695 | golang/gddo | gddo-server/template.go | setFlashMessages | func setFlashMessages(resp http.ResponseWriter, messages []flashMessage) {
var buf []byte
for i, message := range messages {
if i > 0 {
buf = append(buf, '\000')
}
buf = append(buf, message.ID...)
for _, arg := range message.Args {
buf = append(buf, '\001')
buf = append(buf, arg...)
}
}
value := ... | go | func setFlashMessages(resp http.ResponseWriter, messages []flashMessage) {
var buf []byte
for i, message := range messages {
if i > 0 {
buf = append(buf, '\000')
}
buf = append(buf, message.ID...)
for _, arg := range message.Args {
buf = append(buf, '\001')
buf = append(buf, arg...)
}
}
value := ... | [
"func",
"setFlashMessages",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"messages",
"[",
"]",
"flashMessage",
")",
"{",
"var",
"buf",
"[",
"]",
"byte",
"\n",
"for",
"i",
",",
"message",
":=",
"range",
"messages",
"{",
"if",
"i",
">",
"0",
"{",
"... | // setFlashMessages sets a cookie with the given flash messages. | [
"setFlashMessages",
"sets",
"a",
"cookie",
"with",
"the",
"given",
"flash",
"messages",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gddo-server/template.go#L63-L77 |
27,696 | golang/gddo | gddo-server/template.go | UsesLink | func (pdoc *tdoc) UsesLink(title string, defParts ...string) htemp.HTML {
if pdoc.sourcegraphURL == "" {
return ""
}
var def string
switch len(defParts) {
case 1:
// Funcs and types have one def part.
def = defParts[0]
case 3:
// Methods have three def parts, the original receiver name, actual receiver ... | go | func (pdoc *tdoc) UsesLink(title string, defParts ...string) htemp.HTML {
if pdoc.sourcegraphURL == "" {
return ""
}
var def string
switch len(defParts) {
case 1:
// Funcs and types have one def part.
def = defParts[0]
case 3:
// Methods have three def parts, the original receiver name, actual receiver ... | [
"func",
"(",
"pdoc",
"*",
"tdoc",
")",
"UsesLink",
"(",
"title",
"string",
",",
"defParts",
"...",
"string",
")",
"htemp",
".",
"HTML",
"{",
"if",
"pdoc",
".",
"sourcegraphURL",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"var",
... | // UsesLink generates a link to uses of a symbol definition.
// title is used as the tooltip. defParts are parts of the symbol definition name. | [
"UsesLink",
"generates",
"a",
"link",
"to",
"uses",
"of",
"a",
"symbol",
"definition",
".",
"title",
"is",
"used",
"as",
"the",
"tooltip",
".",
"defParts",
"are",
"parts",
"of",
"the",
"symbol",
"definition",
"name",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gddo-server/template.go#L114-L153 |
27,697 | golang/gddo | gddo-server/template.go | relativePathFn | func relativePathFn(path string, parentPath interface{}) string {
if p, ok := parentPath.(string); ok && p != "" && strings.HasPrefix(path, p) {
path = path[len(p)+1:]
}
return path
} | go | func relativePathFn(path string, parentPath interface{}) string {
if p, ok := parentPath.(string); ok && p != "" && strings.HasPrefix(path, p) {
path = path[len(p)+1:]
}
return path
} | [
"func",
"relativePathFn",
"(",
"path",
"string",
",",
"parentPath",
"interface",
"{",
"}",
")",
"string",
"{",
"if",
"p",
",",
"ok",
":=",
"parentPath",
".",
"(",
"string",
")",
";",
"ok",
"&&",
"p",
"!=",
"\"",
"\"",
"&&",
"strings",
".",
"HasPrefix... | // relativePathFn formats an import path as HTML. | [
"relativePathFn",
"formats",
"an",
"import",
"path",
"as",
"HTML",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gddo-server/template.go#L321-L326 |
27,698 | golang/gddo | gddo-server/template.go | importPathFn | func importPathFn(path string) htemp.HTML {
path = htemp.HTMLEscapeString(path)
if len(path) > 45 {
// Allow long import paths to break following "/"
path = strings.Replace(path, "/", "/​", -1)
}
return htemp.HTML(path)
} | go | func importPathFn(path string) htemp.HTML {
path = htemp.HTMLEscapeString(path)
if len(path) > 45 {
// Allow long import paths to break following "/"
path = strings.Replace(path, "/", "/​", -1)
}
return htemp.HTML(path)
} | [
"func",
"importPathFn",
"(",
"path",
"string",
")",
"htemp",
".",
"HTML",
"{",
"path",
"=",
"htemp",
".",
"HTMLEscapeString",
"(",
"path",
")",
"\n",
"if",
"len",
"(",
"path",
")",
">",
"45",
"{",
"// Allow long import paths to break following \"/\"",
"path",
... | // importPathFn formats an import with zero width space characters to allow for breaks. | [
"importPathFn",
"formats",
"an",
"import",
"with",
"zero",
"width",
"space",
"characters",
"to",
"allow",
"for",
"breaks",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gddo-server/template.go#L329-L336 |
27,699 | golang/gddo | gddo-server/template.go | commentFn | func commentFn(v string) htemp.HTML {
var buf bytes.Buffer
godoc.ToHTML(&buf, v, nil)
p := buf.Bytes()
p = replaceAll(p, h3Pat, func(out, src []byte, m []int) []byte {
out = append(out, `<h4 id="`...)
out = append(out, src[m[2]:m[3]]...)
out = append(out, `">`...)
out = append(out, src[m[4]:m[5]]...)
out ... | go | func commentFn(v string) htemp.HTML {
var buf bytes.Buffer
godoc.ToHTML(&buf, v, nil)
p := buf.Bytes()
p = replaceAll(p, h3Pat, func(out, src []byte, m []int) []byte {
out = append(out, `<h4 id="`...)
out = append(out, src[m[2]:m[3]]...)
out = append(out, `">`...)
out = append(out, src[m[4]:m[5]]...)
out ... | [
"func",
"commentFn",
"(",
"v",
"string",
")",
"htemp",
".",
"HTML",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"godoc",
".",
"ToHTML",
"(",
"&",
"buf",
",",
"v",
",",
"nil",
")",
"\n",
"p",
":=",
"buf",
".",
"Bytes",
"(",
")",
"\n",
"p",
... | // commentFn formats a source code comment as HTML. | [
"commentFn",
"formats",
"a",
"source",
"code",
"comment",
"as",
"HTML",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/gddo-server/template.go#L362-L406 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.