id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
18,300 | yosida95/golang-jenkins | jenkins.go | CreateView | func (jenkins *Jenkins) CreateView(listView ListView) error {
xmlListView, _ := xml.Marshal(listView)
reader := bytes.NewReader(xmlListView)
params := url.Values{"name": []string{listView.Name}}
return jenkins.postXml("/createView", params, reader, nil)
} | go | func (jenkins *Jenkins) CreateView(listView ListView) error {
xmlListView, _ := xml.Marshal(listView)
reader := bytes.NewReader(xmlListView)
params := url.Values{"name": []string{listView.Name}}
return jenkins.postXml("/createView", params, reader, nil)
} | [
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"CreateView",
"(",
"listView",
"ListView",
")",
"error",
"{",
"xmlListView",
",",
"_",
":=",
"xml",
".",
"Marshal",
"(",
"listView",
")",
"\n",
"reader",
":=",
"bytes",
".",
"NewReader",
"(",
"xmlListView",
")... | // Create a new view | [
"Create",
"a",
"new",
"view"
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L256-L262 |
18,301 | yosida95/golang-jenkins | jenkins.go | Build | func (jenkins *Jenkins) Build(job Job, params url.Values) error {
if hasParams(job) {
return jenkins.post(fmt.Sprintf("/job/%s/buildWithParameters", job.Name), params, nil)
} else {
return jenkins.post(fmt.Sprintf("/job/%s/build", job.Name), params, nil)
}
} | go | func (jenkins *Jenkins) Build(job Job, params url.Values) error {
if hasParams(job) {
return jenkins.post(fmt.Sprintf("/job/%s/buildWithParameters", job.Name), params, nil)
} else {
return jenkins.post(fmt.Sprintf("/job/%s/build", job.Name), params, nil)
}
} | [
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"Build",
"(",
"job",
"Job",
",",
"params",
"url",
".",
"Values",
")",
"error",
"{",
"if",
"hasParams",
"(",
"job",
")",
"{",
"return",
"jenkins",
".",
"post",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",... | // Create a new build for this job.
// Params can be nil. | [
"Create",
"a",
"new",
"build",
"for",
"this",
"job",
".",
"Params",
"can",
"be",
"nil",
"."
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L266-L272 |
18,302 | yosida95/golang-jenkins | jenkins.go | GetBuildConsoleOutput | func (jenkins *Jenkins) GetBuildConsoleOutput(build Build) ([]byte, error) {
requestUrl := fmt.Sprintf("%s/consoleText", build.Url)
req, err := http.NewRequest("GET", requestUrl, nil)
if err != nil {
return nil, err
}
res, err := jenkins.sendRequest(req)
if err != nil {
return nil, err
}
defer res.Body.Cl... | go | func (jenkins *Jenkins) GetBuildConsoleOutput(build Build) ([]byte, error) {
requestUrl := fmt.Sprintf("%s/consoleText", build.Url)
req, err := http.NewRequest("GET", requestUrl, nil)
if err != nil {
return nil, err
}
res, err := jenkins.sendRequest(req)
if err != nil {
return nil, err
}
defer res.Body.Cl... | [
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetBuildConsoleOutput",
"(",
"build",
"Build",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"requestUrl",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"build",
".",
"Url",
")",
"\n",
"req",
... | // Get the console output from a build. | [
"Get",
"the",
"console",
"output",
"from",
"a",
"build",
"."
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L275-L289 |
18,303 | yosida95/golang-jenkins | jenkins.go | GetQueue | func (jenkins *Jenkins) GetQueue() (queue Queue, err error) {
err = jenkins.get(fmt.Sprintf("/queue"), nil, &queue)
return
} | go | func (jenkins *Jenkins) GetQueue() (queue Queue, err error) {
err = jenkins.get(fmt.Sprintf("/queue"), nil, &queue)
return
} | [
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetQueue",
"(",
")",
"(",
"queue",
"Queue",
",",
"err",
"error",
")",
"{",
"err",
"=",
"jenkins",
".",
"get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
",",
"nil",
",",
"&",
"queue",
")",
"\... | // GetQueue returns the current build queue from Jenkins | [
"GetQueue",
"returns",
"the",
"current",
"build",
"queue",
"from",
"Jenkins"
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L292-L295 |
18,304 | yosida95/golang-jenkins | jenkins.go | SetBuildDescription | func (jenkins *Jenkins) SetBuildDescription(build Build, description string) error {
requestUrl := fmt.Sprintf("%ssubmitDescription?description=%s", build.Url, url.QueryEscape(description))
req, err := http.NewRequest("GET", requestUrl, nil)
if err != nil {
return err
}
res, err := jenkins.sendRequest(req)
if ... | go | func (jenkins *Jenkins) SetBuildDescription(build Build, description string) error {
requestUrl := fmt.Sprintf("%ssubmitDescription?description=%s", build.Url, url.QueryEscape(description))
req, err := http.NewRequest("GET", requestUrl, nil)
if err != nil {
return err
}
res, err := jenkins.sendRequest(req)
if ... | [
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"SetBuildDescription",
"(",
"build",
"Build",
",",
"description",
"string",
")",
"error",
"{",
"requestUrl",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"build",
".",
"Url",
",",
"url",
".",
"QueryEscap... | // SetBuildDescription sets the description of a build | [
"SetBuildDescription",
"sets",
"the",
"description",
"of",
"a",
"build"
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L315-L333 |
18,305 | yosida95/golang-jenkins | jenkins.go | GetComputerObject | func (jenkins *Jenkins) GetComputerObject() (co ComputerObject, err error) {
err = jenkins.get(fmt.Sprintf("/computer"), nil, &co)
return
} | go | func (jenkins *Jenkins) GetComputerObject() (co ComputerObject, err error) {
err = jenkins.get(fmt.Sprintf("/computer"), nil, &co)
return
} | [
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetComputerObject",
"(",
")",
"(",
"co",
"ComputerObject",
",",
"err",
"error",
")",
"{",
"err",
"=",
"jenkins",
".",
"get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
",",
"nil",
",",
"&",
"co",... | // GetComputerObject returns the main ComputerObject | [
"GetComputerObject",
"returns",
"the",
"main",
"ComputerObject"
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L336-L339 |
18,306 | yosida95/golang-jenkins | jenkins.go | GetComputers | func (jenkins *Jenkins) GetComputers() ([]Computer, error) {
var payload = struct {
Computers []Computer `json:"computer"`
}{}
err := jenkins.get("/computer", nil, &payload)
return payload.Computers, err
} | go | func (jenkins *Jenkins) GetComputers() ([]Computer, error) {
var payload = struct {
Computers []Computer `json:"computer"`
}{}
err := jenkins.get("/computer", nil, &payload)
return payload.Computers, err
} | [
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetComputers",
"(",
")",
"(",
"[",
"]",
"Computer",
",",
"error",
")",
"{",
"var",
"payload",
"=",
"struct",
"{",
"Computers",
"[",
"]",
"Computer",
"`json:\"computer\"`",
"\n",
"}",
"{",
"}",
"\n",
"err",
... | // GetComputers returns the list of all Computer objects | [
"GetComputers",
"returns",
"the",
"list",
"of",
"all",
"Computer",
"objects"
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L342-L348 |
18,307 | yosida95/golang-jenkins | jenkins.go | GetComputer | func (jenkins *Jenkins) GetComputer(name string) (computer Computer, err error) {
err = jenkins.get(fmt.Sprintf("/computer/%s", name), nil, &computer)
return
} | go | func (jenkins *Jenkins) GetComputer(name string) (computer Computer, err error) {
err = jenkins.get(fmt.Sprintf("/computer/%s", name), nil, &computer)
return
} | [
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetComputer",
"(",
"name",
"string",
")",
"(",
"computer",
"Computer",
",",
"err",
"error",
")",
"{",
"err",
"=",
"jenkins",
".",
"get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
",... | // GetComputer returns a Computer object with a specified name. | [
"GetComputer",
"returns",
"a",
"Computer",
"object",
"with",
"a",
"specified",
"name",
"."
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L351-L354 |
18,308 | yosida95/golang-jenkins | jenkins.go | hasParams | func hasParams(job Job) bool {
for _, action := range job.Actions {
if len(action.ParameterDefinitions) > 0 {
return true
}
}
return false
} | go | func hasParams(job Job) bool {
for _, action := range job.Actions {
if len(action.ParameterDefinitions) > 0 {
return true
}
}
return false
} | [
"func",
"hasParams",
"(",
"job",
"Job",
")",
"bool",
"{",
"for",
"_",
",",
"action",
":=",
"range",
"job",
".",
"Actions",
"{",
"if",
"len",
"(",
"action",
".",
"ParameterDefinitions",
")",
">",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n... | // hasParams returns a boolean value indicating if the job is parameterized | [
"hasParams",
"returns",
"a",
"boolean",
"value",
"indicating",
"if",
"the",
"job",
"is",
"parameterized"
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L357-L364 |
18,309 | yosida95/golang-jenkins | job.go | UnmarshalXML | func (iscm *Scm) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for _, v := range start.Attr {
if v.Name.Local == "class" {
iscm.Class = v.Value
} else if v.Name.Local == "plugin" {
iscm.Plugin = v.Value
}
}
switch iscm.Class {
case "hudson.scm.SubversionSCM":
iscm.ScmContent = &ScmSvn{}... | go | func (iscm *Scm) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for _, v := range start.Attr {
if v.Name.Local == "class" {
iscm.Class = v.Value
} else if v.Name.Local == "plugin" {
iscm.Plugin = v.Value
}
}
switch iscm.Class {
case "hudson.scm.SubversionSCM":
iscm.ScmContent = &ScmSvn{}... | [
"func",
"(",
"iscm",
"*",
"Scm",
")",
"UnmarshalXML",
"(",
"d",
"*",
"xml",
".",
"Decoder",
",",
"start",
"xml",
".",
"StartElement",
")",
"error",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"start",
".",
"Attr",
"{",
"if",
"v",
".",
"Name",
".",
... | //UnmarshalXML implements xml.UnmarshalXML intrface
//Decode between multiple types of Scm. for now only SVN is supported | [
"UnmarshalXML",
"implements",
"xml",
".",
"UnmarshalXML",
"intrface",
"Decode",
"between",
"multiple",
"types",
"of",
"Scm",
".",
"for",
"now",
"only",
"SVN",
"is",
"supported"
] | 4772716c47ca769dea7f92bc28dc607eeb16d8a8 | https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/job.go#L258-L281 |
18,310 | teambition/gear | response.go | Get | func (r *Response) Get(key string) string {
return r.handlerHeader.Get(key)
} | go | func (r *Response) Get(key string) string {
return r.handlerHeader.Get(key)
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Get",
"(",
"key",
"string",
")",
"string",
"{",
"return",
"r",
".",
"handlerHeader",
".",
"Get",
"(",
"key",
")",
"\n",
"}"
] | // Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "". To access multiple values of a key, access the map directly with CanonicalHeaderKey. | [
"Get",
"gets",
"the",
"first",
"value",
"associated",
"with",
"the",
"given",
"key",
".",
"If",
"there",
"are",
"no",
"values",
"associated",
"with",
"the",
"key",
"Get",
"returns",
".",
"To",
"access",
"multiple",
"values",
"of",
"a",
"key",
"access",
"... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/response.go#L30-L32 |
18,311 | teambition/gear | const.go | ErrByStatus | func ErrByStatus(status int) *Error {
switch status {
case 400:
return ErrBadRequest
case 401:
return ErrUnauthorized
case 402:
return ErrPaymentRequired
case 403:
return ErrForbidden
case 404:
return ErrNotFound
case 405:
return ErrMethodNotAllowed
case 406:
return ErrNotAcceptable
case 407:
r... | go | func ErrByStatus(status int) *Error {
switch status {
case 400:
return ErrBadRequest
case 401:
return ErrUnauthorized
case 402:
return ErrPaymentRequired
case 403:
return ErrForbidden
case 404:
return ErrNotFound
case 405:
return ErrMethodNotAllowed
case 406:
return ErrNotAcceptable
case 407:
r... | [
"func",
"ErrByStatus",
"(",
"status",
"int",
")",
"*",
"Error",
"{",
"switch",
"status",
"{",
"case",
"400",
":",
"return",
"ErrBadRequest",
"\n",
"case",
"401",
":",
"return",
"ErrUnauthorized",
"\n",
"case",
"402",
":",
"return",
"ErrPaymentRequired",
"\n"... | // ErrByStatus returns a gear.Error by http status. | [
"ErrByStatus",
"returns",
"a",
"gear",
".",
"Error",
"by",
"http",
"status",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/const.go#L160-L245 |
18,312 | teambition/gear | router.go | Use | func (r *Router) Use(handle Middleware) *Router {
r.mds = append(r.mds, handle)
r.middleware = Compose(r.mds...)
return r
} | go | func (r *Router) Use(handle Middleware) *Router {
r.mds = append(r.mds, handle)
r.middleware = Compose(r.mds...)
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Use",
"(",
"handle",
"Middleware",
")",
"*",
"Router",
"{",
"r",
".",
"mds",
"=",
"append",
"(",
"r",
".",
"mds",
",",
"handle",
")",
"\n",
"r",
".",
"middleware",
"=",
"Compose",
"(",
"r",
".",
"mds",
"..... | // Use registers a new Middleware in the router, that will be called when router mathed. | [
"Use",
"registers",
"a",
"new",
"Middleware",
"in",
"the",
"router",
"that",
"will",
"be",
"called",
"when",
"router",
"mathed",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L195-L199 |
18,313 | teambition/gear | router.go | Get | func (r *Router) Get(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodGet, pattern, handlers...)
} | go | func (r *Router) Get(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodGet, pattern, handlers...)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Get",
"(",
"pattern",
"string",
",",
"handlers",
"...",
"Middleware",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Handle",
"(",
"http",
".",
"MethodGet",
",",
"pattern",
",",
"handlers",
"...",
")",
"\n",
"}"
... | // Get registers a new GET route for a path with matching handler in the router. | [
"Get",
"registers",
"a",
"new",
"GET",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"router",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L220-L222 |
18,314 | teambition/gear | router.go | Head | func (r *Router) Head(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodHead, pattern, handlers...)
} | go | func (r *Router) Head(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodHead, pattern, handlers...)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Head",
"(",
"pattern",
"string",
",",
"handlers",
"...",
"Middleware",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Handle",
"(",
"http",
".",
"MethodHead",
",",
"pattern",
",",
"handlers",
"...",
")",
"\n",
"}... | // Head registers a new HEAD route for a path with matching handler in the router. | [
"Head",
"registers",
"a",
"new",
"HEAD",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"router",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L225-L227 |
18,315 | teambition/gear | router.go | Post | func (r *Router) Post(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodPost, pattern, handlers...)
} | go | func (r *Router) Post(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodPost, pattern, handlers...)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Post",
"(",
"pattern",
"string",
",",
"handlers",
"...",
"Middleware",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Handle",
"(",
"http",
".",
"MethodPost",
",",
"pattern",
",",
"handlers",
"...",
")",
"\n",
"}... | // Post registers a new POST route for a path with matching handler in the router. | [
"Post",
"registers",
"a",
"new",
"POST",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"router",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L230-L232 |
18,316 | teambition/gear | router.go | Put | func (r *Router) Put(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodPut, pattern, handlers...)
} | go | func (r *Router) Put(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodPut, pattern, handlers...)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Put",
"(",
"pattern",
"string",
",",
"handlers",
"...",
"Middleware",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Handle",
"(",
"http",
".",
"MethodPut",
",",
"pattern",
",",
"handlers",
"...",
")",
"\n",
"}"
... | // Put registers a new PUT route for a path with matching handler in the router. | [
"Put",
"registers",
"a",
"new",
"PUT",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"router",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L235-L237 |
18,317 | teambition/gear | router.go | Patch | func (r *Router) Patch(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodPatch, pattern, handlers...)
} | go | func (r *Router) Patch(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodPatch, pattern, handlers...)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Patch",
"(",
"pattern",
"string",
",",
"handlers",
"...",
"Middleware",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Handle",
"(",
"http",
".",
"MethodPatch",
",",
"pattern",
",",
"handlers",
"...",
")",
"\n",
... | // Patch registers a new PATCH route for a path with matching handler in the router. | [
"Patch",
"registers",
"a",
"new",
"PATCH",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"router",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L240-L242 |
18,318 | teambition/gear | router.go | Delete | func (r *Router) Delete(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodDelete, pattern, handlers...)
} | go | func (r *Router) Delete(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodDelete, pattern, handlers...)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Delete",
"(",
"pattern",
"string",
",",
"handlers",
"...",
"Middleware",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Handle",
"(",
"http",
".",
"MethodDelete",
",",
"pattern",
",",
"handlers",
"...",
")",
"\n",
... | // Delete registers a new DELETE route for a path with matching handler in the router. | [
"Delete",
"registers",
"a",
"new",
"DELETE",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"router",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L245-L247 |
18,319 | teambition/gear | router.go | Options | func (r *Router) Options(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodOptions, pattern, handlers...)
} | go | func (r *Router) Options(pattern string, handlers ...Middleware) *Router {
return r.Handle(http.MethodOptions, pattern, handlers...)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Options",
"(",
"pattern",
"string",
",",
"handlers",
"...",
"Middleware",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Handle",
"(",
"http",
".",
"MethodOptions",
",",
"pattern",
",",
"handlers",
"...",
")",
"\n"... | // Options registers a new OPTIONS route for a path with matching handler in the router. | [
"Options",
"registers",
"a",
"new",
"OPTIONS",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"router",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L250-L252 |
18,320 | teambition/gear | router.go | Otherwise | func (r *Router) Otherwise(handlers ...Middleware) *Router {
if len(handlers) == 0 {
panic(Err.WithMsg("invalid middleware"))
}
r.otherwise = Compose(handlers...)
return r
} | go | func (r *Router) Otherwise(handlers ...Middleware) *Router {
if len(handlers) == 0 {
panic(Err.WithMsg("invalid middleware"))
}
r.otherwise = Compose(handlers...)
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Otherwise",
"(",
"handlers",
"...",
"Middleware",
")",
"*",
"Router",
"{",
"if",
"len",
"(",
"handlers",
")",
"==",
"0",
"{",
"panic",
"(",
"Err",
".",
"WithMsg",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
... | // Otherwise registers a new Middleware handler in the router
// that will run if there is no other handler matching. | [
"Otherwise",
"registers",
"a",
"new",
"Middleware",
"handler",
"in",
"the",
"router",
"that",
"will",
"run",
"if",
"there",
"is",
"no",
"other",
"handler",
"matching",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L256-L262 |
18,321 | teambition/gear | router.go | Serve | func (r *Router) Serve(ctx *Context) error {
path := ctx.Path
method := ctx.Method
var handler Middleware
if !strings.HasPrefix(path, r.root) && path != r.rt {
return nil
}
if path == r.rt {
path = "/"
} else if l := len(r.rt); l > 0 {
path = path[l:]
}
matched := r.trie.Match(path)
if matched.Node ... | go | func (r *Router) Serve(ctx *Context) error {
path := ctx.Path
method := ctx.Method
var handler Middleware
if !strings.HasPrefix(path, r.root) && path != r.rt {
return nil
}
if path == r.rt {
path = "/"
} else if l := len(r.rt); l > 0 {
path = path[l:]
}
matched := r.trie.Match(path)
if matched.Node ... | [
"func",
"(",
"r",
"*",
"Router",
")",
"Serve",
"(",
"ctx",
"*",
"Context",
")",
"error",
"{",
"path",
":=",
"ctx",
".",
"Path",
"\n",
"method",
":=",
"ctx",
".",
"Method",
"\n",
"var",
"handler",
"Middleware",
"\n\n",
"if",
"!",
"strings",
".",
"Ha... | // Serve implemented gear.Handler interface | [
"Serve",
"implemented",
"gear",
".",
"Handler",
"interface"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/router.go#L265-L330 |
18,322 | teambition/gear | middleware/favicon/favicon.go | NewWithIco | func NewWithIco(file []byte, times ...time.Time) gear.Middleware {
modTime := time.Now()
reader := bytes.NewReader(file)
if len(times) > 0 {
modTime = times[0]
}
return func(ctx *gear.Context) (err error) {
if ctx.Path != "/favicon.ico" {
return
}
if ctx.Method != http.MethodGet && ctx.Method != http.M... | go | func NewWithIco(file []byte, times ...time.Time) gear.Middleware {
modTime := time.Now()
reader := bytes.NewReader(file)
if len(times) > 0 {
modTime = times[0]
}
return func(ctx *gear.Context) (err error) {
if ctx.Path != "/favicon.ico" {
return
}
if ctx.Method != http.MethodGet && ctx.Method != http.M... | [
"func",
"NewWithIco",
"(",
"file",
"[",
"]",
"byte",
",",
"times",
"...",
"time",
".",
"Time",
")",
"gear",
".",
"Middleware",
"{",
"modTime",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"reader",
":=",
"bytes",
".",
"NewReader",
"(",
"file",
")",
"\... | // NewWithIco creates a favicon middleware with ico file and a optional modTime. | [
"NewWithIco",
"creates",
"a",
"favicon",
"middleware",
"with",
"ico",
"file",
"and",
"a",
"optional",
"modTime",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/middleware/favicon/favicon.go#L53-L77 |
18,323 | teambition/gear | logging/color.go | colorString | func colorString(code int, str string) string {
return fmt.Sprintf("\x1b[%d;1m%s\x1b[39;22m", code, str)
} | go | func colorString(code int, str string) string {
return fmt.Sprintf("\x1b[%d;1m%s\x1b[39;22m", code, str)
} | [
"func",
"colorString",
"(",
"code",
"int",
",",
"str",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\x1b",
"\\x1b",
"\"",
",",
"code",
",",
"str",
")",
"\n",
"}"
] | // colorString convert a string to a color string with color code. | [
"colorString",
"convert",
"a",
"string",
"to",
"a",
"color",
"string",
"with",
"color",
"code",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/color.go#L34-L36 |
18,324 | teambition/gear | context.go | NewContext | func NewContext(app *App, w http.ResponseWriter, r *http.Request) *Context {
ctx := Context{
app: app,
Req: r,
Res: &Response{w: w, rw: w, handlerHeader: w.Header()},
Host: r.Host,
Method: r.Method,
Path: r.URL.Path,
Cookies: cookie.New(w, r, app.keys...),
kv: make(map[interface{}]interface{... | go | func NewContext(app *App, w http.ResponseWriter, r *http.Request) *Context {
ctx := Context{
app: app,
Req: r,
Res: &Response{w: w, rw: w, handlerHeader: w.Header()},
Host: r.Host,
Method: r.Method,
Path: r.URL.Path,
Cookies: cookie.New(w, r, app.keys...),
kv: make(map[interface{}]interface{... | [
"func",
"NewContext",
"(",
"app",
"*",
"App",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"Context",
"{",
"ctx",
":=",
"Context",
"{",
"app",
":",
"app",
",",
"Req",
":",
"r",
",",
"Res",
":",
"&",
... | // NewContext creates an instance of Context. Export for testing middleware. | [
"NewContext",
"creates",
"an",
"instance",
"of",
"Context",
".",
"Export",
"for",
"testing",
"middleware",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L62-L96 |
18,325 | teambition/gear | context.go | Cancel | func (ctx *Context) Cancel() {
ctx.Res.ended.setTrue() // end the middleware process
ctx.Res.afterHooks = nil
ctx.cancelCtx()
} | go | func (ctx *Context) Cancel() {
ctx.Res.ended.setTrue() // end the middleware process
ctx.Res.afterHooks = nil
ctx.cancelCtx()
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Cancel",
"(",
")",
"{",
"ctx",
".",
"Res",
".",
"ended",
".",
"setTrue",
"(",
")",
"// end the middleware process",
"\n",
"ctx",
".",
"Res",
".",
"afterHooks",
"=",
"nil",
"\n",
"ctx",
".",
"cancelCtx",
"(",
... | // Cancel cancel the ctx and all it' children context.
// The ctx' process will ended too. | [
"Cancel",
"cancel",
"the",
"ctx",
"and",
"all",
"it",
"children",
"context",
".",
"The",
"ctx",
"process",
"will",
"ended",
"too",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L129-L133 |
18,326 | teambition/gear | context.go | WithCancel | func (ctx *Context) WithCancel() (context.Context, context.CancelFunc) {
return context.WithCancel(ctx._ctx)
} | go | func (ctx *Context) WithCancel() (context.Context, context.CancelFunc) {
return context.WithCancel(ctx._ctx)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"WithCancel",
"(",
")",
"(",
"context",
".",
"Context",
",",
"context",
".",
"CancelFunc",
")",
"{",
"return",
"context",
".",
"WithCancel",
"(",
"ctx",
".",
"_ctx",
")",
"\n",
"}"
] | // WithCancel returns a copy of the ctx with a new Done channel.
// The returned context's Done channel is closed when the returned cancel function is called or when the parent context's Done channel is closed, whichever happens first. | [
"WithCancel",
"returns",
"a",
"copy",
"of",
"the",
"ctx",
"with",
"a",
"new",
"Done",
"channel",
".",
"The",
"returned",
"context",
"s",
"Done",
"channel",
"is",
"closed",
"when",
"the",
"returned",
"cancel",
"function",
"is",
"called",
"or",
"when",
"the"... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L137-L139 |
18,327 | teambition/gear | context.go | WithDeadline | func (ctx *Context) WithDeadline(deadline time.Time) (context.Context, context.CancelFunc) {
return context.WithDeadline(ctx._ctx, deadline)
} | go | func (ctx *Context) WithDeadline(deadline time.Time) (context.Context, context.CancelFunc) {
return context.WithDeadline(ctx._ctx, deadline)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"WithDeadline",
"(",
"deadline",
"time",
".",
"Time",
")",
"(",
"context",
".",
"Context",
",",
"context",
".",
"CancelFunc",
")",
"{",
"return",
"context",
".",
"WithDeadline",
"(",
"ctx",
".",
"_ctx",
",",
"de... | // WithDeadline returns a copy of the ctx with the deadline adjusted to be no later than d. | [
"WithDeadline",
"returns",
"a",
"copy",
"of",
"the",
"ctx",
"with",
"the",
"deadline",
"adjusted",
"to",
"be",
"no",
"later",
"than",
"d",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L142-L144 |
18,328 | teambition/gear | context.go | WithValue | func (ctx *Context) WithValue(key, val interface{}) context.Context {
return context.WithValue(ctx._ctx, key, val)
} | go | func (ctx *Context) WithValue(key, val interface{}) context.Context {
return context.WithValue(ctx._ctx, key, val)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"WithValue",
"(",
"key",
",",
"val",
"interface",
"{",
"}",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
".",
"_ctx",
",",
"key",
",",
"val",
")",
"\n",
"}"
] | // WithValue returns a copy of the ctx in which the value associated with key is val. | [
"WithValue",
"returns",
"a",
"copy",
"of",
"the",
"ctx",
"in",
"which",
"the",
"value",
"associated",
"with",
"key",
"is",
"val",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L152-L154 |
18,329 | teambition/gear | context.go | Timing | func (ctx *Context) Timing(dt time.Duration, fn func(context.Context)) (err error) {
ct, cancel := ctx.WithTimeout(dt)
defer cancel()
ch := make(chan error, 1) // not block tryRunTiming
go tryRunTiming(ct, fn, ch)
select {
case <-ct.Done():
err = ct.Err()
case err = <-ch:
}
return
} | go | func (ctx *Context) Timing(dt time.Duration, fn func(context.Context)) (err error) {
ct, cancel := ctx.WithTimeout(dt)
defer cancel()
ch := make(chan error, 1) // not block tryRunTiming
go tryRunTiming(ct, fn, ch)
select {
case <-ct.Done():
err = ct.Err()
case err = <-ch:
}
return
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Timing",
"(",
"dt",
"time",
".",
"Duration",
",",
"fn",
"func",
"(",
"context",
".",
"Context",
")",
")",
"(",
"err",
"error",
")",
"{",
"ct",
",",
"cancel",
":=",
"ctx",
".",
"WithTimeout",
"(",
"dt",
")... | // Timing runs fn with the given time limit. If a call runs for longer than its time limit or panic,
// it will return context.DeadlineExceeded error or panic error. | [
"Timing",
"runs",
"fn",
"with",
"the",
"given",
"time",
"limit",
".",
"If",
"a",
"call",
"runs",
"for",
"longer",
"than",
"its",
"time",
"limit",
"or",
"panic",
"it",
"will",
"return",
"context",
".",
"DeadlineExceeded",
"error",
"or",
"panic",
"error",
... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L195-L208 |
18,330 | teambition/gear | context.go | MustAny | func (ctx *Context) MustAny(any interface{}) interface{} {
val, err := ctx.Any(any)
if err != nil {
panic(err)
}
return val
} | go | func (ctx *Context) MustAny(any interface{}) interface{} {
val, err := ctx.Any(any)
if err != nil {
panic(err)
}
return val
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"MustAny",
"(",
"any",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"val",
",",
"err",
":=",
"ctx",
".",
"Any",
"(",
"any",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
... | // MustAny returns the value on this ctx by key. It is a sugar for ctx.Any,
// If some error occurred, it will panic. | [
"MustAny",
"returns",
"the",
"value",
"on",
"this",
"ctx",
"by",
"key",
".",
"It",
"is",
"a",
"sugar",
"for",
"ctx",
".",
"Any",
"If",
"some",
"error",
"occurred",
"it",
"will",
"panic",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L248-L254 |
18,331 | teambition/gear | context.go | IP | func (ctx *Context) IP(trustedProxy ...bool) net.IP {
trusted := ctx.Setting(SetTrustedProxy).(bool)
if len(trustedProxy) > 0 {
trusted = trustedProxy[0]
}
if trusted {
ip := ctx.Req.Header.Get(HeaderXForwardedFor)
if ip == "" {
ip = ctx.Req.Header.Get(HeaderXRealIP)
} else if i := strings.IndexByte(ip,... | go | func (ctx *Context) IP(trustedProxy ...bool) net.IP {
trusted := ctx.Setting(SetTrustedProxy).(bool)
if len(trustedProxy) > 0 {
trusted = trustedProxy[0]
}
if trusted {
ip := ctx.Req.Header.Get(HeaderXForwardedFor)
if ip == "" {
ip = ctx.Req.Header.Get(HeaderXRealIP)
} else if i := strings.IndexByte(ip,... | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"IP",
"(",
"trustedProxy",
"...",
"bool",
")",
"net",
".",
"IP",
"{",
"trusted",
":=",
"ctx",
".",
"Setting",
"(",
"SetTrustedProxy",
")",
".",
"(",
"bool",
")",
"\n",
"if",
"len",
"(",
"trustedProxy",
")",
... | // IP returns the client's network address based on `X-Forwarded-For`
// or `X-Real-IP` request header. | [
"IP",
"returns",
"the",
"client",
"s",
"network",
"address",
"based",
"on",
"X",
"-",
"Forwarded",
"-",
"For",
"or",
"X",
"-",
"Real",
"-",
"IP",
"request",
"header",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L277-L299 |
18,332 | teambition/gear | context.go | AcceptType | func (ctx *Context) AcceptType(preferred ...string) string {
return negotiator.New(ctx.Req.Header).Type(preferred...)
} | go | func (ctx *Context) AcceptType(preferred ...string) string {
return negotiator.New(ctx.Req.Header).Type(preferred...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"AcceptType",
"(",
"preferred",
"...",
"string",
")",
"string",
"{",
"return",
"negotiator",
".",
"New",
"(",
"ctx",
".",
"Req",
".",
"Header",
")",
".",
"Type",
"(",
"preferred",
"...",
")",
"\n",
"}"
] | // AcceptType returns the most preferred content type from the HTTP Accept header.
// If nothing accepted, then empty string is returned. | [
"AcceptType",
"returns",
"the",
"most",
"preferred",
"content",
"type",
"from",
"the",
"HTTP",
"Accept",
"header",
".",
"If",
"nothing",
"accepted",
"then",
"empty",
"string",
"is",
"returned",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L317-L319 |
18,333 | teambition/gear | context.go | AcceptLanguage | func (ctx *Context) AcceptLanguage(preferred ...string) string {
return negotiator.New(ctx.Req.Header).Language(preferred...)
} | go | func (ctx *Context) AcceptLanguage(preferred ...string) string {
return negotiator.New(ctx.Req.Header).Language(preferred...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"AcceptLanguage",
"(",
"preferred",
"...",
"string",
")",
"string",
"{",
"return",
"negotiator",
".",
"New",
"(",
"ctx",
".",
"Req",
".",
"Header",
")",
".",
"Language",
"(",
"preferred",
"...",
")",
"\n",
"}"
] | // AcceptLanguage returns the most preferred language from the HTTP Accept-Language header.
// If nothing accepted, then empty string is returned. | [
"AcceptLanguage",
"returns",
"the",
"most",
"preferred",
"language",
"from",
"the",
"HTTP",
"Accept",
"-",
"Language",
"header",
".",
"If",
"nothing",
"accepted",
"then",
"empty",
"string",
"is",
"returned",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L323-L325 |
18,334 | teambition/gear | context.go | AcceptEncoding | func (ctx *Context) AcceptEncoding(preferred ...string) string {
return negotiator.New(ctx.Req.Header).Encoding(preferred...)
} | go | func (ctx *Context) AcceptEncoding(preferred ...string) string {
return negotiator.New(ctx.Req.Header).Encoding(preferred...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"AcceptEncoding",
"(",
"preferred",
"...",
"string",
")",
"string",
"{",
"return",
"negotiator",
".",
"New",
"(",
"ctx",
".",
"Req",
".",
"Header",
")",
".",
"Encoding",
"(",
"preferred",
"...",
")",
"\n",
"}"
] | // AcceptEncoding returns the most preferred encoding from the HTTP Accept-Encoding header.
// If nothing accepted, then empty string is returned. | [
"AcceptEncoding",
"returns",
"the",
"most",
"preferred",
"encoding",
"from",
"the",
"HTTP",
"Accept",
"-",
"Encoding",
"header",
".",
"If",
"nothing",
"accepted",
"then",
"empty",
"string",
"is",
"returned",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L329-L331 |
18,335 | teambition/gear | context.go | AcceptCharset | func (ctx *Context) AcceptCharset(preferred ...string) string {
return negotiator.New(ctx.Req.Header).Charset(preferred...)
} | go | func (ctx *Context) AcceptCharset(preferred ...string) string {
return negotiator.New(ctx.Req.Header).Charset(preferred...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"AcceptCharset",
"(",
"preferred",
"...",
"string",
")",
"string",
"{",
"return",
"negotiator",
".",
"New",
"(",
"ctx",
".",
"Req",
".",
"Header",
")",
".",
"Charset",
"(",
"preferred",
"...",
")",
"\n",
"}"
] | // AcceptCharset returns the most preferred charset from the HTTP Accept-Charset header.
// If nothing accepted, then empty string is returned. | [
"AcceptCharset",
"returns",
"the",
"most",
"preferred",
"charset",
"from",
"the",
"HTTP",
"Accept",
"-",
"Charset",
"header",
".",
"If",
"nothing",
"accepted",
"then",
"empty",
"string",
"is",
"returned",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L335-L337 |
18,336 | teambition/gear | context.go | Query | func (ctx *Context) Query(name string) string {
if ctx.query == nil {
ctx.query = ctx.Req.URL.Query()
}
return ctx.query.Get(name)
} | go | func (ctx *Context) Query(name string) string {
if ctx.query == nil {
ctx.query = ctx.Req.URL.Query()
}
return ctx.query.Get(name)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Query",
"(",
"name",
"string",
")",
"string",
"{",
"if",
"ctx",
".",
"query",
"==",
"nil",
"{",
"ctx",
".",
"query",
"=",
"ctx",
".",
"Req",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"}",
"\n",
"return"... | // Query returns the query param for the provided name. | [
"Query",
"returns",
"the",
"query",
"param",
"for",
"the",
"provided",
"name",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L348-L353 |
18,337 | teambition/gear | context.go | Set | func (ctx *Context) Set(key, value string) {
ctx.SetHeader(key, value)
} | go | func (ctx *Context) Set(key, value string) {
ctx.SetHeader(key, value)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Set",
"(",
"key",
",",
"value",
"string",
")",
"{",
"ctx",
".",
"SetHeader",
"(",
"key",
",",
"value",
")",
"\n",
"}"
] | // Set - Please use ctx.SetHeader instead. This method will be changed in v2. | [
"Set",
"-",
"Please",
"use",
"ctx",
".",
"SetHeader",
"instead",
".",
"This",
"method",
"will",
"be",
"changed",
"in",
"v2",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L484-L486 |
18,338 | teambition/gear | context.go | GetHeader | func (ctx *Context) GetHeader(key string) string {
switch key {
case "Referer", "referer", "Referrer", "referrer":
if val := ctx.Req.Header.Get("Referer"); val != "" {
return val
}
return ctx.Req.Header.Get("Referrer")
default:
return ctx.Req.Header.Get(key)
}
} | go | func (ctx *Context) GetHeader(key string) string {
switch key {
case "Referer", "referer", "Referrer", "referrer":
if val := ctx.Req.Header.Get("Referer"); val != "" {
return val
}
return ctx.Req.Header.Get("Referrer")
default:
return ctx.Req.Header.Get(key)
}
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"GetHeader",
"(",
"key",
"string",
")",
"string",
"{",
"switch",
"key",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"if",
"val",
":=",
"ctx",
".",
"Req",
".",
"Header... | // GetHeader retrieves data from the request Header. | [
"GetHeader",
"retrieves",
"data",
"from",
"the",
"request",
"Header",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L489-L499 |
18,339 | teambition/gear | context.go | HTML | func (ctx *Context) HTML(code int, str string) error {
ctx.Type(MIMETextHTMLCharsetUTF8)
return ctx.End(code, []byte(str))
} | go | func (ctx *Context) HTML(code int, str string) error {
ctx.Type(MIMETextHTMLCharsetUTF8)
return ctx.End(code, []byte(str))
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"HTML",
"(",
"code",
"int",
",",
"str",
"string",
")",
"error",
"{",
"ctx",
".",
"Type",
"(",
"MIMETextHTMLCharsetUTF8",
")",
"\n",
"return",
"ctx",
".",
"End",
"(",
"code",
",",
"[",
"]",
"byte",
"(",
"str"... | // HTML set an Html body with status code to response.
// It will end the ctx. The middlewares after current middleware will not run.
// "after hooks" and "end hooks" will run normally. | [
"HTML",
"set",
"an",
"Html",
"body",
"with",
"status",
"code",
"to",
"response",
".",
"It",
"will",
"end",
"the",
"ctx",
".",
"The",
"middlewares",
"after",
"current",
"middleware",
"will",
"not",
"run",
".",
"after",
"hooks",
"and",
"end",
"hooks",
"wil... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L519-L522 |
18,340 | teambition/gear | context.go | JSONBlob | func (ctx *Context) JSONBlob(code int, buf []byte) error {
ctx.Type(MIMEApplicationJSONCharsetUTF8)
return ctx.End(code, buf)
} | go | func (ctx *Context) JSONBlob(code int, buf []byte) error {
ctx.Type(MIMEApplicationJSONCharsetUTF8)
return ctx.End(code, buf)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"JSONBlob",
"(",
"code",
"int",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"ctx",
".",
"Type",
"(",
"MIMEApplicationJSONCharsetUTF8",
")",
"\n",
"return",
"ctx",
".",
"End",
"(",
"code",
",",
"buf",
")",... | // JSONBlob set a JSON blob body with status code to response.
// It will end the ctx. The middlewares after current middleware will not run.
// "after hooks" and "end hooks" will run normally. | [
"JSONBlob",
"set",
"a",
"JSON",
"blob",
"body",
"with",
"status",
"code",
"to",
"response",
".",
"It",
"will",
"end",
"the",
"ctx",
".",
"The",
"middlewares",
"after",
"current",
"middleware",
"will",
"not",
"run",
".",
"after",
"hooks",
"and",
"end",
"h... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L538-L541 |
18,341 | teambition/gear | context.go | JSONPBlob | func (ctx *Context) JSONPBlob(code int, callback string, buf []byte) error {
ctx.Type(MIMEApplicationJavaScriptCharsetUTF8)
ctx.SetHeader(HeaderXContentTypeOptions, "nosniff")
// the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"
// @see http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosett... | go | func (ctx *Context) JSONPBlob(code int, callback string, buf []byte) error {
ctx.Type(MIMEApplicationJavaScriptCharsetUTF8)
ctx.SetHeader(HeaderXContentTypeOptions, "nosniff")
// the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"
// @see http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosett... | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"JSONPBlob",
"(",
"code",
"int",
",",
"callback",
"string",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"ctx",
".",
"Type",
"(",
"MIMEApplicationJavaScriptCharsetUTF8",
")",
"\n",
"ctx",
".",
"SetHeader",
"("... | // JSONPBlob sends a JSONP blob response with status code. It uses `callback`
// to construct the JSONP payload.
// It will end the ctx. The middlewares after current middleware will not run.
// "after hooks" and "end hooks" will run normally. | [
"JSONPBlob",
"sends",
"a",
"JSONP",
"blob",
"response",
"with",
"status",
"code",
".",
"It",
"uses",
"callback",
"to",
"construct",
"the",
"JSONP",
"payload",
".",
"It",
"will",
"end",
"the",
"ctx",
".",
"The",
"middlewares",
"after",
"current",
"middleware"... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L558-L567 |
18,342 | teambition/gear | context.go | XMLBlob | func (ctx *Context) XMLBlob(code int, buf []byte) error {
ctx.Type(MIMEApplicationXMLCharsetUTF8)
return ctx.End(code, buf)
} | go | func (ctx *Context) XMLBlob(code int, buf []byte) error {
ctx.Type(MIMEApplicationXMLCharsetUTF8)
return ctx.End(code, buf)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"XMLBlob",
"(",
"code",
"int",
",",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"ctx",
".",
"Type",
"(",
"MIMEApplicationXMLCharsetUTF8",
")",
"\n",
"return",
"ctx",
".",
"End",
"(",
"code",
",",
"buf",
")",
... | // XMLBlob set a XML blob body with status code to response.
// It will end the ctx. The middlewares after current middleware will not run.
// "after hooks" and "end hooks" will run normally. | [
"XMLBlob",
"set",
"a",
"XML",
"blob",
"body",
"with",
"status",
"code",
"to",
"response",
".",
"It",
"will",
"end",
"the",
"ctx",
".",
"The",
"middlewares",
"after",
"current",
"middleware",
"will",
"not",
"run",
".",
"after",
"hooks",
"and",
"end",
"hoo... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L583-L586 |
18,343 | teambition/gear | context.go | Stream | func (ctx *Context) Stream(code int, contentType string, r io.Reader) (err error) {
if ctx.Res.ended.swapTrue() {
ctx.Status(code)
ctx.Type(contentType)
_, err = io.Copy(ctx.Res, r)
} else {
err = ErrInternalServerError.WithMsg("request ended before ctx.Stream")
}
return
} | go | func (ctx *Context) Stream(code int, contentType string, r io.Reader) (err error) {
if ctx.Res.ended.swapTrue() {
ctx.Status(code)
ctx.Type(contentType)
_, err = io.Copy(ctx.Res, r)
} else {
err = ErrInternalServerError.WithMsg("request ended before ctx.Stream")
}
return
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Stream",
"(",
"code",
"int",
",",
"contentType",
"string",
",",
"r",
"io",
".",
"Reader",
")",
"(",
"err",
"error",
")",
"{",
"if",
"ctx",
".",
"Res",
".",
"ended",
".",
"swapTrue",
"(",
")",
"{",
"ctx",
... | // Stream sends a streaming response with status code and content type.
// It will end the ctx. The middlewares after current middleware will not run.
// "after hooks" and "end hooks" will run normally. | [
"Stream",
"sends",
"a",
"streaming",
"response",
"with",
"status",
"code",
"and",
"content",
"type",
".",
"It",
"will",
"end",
"the",
"ctx",
".",
"The",
"middlewares",
"after",
"current",
"middleware",
"will",
"not",
"run",
".",
"after",
"hooks",
"and",
"e... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L649-L658 |
18,344 | teambition/gear | context.go | Attachment | func (ctx *Context) Attachment(name string, modtime time.Time, content io.ReadSeeker, inline ...bool) (err error) {
if ctx.Res.ended.swapTrue() {
dispositionType := "attachment"
if len(inline) > 0 && inline[0] {
dispositionType = "inline"
}
ctx.SetHeader(HeaderContentDisposition, ContentDisposition(name, di... | go | func (ctx *Context) Attachment(name string, modtime time.Time, content io.ReadSeeker, inline ...bool) (err error) {
if ctx.Res.ended.swapTrue() {
dispositionType := "attachment"
if len(inline) > 0 && inline[0] {
dispositionType = "inline"
}
ctx.SetHeader(HeaderContentDisposition, ContentDisposition(name, di... | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Attachment",
"(",
"name",
"string",
",",
"modtime",
"time",
".",
"Time",
",",
"content",
"io",
".",
"ReadSeeker",
",",
"inline",
"...",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"if",
"ctx",
".",
"Res",
"... | // Attachment sends a response from `io.ReaderSeeker` as attachment, prompting
// client to save the file. If inline is true, the attachment will sends as inline,
// opening the file in the browser.
// It will end the ctx. The middlewares after current middleware will not run.
// "after hooks" and "end hooks" will run ... | [
"Attachment",
"sends",
"a",
"response",
"from",
"io",
".",
"ReaderSeeker",
"as",
"attachment",
"prompting",
"client",
"to",
"save",
"the",
"file",
".",
"If",
"inline",
"is",
"true",
"the",
"attachment",
"will",
"sends",
"as",
"inline",
"opening",
"the",
"fil... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L665-L677 |
18,345 | teambition/gear | context.go | Redirect | func (ctx *Context) Redirect(url string) (err error) {
if ctx.Res.ended.swapTrue() {
if !isRedirectStatus(ctx.Res.status) {
ctx.Res.status = http.StatusFound
}
http.Redirect(ctx.Res, ctx.Req, url, ctx.Res.status)
} else {
err = ErrInternalServerError.WithMsg("request ended before ctx.Redirect")
}
return
... | go | func (ctx *Context) Redirect(url string) (err error) {
if ctx.Res.ended.swapTrue() {
if !isRedirectStatus(ctx.Res.status) {
ctx.Res.status = http.StatusFound
}
http.Redirect(ctx.Res, ctx.Req, url, ctx.Res.status)
} else {
err = ErrInternalServerError.WithMsg("request ended before ctx.Redirect")
}
return
... | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Redirect",
"(",
"url",
"string",
")",
"(",
"err",
"error",
")",
"{",
"if",
"ctx",
".",
"Res",
".",
"ended",
".",
"swapTrue",
"(",
")",
"{",
"if",
"!",
"isRedirectStatus",
"(",
"ctx",
".",
"Res",
".",
"sta... | // Redirect redirects the request with status code 302.
// You can use other status code with ctx.Status method, It is a wrap of http.Redirect.
// It will end the ctx. The middlewares after current middleware will not run.
// "after hooks" and "end hooks" will run normally. | [
"Redirect",
"redirects",
"the",
"request",
"with",
"status",
"code",
"302",
".",
"You",
"can",
"use",
"other",
"status",
"code",
"with",
"ctx",
".",
"Status",
"method",
"It",
"is",
"a",
"wrap",
"of",
"http",
".",
"Redirect",
".",
"It",
"will",
"end",
"... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L683-L693 |
18,346 | teambition/gear | context.go | OkHTML | func (ctx *Context) OkHTML(str string) error {
return ctx.HTML(http.StatusOK, str)
} | go | func (ctx *Context) OkHTML(str string) error {
return ctx.HTML(http.StatusOK, str)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"OkHTML",
"(",
"str",
"string",
")",
"error",
"{",
"return",
"ctx",
".",
"HTML",
"(",
"http",
".",
"StatusOK",
",",
"str",
")",
"\n",
"}"
] | // OkHTML is a wrap of ctx.HTML with http.StatusOK | [
"OkHTML",
"is",
"a",
"wrap",
"of",
"ctx",
".",
"HTML",
"with",
"http",
".",
"StatusOK"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L696-L698 |
18,347 | teambition/gear | context.go | OkXML | func (ctx *Context) OkXML(val interface{}) error {
return ctx.XML(http.StatusOK, val)
} | go | func (ctx *Context) OkXML(val interface{}) error {
return ctx.XML(http.StatusOK, val)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"OkXML",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"ctx",
".",
"XML",
"(",
"http",
".",
"StatusOK",
",",
"val",
")",
"\n",
"}"
] | // OkXML is a wrap of ctx.XML with http.StatusOK | [
"OkXML",
"is",
"a",
"wrap",
"of",
"ctx",
".",
"XML",
"with",
"http",
".",
"StatusOK"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L708-L710 |
18,348 | teambition/gear | context.go | OkSend | func (ctx *Context) OkSend(val interface{}) error {
return ctx.Send(http.StatusOK, val)
} | go | func (ctx *Context) OkSend(val interface{}) error {
return ctx.Send(http.StatusOK, val)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"OkSend",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"ctx",
".",
"Send",
"(",
"http",
".",
"StatusOK",
",",
"val",
")",
"\n",
"}"
] | // OkSend is a wrap of ctx.Send with http.StatusOK | [
"OkSend",
"is",
"a",
"wrap",
"of",
"ctx",
".",
"Send",
"with",
"http",
".",
"StatusOK"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L713-L715 |
18,349 | teambition/gear | context.go | OkRender | func (ctx *Context) OkRender(name string, val interface{}) error {
return ctx.Render(http.StatusOK, name, val)
} | go | func (ctx *Context) OkRender(name string, val interface{}) error {
return ctx.Render(http.StatusOK, name, val)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"OkRender",
"(",
"name",
"string",
",",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"ctx",
".",
"Render",
"(",
"http",
".",
"StatusOK",
",",
"name",
",",
"val",
")",
"\n",
"}"
] | // OkRender is a wrap of ctx.Render with http.StatusOK | [
"OkRender",
"is",
"a",
"wrap",
"of",
"ctx",
".",
"Render",
"with",
"http",
".",
"StatusOK"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L718-L720 |
18,350 | teambition/gear | context.go | OkStream | func (ctx *Context) OkStream(contentType string, r io.Reader) error {
return ctx.Stream(http.StatusOK, contentType, r)
} | go | func (ctx *Context) OkStream(contentType string, r io.Reader) error {
return ctx.Stream(http.StatusOK, contentType, r)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"OkStream",
"(",
"contentType",
"string",
",",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"return",
"ctx",
".",
"Stream",
"(",
"http",
".",
"StatusOK",
",",
"contentType",
",",
"r",
")",
"\n",
"}"
] | // OkStream is a wrap of ctx.Stream with http.StatusOK | [
"OkStream",
"is",
"a",
"wrap",
"of",
"ctx",
".",
"Stream",
"with",
"http",
".",
"StatusOK"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L723-L725 |
18,351 | teambition/gear | context.go | ErrorStatus | func (ctx *Context) ErrorStatus(status int) error {
if status >= 400 && IsStatusCode(status) {
return ctx.Error(ErrByStatus(status))
}
return ErrInternalServerError.WithMsg("invalid error status")
} | go | func (ctx *Context) ErrorStatus(status int) error {
if status >= 400 && IsStatusCode(status) {
return ctx.Error(ErrByStatus(status))
}
return ErrInternalServerError.WithMsg("invalid error status")
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ErrorStatus",
"(",
"status",
"int",
")",
"error",
"{",
"if",
"status",
">=",
"400",
"&&",
"IsStatusCode",
"(",
"status",
")",
"{",
"return",
"ctx",
".",
"Error",
"(",
"ErrByStatus",
"(",
"status",
")",
")",
"... | // ErrorStatus send a error by status code to response.
// It is sugar of ctx.Error | [
"ErrorStatus",
"send",
"a",
"error",
"by",
"status",
"code",
"to",
"response",
".",
"It",
"is",
"sugar",
"of",
"ctx",
".",
"Error"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L744-L749 |
18,352 | teambition/gear | context.go | End | func (ctx *Context) End(code int, buf ...[]byte) (err error) {
if ctx.Res.ended.swapTrue() {
var body []byte
if len(buf) > 0 {
body = buf[0]
}
err = ctx.Res.respond(code, body)
} else {
err = ErrInternalServerError.WithMsg("request ended before ctx.End")
}
return
} | go | func (ctx *Context) End(code int, buf ...[]byte) (err error) {
if ctx.Res.ended.swapTrue() {
var body []byte
if len(buf) > 0 {
body = buf[0]
}
err = ctx.Res.respond(code, body)
} else {
err = ErrInternalServerError.WithMsg("request ended before ctx.End")
}
return
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"End",
"(",
"code",
"int",
",",
"buf",
"...",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"ctx",
".",
"Res",
".",
"ended",
".",
"swapTrue",
"(",
")",
"{",
"var",
"body",
"[",
"]",
"byte... | // End end the ctx with bytes and status code optionally.
// After it's called, the rest of middleware handles will not run.
// But "after hooks" and "end hooks" will run normally. | [
"End",
"end",
"the",
"ctx",
"with",
"bytes",
"and",
"status",
"code",
"optionally",
".",
"After",
"it",
"s",
"called",
"the",
"rest",
"of",
"middleware",
"handles",
"will",
"not",
"run",
".",
"But",
"after",
"hooks",
"and",
"end",
"hooks",
"will",
"run",... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L754-L765 |
18,353 | teambition/gear | context.go | After | func (ctx *Context) After(hook func()) {
if ctx.Res.ended.isTrue() { // should not add afterHooks if ctx.Res.ended
panic(Err.WithMsg(`can't add "after hook" after middleware process ended`))
}
ctx.Res.afterHooks = append(ctx.Res.afterHooks, hook)
} | go | func (ctx *Context) After(hook func()) {
if ctx.Res.ended.isTrue() { // should not add afterHooks if ctx.Res.ended
panic(Err.WithMsg(`can't add "after hook" after middleware process ended`))
}
ctx.Res.afterHooks = append(ctx.Res.afterHooks, hook)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"After",
"(",
"hook",
"func",
"(",
")",
")",
"{",
"if",
"ctx",
".",
"Res",
".",
"ended",
".",
"isTrue",
"(",
")",
"{",
"// should not add afterHooks if ctx.Res.ended",
"panic",
"(",
"Err",
".",
"WithMsg",
"(",
"... | // After add a "after hook" to the ctx that will run after middleware process,
// but before Response.WriteHeader. So it will block response writing. | [
"After",
"add",
"a",
"after",
"hook",
"to",
"the",
"ctx",
"that",
"will",
"run",
"after",
"middleware",
"process",
"but",
"before",
"Response",
".",
"WriteHeader",
".",
"So",
"it",
"will",
"block",
"response",
"writing",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/context.go#L769-L774 |
18,354 | teambition/gear | middleware/grpc/grpc.go | New | func New(srv http.Handler) gear.Middleware {
return func(ctx *gear.Context) error {
// "application/grpc", "application/grpc+proto"
if strings.HasPrefix(ctx.GetHeader(gear.HeaderContentType), "application/grpc") {
srv.ServeHTTP(ctx.Res, ctx.Req)
ctx.End(204) // Must end with 204 to handle rpc error
}
ret... | go | func New(srv http.Handler) gear.Middleware {
return func(ctx *gear.Context) error {
// "application/grpc", "application/grpc+proto"
if strings.HasPrefix(ctx.GetHeader(gear.HeaderContentType), "application/grpc") {
srv.ServeHTTP(ctx.Res, ctx.Req)
ctx.End(204) // Must end with 204 to handle rpc error
}
ret... | [
"func",
"New",
"(",
"srv",
"http",
".",
"Handler",
")",
"gear",
".",
"Middleware",
"{",
"return",
"func",
"(",
"ctx",
"*",
"gear",
".",
"Context",
")",
"error",
"{",
"// \"application/grpc\", \"application/grpc+proto\"",
"if",
"strings",
".",
"HasPrefix",
"(",... | // New creates a middleware with gRPC server to Handle gRPC requests. | [
"New",
"creates",
"a",
"middleware",
"with",
"gRPC",
"server",
"to",
"Handle",
"gRPC",
"requests",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/middleware/grpc/grpc.go#L11-L20 |
18,355 | teambition/gear | middleware/secure/secure.go | HidePoweredBy | func HidePoweredBy() gear.Middleware {
return func(ctx *gear.Context) error {
ctx.After(func() {
ctx.Res.Header().Del(gear.HeaderXPoweredBy)
})
return nil
}
} | go | func HidePoweredBy() gear.Middleware {
return func(ctx *gear.Context) error {
ctx.After(func() {
ctx.Res.Header().Del(gear.HeaderXPoweredBy)
})
return nil
}
} | [
"func",
"HidePoweredBy",
"(",
")",
"gear",
".",
"Middleware",
"{",
"return",
"func",
"(",
"ctx",
"*",
"gear",
".",
"Context",
")",
"error",
"{",
"ctx",
".",
"After",
"(",
"func",
"(",
")",
"{",
"ctx",
".",
"Res",
".",
"Header",
"(",
")",
".",
"De... | // HidePoweredBy removes the X-Powered-By header to make it slightly harder for
// attackers to see what potentially-vulnerable technology powers your site. | [
"HidePoweredBy",
"removes",
"the",
"X",
"-",
"Powered",
"-",
"By",
"header",
"to",
"make",
"it",
"slightly",
"harder",
"for",
"attackers",
"to",
"see",
"what",
"potentially",
"-",
"vulnerable",
"technology",
"powers",
"your",
"site",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/middleware/secure/secure.go#L119-L126 |
18,356 | teambition/gear | app.go | Parse | func (d DefaultURLParser) Parse(val map[string][]string, body interface{}, tag string) error {
return ValuesToStruct(val, body, tag)
} | go | func (d DefaultURLParser) Parse(val map[string][]string, body interface{}, tag string) error {
return ValuesToStruct(val, body, tag)
} | [
"func",
"(",
"d",
"DefaultURLParser",
")",
"Parse",
"(",
"val",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
",",
"body",
"interface",
"{",
"}",
",",
"tag",
"string",
")",
"error",
"{",
"return",
"ValuesToStruct",
"(",
"val",
",",
"body",
",",
"tag... | // Parse implemented URLParser interface. | [
"Parse",
"implemented",
"URLParser",
"interface",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L46-L48 |
18,357 | teambition/gear | app.go | Parse | func (d DefaultBodyParser) Parse(buf []byte, body interface{}, mediaType, charset string) error {
if len(buf) == 0 {
return ErrBadRequest.WithMsg("request entity empty")
}
switch true {
case mediaType == MIMEApplicationJSON, isLikeMediaType(mediaType, "json"):
err := json.Unmarshal(buf, body)
if err == nil {
... | go | func (d DefaultBodyParser) Parse(buf []byte, body interface{}, mediaType, charset string) error {
if len(buf) == 0 {
return ErrBadRequest.WithMsg("request entity empty")
}
switch true {
case mediaType == MIMEApplicationJSON, isLikeMediaType(mediaType, "json"):
err := json.Unmarshal(buf, body)
if err == nil {
... | [
"func",
"(",
"d",
"DefaultBodyParser",
")",
"Parse",
"(",
"buf",
"[",
"]",
"byte",
",",
"body",
"interface",
"{",
"}",
",",
"mediaType",
",",
"charset",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
"{",
"return",
"ErrBadReque... | // Parse implemented BodyParser interface. | [
"Parse",
"implemented",
"BodyParser",
"interface",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L72-L106 |
18,358 | teambition/gear | app.go | New | func New() *App {
app := new(App)
app.Server = new(http.Server)
app.mds = make(middlewares, 0)
app.settings = make(map[interface{}]interface{})
env := os.Getenv("APP_ENV")
if env == "" {
env = "development"
}
app.Set(SetEnv, env)
app.Set(SetServerName, "Gear/"+Version)
app.Set(SetTrustedProxy, false)
app.... | go | func New() *App {
app := new(App)
app.Server = new(http.Server)
app.mds = make(middlewares, 0)
app.settings = make(map[interface{}]interface{})
env := os.Getenv("APP_ENV")
if env == "" {
env = "development"
}
app.Set(SetEnv, env)
app.Set(SetServerName, "Gear/"+Version)
app.Set(SetTrustedProxy, false)
app.... | [
"func",
"New",
"(",
")",
"*",
"App",
"{",
"app",
":=",
"new",
"(",
"App",
")",
"\n",
"app",
".",
"Server",
"=",
"new",
"(",
"http",
".",
"Server",
")",
"\n",
"app",
".",
"mds",
"=",
"make",
"(",
"middlewares",
",",
"0",
")",
"\n",
"app",
".",... | // New creates an instance of App. | [
"New",
"creates",
"an",
"instance",
"of",
"App",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L152-L175 |
18,359 | teambition/gear | app.go | Use | func (app *App) Use(handle Middleware) *App {
app.mds = append(app.mds, handle)
return app
} | go | func (app *App) Use(handle Middleware) *App {
app.mds = append(app.mds, handle)
return app
} | [
"func",
"(",
"app",
"*",
"App",
")",
"Use",
"(",
"handle",
"Middleware",
")",
"*",
"App",
"{",
"app",
".",
"mds",
"=",
"append",
"(",
"app",
".",
"mds",
",",
"handle",
")",
"\n",
"return",
"app",
"\n",
"}"
] | // Use uses the given middleware `handle`. | [
"Use",
"uses",
"the",
"given",
"middleware",
"handle",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L178-L181 |
18,360 | teambition/gear | app.go | UseHandler | func (app *App) UseHandler(h Handler) *App {
app.mds = append(app.mds, h.Serve)
return app
} | go | func (app *App) UseHandler(h Handler) *App {
app.mds = append(app.mds, h.Serve)
return app
} | [
"func",
"(",
"app",
"*",
"App",
")",
"UseHandler",
"(",
"h",
"Handler",
")",
"*",
"App",
"{",
"app",
".",
"mds",
"=",
"append",
"(",
"app",
".",
"mds",
",",
"h",
".",
"Serve",
")",
"\n",
"return",
"app",
"\n",
"}"
] | // UseHandler uses a instance that implemented Handler interface. | [
"UseHandler",
"uses",
"a",
"instance",
"that",
"implemented",
"Handler",
"interface",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L184-L187 |
18,361 | teambition/gear | app.go | Listen | func (app *App) Listen(addr string) error {
app.Server.Addr = addr
app.Server.ErrorLog = app.logger
app.Server.Handler = app
return app.Server.ListenAndServe()
} | go | func (app *App) Listen(addr string) error {
app.Server.Addr = addr
app.Server.ErrorLog = app.logger
app.Server.Handler = app
return app.Server.ListenAndServe()
} | [
"func",
"(",
"app",
"*",
"App",
")",
"Listen",
"(",
"addr",
"string",
")",
"error",
"{",
"app",
".",
"Server",
".",
"Addr",
"=",
"addr",
"\n",
"app",
".",
"Server",
".",
"ErrorLog",
"=",
"app",
".",
"logger",
"\n",
"app",
".",
"Server",
".",
"Han... | // Listen starts the HTTP server. | [
"Listen",
"starts",
"the",
"HTTP",
"server",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L363-L368 |
18,362 | teambition/gear | app.go | ListenTLS | func (app *App) ListenTLS(addr, certFile, keyFile string) error {
app.Server.Addr = addr
app.Server.ErrorLog = app.logger
app.Server.Handler = app
return app.Server.ListenAndServeTLS(certFile, keyFile)
} | go | func (app *App) ListenTLS(addr, certFile, keyFile string) error {
app.Server.Addr = addr
app.Server.ErrorLog = app.logger
app.Server.Handler = app
return app.Server.ListenAndServeTLS(certFile, keyFile)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"ListenTLS",
"(",
"addr",
",",
"certFile",
",",
"keyFile",
"string",
")",
"error",
"{",
"app",
".",
"Server",
".",
"Addr",
"=",
"addr",
"\n",
"app",
".",
"Server",
".",
"ErrorLog",
"=",
"app",
".",
"logger",
"\n... | // ListenTLS starts the HTTPS server. | [
"ListenTLS",
"starts",
"the",
"HTTPS",
"server",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L371-L376 |
18,363 | teambition/gear | app.go | Error | func (app *App) Error(err interface{}) {
if err := ErrorWithStack(err, 4); err != nil {
str, e := err.Format()
f := app.logger.Flags() == 0
switch {
case f && e == nil:
app.logger.Printf("[%s] ERR %s\n", time.Now().UTC().Format("2006-01-02T15:04:05.999Z"), str)
case f && e != nil:
app.logger.Printf("[%... | go | func (app *App) Error(err interface{}) {
if err := ErrorWithStack(err, 4); err != nil {
str, e := err.Format()
f := app.logger.Flags() == 0
switch {
case f && e == nil:
app.logger.Printf("[%s] ERR %s\n", time.Now().UTC().Format("2006-01-02T15:04:05.999Z"), str)
case f && e != nil:
app.logger.Printf("[%... | [
"func",
"(",
"app",
"*",
"App",
")",
"Error",
"(",
"err",
"interface",
"{",
"}",
")",
"{",
"if",
"err",
":=",
"ErrorWithStack",
"(",
"err",
",",
"4",
")",
";",
"err",
"!=",
"nil",
"{",
"str",
",",
"e",
":=",
"err",
".",
"Format",
"(",
")",
"\... | // Error writes error to underlayer logging system. | [
"Error",
"writes",
"error",
"to",
"underlayer",
"logging",
"system",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L402-L417 |
18,364 | teambition/gear | app.go | Close | func (app *App) Close(ctx ...context.Context) error {
if len(ctx) > 0 {
return app.Server.Shutdown(ctx[0])
}
return app.Server.Close()
} | go | func (app *App) Close(ctx ...context.Context) error {
if len(ctx) > 0 {
return app.Server.Shutdown(ctx[0])
}
return app.Server.Close()
} | [
"func",
"(",
"app",
"*",
"App",
")",
"Close",
"(",
"ctx",
"...",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"len",
"(",
"ctx",
")",
">",
"0",
"{",
"return",
"app",
".",
"Server",
".",
"Shutdown",
"(",
"ctx",
"[",
"0",
"]",
")",
"\n",
... | // Close closes the underlying server.
// If context omit, Server.Close will be used to close immediately.
// Otherwise Server.Shutdown will be used to close gracefully. | [
"Close",
"closes",
"the",
"underlying",
"server",
".",
"If",
"context",
"omit",
"Server",
".",
"Close",
"will",
"be",
"used",
"to",
"close",
"immediately",
".",
"Otherwise",
"Server",
".",
"Shutdown",
"will",
"be",
"used",
"to",
"close",
"gracefully",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/app.go#L468-L473 |
18,365 | teambition/gear | util.go | Compose | func Compose(mds ...Middleware) Middleware {
switch len(mds) {
case 0:
return noOp
case 1:
return mds[0]
default:
return middlewares(mds).run
}
} | go | func Compose(mds ...Middleware) Middleware {
switch len(mds) {
case 0:
return noOp
case 1:
return mds[0]
default:
return middlewares(mds).run
}
} | [
"func",
"Compose",
"(",
"mds",
"...",
"Middleware",
")",
"Middleware",
"{",
"switch",
"len",
"(",
"mds",
")",
"{",
"case",
"0",
":",
"return",
"noOp",
"\n",
"case",
"1",
":",
"return",
"mds",
"[",
"0",
"]",
"\n",
"default",
":",
"return",
"middleware... | // Compose composes a slice of middlewares to one middleware | [
"Compose",
"composes",
"a",
"slice",
"of",
"middlewares",
"to",
"one",
"middleware"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L35-L44 |
18,366 | teambition/gear | util.go | WrapHandler | func WrapHandler(handler http.Handler) Middleware {
return func(ctx *Context) error {
handler.ServeHTTP(ctx.Res, ctx.Req)
return nil
}
} | go | func WrapHandler(handler http.Handler) Middleware {
return func(ctx *Context) error {
handler.ServeHTTP(ctx.Res, ctx.Req)
return nil
}
} | [
"func",
"WrapHandler",
"(",
"handler",
"http",
".",
"Handler",
")",
"Middleware",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"error",
"{",
"handler",
".",
"ServeHTTP",
"(",
"ctx",
".",
"Res",
",",
"ctx",
".",
"Req",
")",
"\n",
"return",
... | // WrapHandler wrap a http.Handler to Gear Middleware | [
"WrapHandler",
"wrap",
"a",
"http",
".",
"Handler",
"to",
"Gear",
"Middleware"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L49-L54 |
18,367 | teambition/gear | util.go | WrapHandlerFunc | func WrapHandlerFunc(fn http.HandlerFunc) Middleware {
return func(ctx *Context) error {
fn(ctx.Res, ctx.Req)
return nil
}
} | go | func WrapHandlerFunc(fn http.HandlerFunc) Middleware {
return func(ctx *Context) error {
fn(ctx.Res, ctx.Req)
return nil
}
} | [
"func",
"WrapHandlerFunc",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"Middleware",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"error",
"{",
"fn",
"(",
"ctx",
".",
"Res",
",",
"ctx",
".",
"Req",
")",
"\n",
"return",
"nil",
"\n",
"}",
... | // WrapHandlerFunc wrap a http.HandlerFunc to Gear Middleware | [
"WrapHandlerFunc",
"wrap",
"a",
"http",
".",
"HandlerFunc",
"to",
"Gear",
"Middleware"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L57-L62 |
18,368 | teambition/gear | util.go | Error | func (err *Error) Error() string {
return fmt.Sprintf("%s: %s", err.Err, err.Msg)
} | go | func (err *Error) Error() string {
return fmt.Sprintf("%s: %s", err.Err, err.Msg)
} | [
"func",
"(",
"err",
"*",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
".",
"Err",
",",
"err",
".",
"Msg",
")",
"\n",
"}"
] | // Error implemented HTTPError interface. | [
"Error",
"implemented",
"HTTPError",
"interface",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L103-L105 |
18,369 | teambition/gear | util.go | Format | func (err Error) Format() (string, error) {
errlog := errorForLog{err.Code, err.Err, err.Msg, err.Data, err.Stack}
res, e := json.Marshal(errlog)
if e == nil {
return string(res), nil
}
return "", e
} | go | func (err Error) Format() (string, error) {
errlog := errorForLog{err.Code, err.Err, err.Msg, err.Data, err.Stack}
res, e := json.Marshal(errlog)
if e == nil {
return string(res), nil
}
return "", e
} | [
"func",
"(",
"err",
"Error",
")",
"Format",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"errlog",
":=",
"errorForLog",
"{",
"err",
".",
"Code",
",",
"err",
".",
"Err",
",",
"err",
".",
"Msg",
",",
"err",
".",
"Data",
",",
"err",
".",
"Stac... | // Format implemented logging.Messager interface. | [
"Format",
"implemented",
"logging",
".",
"Messager",
"interface",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L122-L129 |
18,370 | teambition/gear | util.go | ParseError | func ParseError(e error, code ...int) HTTPError {
if IsNil(e) {
return nil
}
switch v := e.(type) {
case HTTPError:
return v
case *textproto.Error:
err := Err.WithCode(v.Code)
err.Msg = v.Msg
return err
default:
err := ErrInternalServerError.WithMsg(e.Error())
if len(code) > 0 && code[0] > 0 {
e... | go | func ParseError(e error, code ...int) HTTPError {
if IsNil(e) {
return nil
}
switch v := e.(type) {
case HTTPError:
return v
case *textproto.Error:
err := Err.WithCode(v.Code)
err.Msg = v.Msg
return err
default:
err := ErrInternalServerError.WithMsg(e.Error())
if len(code) > 0 && code[0] > 0 {
e... | [
"func",
"ParseError",
"(",
"e",
"error",
",",
"code",
"...",
"int",
")",
"HTTPError",
"{",
"if",
"IsNil",
"(",
"e",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"switch",
"v",
":=",
"e",
".",
"(",
"type",
")",
"{",
"case",
"HTTPError",
":",
"ret... | // ParseError parse a error, textproto.Error or HTTPError to HTTPError | [
"ParseError",
"parse",
"a",
"error",
"textproto",
".",
"Error",
"or",
"HTTPError",
"to",
"HTTPError"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L199-L218 |
18,371 | teambition/gear | util.go | ErrorWithStack | func ErrorWithStack(val interface{}, skip ...int) *Error {
if IsNil(val) {
return nil
}
var err *Error
switch v := val.(type) {
case *Error:
err = v.WithMsg() // must clone, should not change the origin *Error instance
case error:
err = ErrInternalServerError.From(v)
case string:
err = ErrInternalServer... | go | func ErrorWithStack(val interface{}, skip ...int) *Error {
if IsNil(val) {
return nil
}
var err *Error
switch v := val.(type) {
case *Error:
err = v.WithMsg() // must clone, should not change the origin *Error instance
case error:
err = ErrInternalServerError.From(v)
case string:
err = ErrInternalServer... | [
"func",
"ErrorWithStack",
"(",
"val",
"interface",
"{",
"}",
",",
"skip",
"...",
"int",
")",
"*",
"Error",
"{",
"if",
"IsNil",
"(",
"val",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"err",
"*",
"Error",
"\n",
"switch",
"v",
":=",
"val",
... | // ErrorWithStack create a error with stacktrace | [
"ErrorWithStack",
"create",
"a",
"error",
"with",
"stacktrace"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L221-L248 |
18,372 | teambition/gear | util.go | Add | func (s *LoggerFilterWriter) Add(err string) {
if s.out == nil {
panic(Err.WithMsg("output io.Writer should be set with SetOutput method"))
}
s.phrases = append(s.phrases, []byte(err))
} | go | func (s *LoggerFilterWriter) Add(err string) {
if s.out == nil {
panic(Err.WithMsg("output io.Writer should be set with SetOutput method"))
}
s.phrases = append(s.phrases, []byte(err))
} | [
"func",
"(",
"s",
"*",
"LoggerFilterWriter",
")",
"Add",
"(",
"err",
"string",
")",
"{",
"if",
"s",
".",
"out",
"==",
"nil",
"{",
"panic",
"(",
"Err",
".",
"WithMsg",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"s",
".",
"phrases",
"=",
"append... | // Add add a phrase string to filter | [
"Add",
"add",
"a",
"phrase",
"string",
"to",
"filter"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L582-L587 |
18,373 | teambition/gear | util.go | Decompress | func Decompress(encoding string, r io.Reader) (io.ReadCloser, error) {
switch encoding {
case "gzip":
return gzip.NewReader(r)
case "deflate", "zlib":
// compatible for RFC 1950 zlib, RFC 1951 deflate, http://www.open-open.com/lib/view/open1460866410410.html
return zlib.NewReader(r)
default:
return nil, Err... | go | func Decompress(encoding string, r io.Reader) (io.ReadCloser, error) {
switch encoding {
case "gzip":
return gzip.NewReader(r)
case "deflate", "zlib":
// compatible for RFC 1950 zlib, RFC 1951 deflate, http://www.open-open.com/lib/view/open1460866410410.html
return zlib.NewReader(r)
default:
return nil, Err... | [
"func",
"Decompress",
"(",
"encoding",
"string",
",",
"r",
"io",
".",
"Reader",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"switch",
"encoding",
"{",
"case",
"\"",
"\"",
":",
"return",
"gzip",
".",
"NewReader",
"(",
"r",
")",
"\n",
... | // Decompress wrap the reader for decompressing, It support gzip and zlib, and compatible for deflate. | [
"Decompress",
"wrap",
"the",
"reader",
"for",
"decompressing",
"It",
"support",
"gzip",
"and",
"zlib",
"and",
"compatible",
"for",
"deflate",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/util.go#L600-L610 |
18,374 | teambition/gear | middleware/cors/cors.go | New | func New(options ...Options) gear.Middleware {
opts := Options{}
if len(options) > 0 {
opts = options[0]
}
if opts.AllowOrigins == nil {
opts.AllowOrigins = defaultAllowOrigins
}
if opts.AllowMethods == nil {
opts.AllowMethods = defaultAllowMethods
}
if opts.AllowOriginsValidator == nil {
opts.AllowOrig... | go | func New(options ...Options) gear.Middleware {
opts := Options{}
if len(options) > 0 {
opts = options[0]
}
if opts.AllowOrigins == nil {
opts.AllowOrigins = defaultAllowOrigins
}
if opts.AllowMethods == nil {
opts.AllowMethods = defaultAllowMethods
}
if opts.AllowOriginsValidator == nil {
opts.AllowOrig... | [
"func",
"New",
"(",
"options",
"...",
"Options",
")",
"gear",
".",
"Middleware",
"{",
"opts",
":=",
"Options",
"{",
"}",
"\n",
"if",
"len",
"(",
"options",
")",
">",
"0",
"{",
"opts",
"=",
"options",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"opts",
... | // New creates a middleware to provide CORS support for gear. | [
"New",
"creates",
"a",
"middleware",
"to",
"provide",
"CORS",
"support",
"for",
"gear",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/middleware/cors/cors.go#L52-L142 |
18,375 | teambition/gear | logging/logger.go | Format | func (l Log) Format() (string, error) {
res, err := json.Marshal(l)
if err == nil {
return string(res), nil
}
return "", err
} | go | func (l Log) Format() (string, error) {
res, err := json.Marshal(l)
if err == nil {
return string(res), nil
}
return "", err
} | [
"func",
"(",
"l",
"Log",
")",
"Format",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"l",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"string",
"(",
"res",
")",
",",
"nil",
"\n... | // Format try to marshal the structured log with json.Marshal. | [
"Format",
"try",
"to",
"marshal",
"the",
"structured",
"log",
"with",
"json",
".",
"Marshal",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L30-L36 |
18,376 | teambition/gear | logging/logger.go | ParseLevel | func ParseLevel(lvl string) (Level, error) {
switch strings.ToUpper(lvl) {
case "EMERGENCY", "EMERG":
return EmergLevel, nil
case "ALERT":
return AlertLevel, nil
case "CRITICAL", "CRIT", "CRITI":
return CritiLevel, nil
case "ERROR", "ERR":
return ErrLevel, nil
case "WARNING", "WARN":
return WarningLevel... | go | func ParseLevel(lvl string) (Level, error) {
switch strings.ToUpper(lvl) {
case "EMERGENCY", "EMERG":
return EmergLevel, nil
case "ALERT":
return AlertLevel, nil
case "CRITICAL", "CRIT", "CRITI":
return CritiLevel, nil
case "ERROR", "ERR":
return ErrLevel, nil
case "WARNING", "WARN":
return WarningLevel... | [
"func",
"ParseLevel",
"(",
"lvl",
"string",
")",
"(",
"Level",
",",
"error",
")",
"{",
"switch",
"strings",
".",
"ToUpper",
"(",
"lvl",
")",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"EmergLevel",
",",
"nil",
"\n",
"case",
"\"",
"\""... | // ParseLevel takes a string level and returns the gear logging level constant. | [
"ParseLevel",
"takes",
"a",
"string",
"level",
"and",
"returns",
"the",
"gear",
"logging",
"level",
"constant",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L151-L173 |
18,377 | teambition/gear | logging/logger.go | Default | func Default(devMode ...bool) *Logger {
if len(devMode) > 0 && devMode[0] {
std.SetLogConsume(developmentConsume)
}
return std
} | go | func Default(devMode ...bool) *Logger {
if len(devMode) > 0 && devMode[0] {
std.SetLogConsume(developmentConsume)
}
return std
} | [
"func",
"Default",
"(",
"devMode",
"...",
"bool",
")",
"*",
"Logger",
"{",
"if",
"len",
"(",
"devMode",
")",
">",
"0",
"&&",
"devMode",
"[",
"0",
"]",
"{",
"std",
".",
"SetLogConsume",
"(",
"developmentConsume",
")",
"\n",
"}",
"\n",
"return",
"std",... | // Default returns the default logger
// If devMode is true, logger will print a simple version of Common Log Format with terminal color | [
"Default",
"returns",
"the",
"default",
"logger",
"If",
"devMode",
"is",
"true",
"logger",
"will",
"print",
"a",
"simple",
"version",
"of",
"Common",
"Log",
"Format",
"with",
"terminal",
"color"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L179-L184 |
18,378 | teambition/gear | logging/logger.go | Emerg | func (l *Logger) Emerg(v interface{}) {
l.Output(time.Now(), EmergLevel, formatError(v))
} | go | func (l *Logger) Emerg(v interface{}) {
l.Output(time.Now(), EmergLevel, formatError(v))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Emerg",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
",",
"EmergLevel",
",",
"formatError",
"(",
"v",
")",
")",
"\n",
"}"
] | // Emerg produce a "Emergency" log | [
"Emerg",
"produce",
"a",
"Emergency",
"log"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L313-L315 |
18,379 | teambition/gear | logging/logger.go | Alert | func (l *Logger) Alert(v interface{}) {
if l.checkLogLevel(AlertLevel) {
l.Output(time.Now(), AlertLevel, formatError(v))
}
} | go | func (l *Logger) Alert(v interface{}) {
if l.checkLogLevel(AlertLevel) {
l.Output(time.Now(), AlertLevel, formatError(v))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Alert",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"checkLogLevel",
"(",
"AlertLevel",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
",",
"AlertLevel",
",",
"formatError",
... | // Alert produce a "Alert" log | [
"Alert",
"produce",
"a",
"Alert",
"log"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L318-L322 |
18,380 | teambition/gear | logging/logger.go | Crit | func (l *Logger) Crit(v interface{}) {
if l.checkLogLevel(CritiLevel) {
l.Output(time.Now(), CritiLevel, formatError(v))
}
} | go | func (l *Logger) Crit(v interface{}) {
if l.checkLogLevel(CritiLevel) {
l.Output(time.Now(), CritiLevel, formatError(v))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Crit",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"checkLogLevel",
"(",
"CritiLevel",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
",",
"CritiLevel",
",",
"formatError",
"... | // Crit produce a "Critical" log | [
"Crit",
"produce",
"a",
"Critical",
"log"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L325-L329 |
18,381 | teambition/gear | logging/logger.go | Err | func (l *Logger) Err(v interface{}) {
if l.checkLogLevel(ErrLevel) {
l.Output(time.Now(), ErrLevel, formatError(v))
}
} | go | func (l *Logger) Err(v interface{}) {
if l.checkLogLevel(ErrLevel) {
l.Output(time.Now(), ErrLevel, formatError(v))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Err",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"checkLogLevel",
"(",
"ErrLevel",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
",",
"ErrLevel",
",",
"formatError",
"(",
... | // Err produce a "Error" log | [
"Err",
"produce",
"a",
"Error",
"log"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L332-L336 |
18,382 | teambition/gear | logging/logger.go | Warning | func (l *Logger) Warning(v interface{}) {
if l.checkLogLevel(WarningLevel) {
l.Output(time.Now(), WarningLevel, format(v))
}
} | go | func (l *Logger) Warning(v interface{}) {
if l.checkLogLevel(WarningLevel) {
l.Output(time.Now(), WarningLevel, format(v))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Warning",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"checkLogLevel",
"(",
"WarningLevel",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
",",
"WarningLevel",
",",
"format",
... | // Warning produce a "Warning" log | [
"Warning",
"produce",
"a",
"Warning",
"log"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L339-L343 |
18,383 | teambition/gear | logging/logger.go | Notice | func (l *Logger) Notice(v interface{}) {
if l.checkLogLevel(NoticeLevel) {
l.Output(time.Now(), NoticeLevel, format(v))
}
} | go | func (l *Logger) Notice(v interface{}) {
if l.checkLogLevel(NoticeLevel) {
l.Output(time.Now(), NoticeLevel, format(v))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Notice",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"checkLogLevel",
"(",
"NoticeLevel",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
",",
"NoticeLevel",
",",
"format",
"(... | // Notice produce a "Notice" log | [
"Notice",
"produce",
"a",
"Notice",
"log"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L346-L350 |
18,384 | teambition/gear | logging/logger.go | Info | func (l *Logger) Info(v interface{}) {
if l.checkLogLevel(InfoLevel) {
l.Output(time.Now(), InfoLevel, format(v))
}
} | go | func (l *Logger) Info(v interface{}) {
if l.checkLogLevel(InfoLevel) {
l.Output(time.Now(), InfoLevel, format(v))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Info",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"checkLogLevel",
"(",
"InfoLevel",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
",",
"InfoLevel",
",",
"format",
"(",
"... | // Info produce a "Informational" log | [
"Info",
"produce",
"a",
"Informational",
"log"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L353-L357 |
18,385 | teambition/gear | logging/logger.go | Debug | func (l *Logger) Debug(v interface{}) {
if l.checkLogLevel(DebugLevel) {
l.Output(time.Now(), DebugLevel, format(v))
}
} | go | func (l *Logger) Debug(v interface{}) {
if l.checkLogLevel(DebugLevel) {
l.Output(time.Now(), DebugLevel, format(v))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Debug",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"checkLogLevel",
"(",
"DebugLevel",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
",",
"DebugLevel",
",",
"format",
"(",
... | // Debug produce a "Debug" log | [
"Debug",
"produce",
"a",
"Debug",
"log"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L360-L364 |
18,386 | teambition/gear | logging/logger.go | Debugf | func (l *Logger) Debugf(format string, args ...interface{}) {
if l.checkLogLevel(DebugLevel) {
l.Output(time.Now(), DebugLevel, fmt.Sprintf(format, args...))
}
} | go | func (l *Logger) Debugf(format string, args ...interface{}) {
if l.checkLogLevel(DebugLevel) {
l.Output(time.Now(), DebugLevel, fmt.Sprintf(format, args...))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Debugf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"checkLogLevel",
"(",
"DebugLevel",
")",
"{",
"l",
".",
"Output",
"(",
"time",
".",
"Now",
"(",
")",
","... | // Debugf produce a "Debug" log in the manner of fmt.Printf | [
"Debugf",
"produce",
"a",
"Debug",
"log",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Printf"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L367-L371 |
18,387 | teambition/gear | logging/logger.go | Panic | func (l *Logger) Panic(v interface{}) {
s := format(v)
l.Emerg(s)
panic(s)
} | go | func (l *Logger) Panic(v interface{}) {
s := format(v)
l.Emerg(s)
panic(s)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Panic",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"s",
":=",
"format",
"(",
"v",
")",
"\n",
"l",
".",
"Emerg",
"(",
"s",
")",
"\n",
"panic",
"(",
"s",
")",
"\n",
"}"
] | // Panic produce a "Emergency" log and then calls panic with the message | [
"Panic",
"produce",
"a",
"Emergency",
"log",
"and",
"then",
"calls",
"panic",
"with",
"the",
"message"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L374-L378 |
18,388 | teambition/gear | logging/logger.go | Print | func (l *Logger) Print(args ...interface{}) {
l.mu.Lock()
defer l.mu.Unlock()
fmt.Fprint(l.Out, args...)
} | go | func (l *Logger) Print(args ...interface{}) {
l.mu.Lock()
defer l.mu.Unlock()
fmt.Fprint(l.Out, args...)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Print",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"fmt",
".",
"Fprint",
"(",
"l",
".",
"O... | // Print produce a log in the manner of fmt.Print, without timestamp and log level | [
"Print",
"produce",
"a",
"log",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Print",
"without",
"timestamp",
"and",
"log",
"level"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L389-L393 |
18,389 | teambition/gear | logging/logger.go | Printf | func (l *Logger) Printf(format string, args ...interface{}) {
l.mu.Lock()
defer l.mu.Unlock()
fmt.Fprintf(l.Out, format, args...)
} | go | func (l *Logger) Printf(format string, args ...interface{}) {
l.mu.Lock()
defer l.mu.Unlock()
fmt.Fprintf(l.Out, format, args...)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Printf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"fmt",
".",
"Fp... | // Printf produce a log in the manner of fmt.Printf, without timestamp and log level | [
"Printf",
"produce",
"a",
"log",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Printf",
"without",
"timestamp",
"and",
"log",
"level"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L396-L400 |
18,390 | teambition/gear | logging/logger.go | Println | func (l *Logger) Println(args ...interface{}) {
l.mu.Lock()
defer l.mu.Unlock()
fmt.Fprintln(l.Out, args...)
} | go | func (l *Logger) Println(args ...interface{}) {
l.mu.Lock()
defer l.mu.Unlock()
fmt.Fprintln(l.Out, args...)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Println",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"l",
".",
... | // Println produce a log in the manner of fmt.Println, without timestamp and log level | [
"Println",
"produce",
"a",
"log",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Println",
"without",
"timestamp",
"and",
"log",
"level"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L403-L407 |
18,391 | teambition/gear | logging/logger.go | Output | func (l *Logger) Output(t time.Time, level Level, s string) (err error) {
l.mu.Lock()
defer l.mu.Unlock()
if l := len(s); l > 0 && s[l-1] == '\n' {
s = s[0 : l-1]
}
_, err = fmt.Fprintf(l.Out, l.lf, t.UTC().Format(l.tf), level.String(), crlfEscaper.Replace(s))
if err == nil {
l.Out.Write([]byte{'\n'})
}
re... | go | func (l *Logger) Output(t time.Time, level Level, s string) (err error) {
l.mu.Lock()
defer l.mu.Unlock()
if l := len(s); l > 0 && s[l-1] == '\n' {
s = s[0 : l-1]
}
_, err = fmt.Fprintf(l.Out, l.lf, t.UTC().Format(l.tf), level.String(), crlfEscaper.Replace(s))
if err == nil {
l.Out.Write([]byte{'\n'})
}
re... | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Output",
"(",
"t",
"time",
".",
"Time",
",",
"level",
"Level",
",",
"s",
"string",
")",
"(",
"err",
"error",
")",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",... | // Output writes a string log with timestamp and log level to the output.
// If the level is greater than logger level, the log will be omitted.
// The log will be format by timeFormat and logFormat. | [
"Output",
"writes",
"a",
"string",
"log",
"with",
"timestamp",
"and",
"log",
"level",
"to",
"the",
"output",
".",
"If",
"the",
"level",
"is",
"greater",
"than",
"logger",
"level",
"the",
"log",
"will",
"be",
"omitted",
".",
"The",
"log",
"will",
"be",
... | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L412-L424 |
18,392 | teambition/gear | logging/logger.go | GetLevel | func (l *Logger) GetLevel() Level {
l.mu.Lock()
defer l.mu.Unlock()
return l.l
} | go | func (l *Logger) GetLevel() Level {
l.mu.Lock()
defer l.mu.Unlock()
return l.l
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"GetLevel",
"(",
")",
"Level",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"l",
".",
"l",
"\n",
"}"
] | // GetLevel get the logger's log level | [
"GetLevel",
"get",
"the",
"logger",
"s",
"log",
"level"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L427-L431 |
18,393 | teambition/gear | logging/logger.go | SetLevel | func (l *Logger) SetLevel(level Level) *Logger {
l.mu.Lock()
defer l.mu.Unlock()
if level > DebugLevel {
panic(gear.Err.WithMsg("invalid logger level"))
}
l.l = level
return l
} | go | func (l *Logger) SetLevel(level Level) *Logger {
l.mu.Lock()
defer l.mu.Unlock()
if level > DebugLevel {
panic(gear.Err.WithMsg("invalid logger level"))
}
l.l = level
return l
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"SetLevel",
"(",
"level",
"Level",
")",
"*",
"Logger",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"level",
">",
"DebugLevel",
"{",
"panic... | // SetLevel set the logger's log level
// The default logger level is DebugLevel | [
"SetLevel",
"set",
"the",
"logger",
"s",
"log",
"level",
"The",
"default",
"logger",
"level",
"is",
"DebugLevel"
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L435-L443 |
18,394 | teambition/gear | logging/logger.go | SetLogInit | func (l *Logger) SetLogInit(fn func(Log, *gear.Context)) *Logger {
l.mu.Lock()
defer l.mu.Unlock()
l.init = fn
return l
} | go | func (l *Logger) SetLogInit(fn func(Log, *gear.Context)) *Logger {
l.mu.Lock()
defer l.mu.Unlock()
l.init = fn
return l
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"SetLogInit",
"(",
"fn",
"func",
"(",
"Log",
",",
"*",
"gear",
".",
"Context",
")",
")",
"*",
"Logger",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
... | // SetLogInit set a log init handle to the logger.
// It will be called when log created. | [
"SetLogInit",
"set",
"a",
"log",
"init",
"handle",
"to",
"the",
"logger",
".",
"It",
"will",
"be",
"called",
"when",
"log",
"created",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L466-L471 |
18,395 | teambition/gear | logging/logger.go | New | func (l *Logger) New(ctx *gear.Context) (interface{}, error) {
log := Log{}
l.init(log, ctx)
return log, nil
} | go | func (l *Logger) New(ctx *gear.Context) (interface{}, error) {
log := Log{}
l.init(log, ctx)
return log, nil
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"New",
"(",
"ctx",
"*",
"gear",
".",
"Context",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"log",
":=",
"Log",
"{",
"}",
"\n",
"l",
".",
"init",
"(",
"log",
",",
"ctx",
")",
"\n",
"return",
... | // New implements gear.Any interface,then we can use ctx.Any to retrieve a Log instance from ctx.
// Here also some initialization work after created. | [
"New",
"implements",
"gear",
".",
"Any",
"interface",
"then",
"we",
"can",
"use",
"ctx",
".",
"Any",
"to",
"retrieve",
"a",
"Log",
"instance",
"from",
"ctx",
".",
"Here",
"also",
"some",
"initialization",
"work",
"after",
"created",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L489-L493 |
18,396 | teambition/gear | logging/logger.go | FromCtx | func (l *Logger) FromCtx(ctx *gear.Context) Log {
any, _ := ctx.Any(l)
return any.(Log)
} | go | func (l *Logger) FromCtx(ctx *gear.Context) Log {
any, _ := ctx.Any(l)
return any.(Log)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"FromCtx",
"(",
"ctx",
"*",
"gear",
".",
"Context",
")",
"Log",
"{",
"any",
",",
"_",
":=",
"ctx",
".",
"Any",
"(",
"l",
")",
"\n",
"return",
"any",
".",
"(",
"Log",
")",
"\n",
"}"
] | // FromCtx retrieve the Log instance from the ctx with ctx.Any.
// Logger.New and ctx.Any will guarantee it exists. | [
"FromCtx",
"retrieve",
"the",
"Log",
"instance",
"from",
"the",
"ctx",
"with",
"ctx",
".",
"Any",
".",
"Logger",
".",
"New",
"and",
"ctx",
".",
"Any",
"will",
"guarantee",
"it",
"exists",
"."
] | a2c5175e04298aa0918a50d40e95475520e9d78e | https://github.com/teambition/gear/blob/a2c5175e04298aa0918a50d40e95475520e9d78e/logging/logger.go#L497-L500 |
18,397 | ns3777k/go-shodan | shodan/datasets.go | GetDatasets | func (c *Client) GetDatasets(ctx context.Context) ([]*Dataset, error) {
datasets := make([]*Dataset, 0)
req, err := c.NewRequest("GET", datasetsPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &datasets); err != nil {
return nil, err
}
return datasets, nil
} | go | func (c *Client) GetDatasets(ctx context.Context) ([]*Dataset, error) {
datasets := make([]*Dataset, 0)
req, err := c.NewRequest("GET", datasetsPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &datasets); err != nil {
return nil, err
}
return datasets, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetDatasets",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"*",
"Dataset",
",",
"error",
")",
"{",
"datasets",
":=",
"make",
"(",
"[",
"]",
"*",
"Dataset",
",",
"0",
")",
"\n",
"req",
",",
"e... | // GetDatasets provides list of the datasets that are available for download. | [
"GetDatasets",
"provides",
"list",
"of",
"the",
"datasets",
"that",
"are",
"available",
"for",
"download",
"."
] | 1320f6c93371f1828788ee9b7f3fcf568de18142 | https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/datasets.go#L81-L93 |
18,398 | ns3777k/go-shodan | shodan/datasets.go | GetDatasetFiles | func (c *Client) GetDatasetFiles(ctx context.Context, name string) ([]*DatasetFile, error) {
files := make([]*DatasetFile, 0)
path := fmt.Sprintf(datasetFilesPath, name)
req, err := c.NewRequest("GET", path, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &files); err != nil {
return ni... | go | func (c *Client) GetDatasetFiles(ctx context.Context, name string) ([]*DatasetFile, error) {
files := make([]*DatasetFile, 0)
path := fmt.Sprintf(datasetFilesPath, name)
req, err := c.NewRequest("GET", path, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &files); err != nil {
return ni... | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetDatasetFiles",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"[",
"]",
"*",
"DatasetFile",
",",
"error",
")",
"{",
"files",
":=",
"make",
"(",
"[",
"]",
"*",
"DatasetFile",
",",
"0... | // GetDatasetFiles returns a list of files that are available for download from the provided dataset. | [
"GetDatasetFiles",
"returns",
"a",
"list",
"of",
"files",
"that",
"are",
"available",
"for",
"download",
"from",
"the",
"provided",
"dataset",
"."
] | 1320f6c93371f1828788ee9b7f3fcf568de18142 | https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/datasets.go#L96-L110 |
18,399 | ns3777k/go-shodan | shodan/alert.go | GetAlerts | func (c *Client) GetAlerts(ctx context.Context) ([]*Alert, error) {
alerts := make([]*Alert, 0, 0)
req, err := c.NewRequest("GET", alertsInfoListPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &alerts); err != nil {
return nil, err
}
return alerts, err
} | go | func (c *Client) GetAlerts(ctx context.Context) ([]*Alert, error) {
alerts := make([]*Alert, 0, 0)
req, err := c.NewRequest("GET", alertsInfoListPath, nil, nil)
if err != nil {
return nil, err
}
if err := c.Do(ctx, req, &alerts); err != nil {
return nil, err
}
return alerts, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetAlerts",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"*",
"Alert",
",",
"error",
")",
"{",
"alerts",
":=",
"make",
"(",
"[",
"]",
"*",
"Alert",
",",
"0",
",",
"0",
")",
"\n\n",
"req",
"... | // GetAlerts returns a listing of all the network alerts that are currently active on the account. | [
"GetAlerts",
"returns",
"a",
"listing",
"of",
"all",
"the",
"network",
"alerts",
"that",
"are",
"currently",
"active",
"on",
"the",
"account",
"."
] | 1320f6c93371f1828788ee9b7f3fcf568de18142 | https://github.com/ns3777k/go-shodan/blob/1320f6c93371f1828788ee9b7f3fcf568de18142/shodan/alert.go#L68-L81 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.