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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
149,100 | bndr/gojenkins | artifact.go | GetData | func (a Artifact) GetData() ([]byte, error) {
var data string
response, err := a.Jenkins.Requester.Get(a.Path, &data, nil)
if err != nil {
return nil, err
}
code := response.StatusCode
if code != 200 {
Error.Printf("Jenkins responded with StatusCode: %d", code)
return nil, errors.New("Could not get File Contents")
}
return []byte(data), nil
} | go | func (a Artifact) GetData() ([]byte, error) {
var data string
response, err := a.Jenkins.Requester.Get(a.Path, &data, nil)
if err != nil {
return nil, err
}
code := response.StatusCode
if code != 200 {
Error.Printf("Jenkins responded with StatusCode: %d", code)
return nil, errors.New("Could not get File Contents")
}
return []byte(data), nil
} | [
"func",
"(",
"a",
"Artifact",
")",
"GetData",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"data",
"string",
"\n",
"response",
",",
"err",
":=",
"a",
".",
"Jenkins",
".",
"Requester",
".",
"Get",
"(",
"a",
".",
"Path",
",",
"&",
"data",
",",
"nil",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"code",
":=",
"response",
".",
"StatusCode",
"\n",
"if",
"code",
"!=",
"200",
"{",
"Error",
".",
"Printf",
"(",
"\"",
"\"",
",",
"code",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"(",
"data",
")",
",",
"nil",
"\n",
"}"
] | // Get raw byte data of Artifact | [
"Get",
"raw",
"byte",
"data",
"of",
"Artifact"
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/artifact.go#L36-L50 |
149,101 | bndr/gojenkins | artifact.go | Save | func (a Artifact) Save(path string) (bool, error) {
data, err := a.GetData()
if err != nil {
return false, errors.New("No Data received, not saving file.")
}
if _, err = os.Stat(path); err == nil {
Warning.Println("Local Copy already exists, Overwriting...")
}
err = ioutil.WriteFile(path, data, 0644)
a.validateDownload(path)
if err != nil {
return false, err
}
return true, nil
} | go | func (a Artifact) Save(path string) (bool, error) {
data, err := a.GetData()
if err != nil {
return false, errors.New("No Data received, not saving file.")
}
if _, err = os.Stat(path); err == nil {
Warning.Println("Local Copy already exists, Overwriting...")
}
err = ioutil.WriteFile(path, data, 0644)
a.validateDownload(path)
if err != nil {
return false, err
}
return true, nil
} | [
"func",
"(",
"a",
"Artifact",
")",
"Save",
"(",
"path",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"a",
".",
"GetData",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
"=",
"os",
".",
"Stat",
"(",
"path",
")",
";",
"err",
"==",
"nil",
"{",
"Warning",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"ioutil",
".",
"WriteFile",
"(",
"path",
",",
"data",
",",
"0644",
")",
"\n",
"a",
".",
"validateDownload",
"(",
"path",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // Save artifact to a specific path, using your own filename. | [
"Save",
"artifact",
"to",
"a",
"specific",
"path",
"using",
"your",
"own",
"filename",
"."
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/artifact.go#L53-L71 |
149,102 | bndr/gojenkins | artifact.go | SaveToDir | func (a Artifact) SaveToDir(dir string) (bool, error) {
if _, err := os.Stat(dir); err != nil {
Error.Printf("can't save artifact: directory %s does not exist", dir)
return false, fmt.Errorf("can't save artifact: directory %s does not exist", dir)
}
saved, err := a.Save(path.Join(dir, a.FileName))
if err != nil {
return saved, nil
}
return saved, nil
} | go | func (a Artifact) SaveToDir(dir string) (bool, error) {
if _, err := os.Stat(dir); err != nil {
Error.Printf("can't save artifact: directory %s does not exist", dir)
return false, fmt.Errorf("can't save artifact: directory %s does not exist", dir)
}
saved, err := a.Save(path.Join(dir, a.FileName))
if err != nil {
return saved, nil
}
return saved, nil
} | [
"func",
"(",
"a",
"Artifact",
")",
"SaveToDir",
"(",
"dir",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"{",
"Error",
".",
"Printf",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"}",
"\n",
"saved",
",",
"err",
":=",
"a",
".",
"Save",
"(",
"path",
".",
"Join",
"(",
"dir",
",",
"a",
".",
"FileName",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"saved",
",",
"nil",
"\n",
"}",
"\n",
"return",
"saved",
",",
"nil",
"\n",
"}"
] | // Save Artifact to directory using Artifact filename. | [
"Save",
"Artifact",
"to",
"directory",
"using",
"Artifact",
"filename",
"."
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/artifact.go#L74-L84 |
149,103 | bndr/gojenkins | artifact.go | validateDownload | func (a Artifact) validateDownload(path string) (bool, error) {
localHash := a.getMD5local(path)
fp := FingerPrint{Jenkins: a.Jenkins, Base: "/fingerprint/", Id: localHash, Raw: new(FingerPrintResponse)}
valid, err := fp.ValidateForBuild(a.FileName, a.Build)
if err != nil {
return false, err
}
if !valid {
return false, errors.New("FingerPrint of the downloaded artifact could not be verified")
}
return true, nil
} | go | func (a Artifact) validateDownload(path string) (bool, error) {
localHash := a.getMD5local(path)
fp := FingerPrint{Jenkins: a.Jenkins, Base: "/fingerprint/", Id: localHash, Raw: new(FingerPrintResponse)}
valid, err := fp.ValidateForBuild(a.FileName, a.Build)
if err != nil {
return false, err
}
if !valid {
return false, errors.New("FingerPrint of the downloaded artifact could not be verified")
}
return true, nil
} | [
"func",
"(",
"a",
"Artifact",
")",
"validateDownload",
"(",
"path",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"localHash",
":=",
"a",
".",
"getMD5local",
"(",
"path",
")",
"\n\n",
"fp",
":=",
"FingerPrint",
"{",
"Jenkins",
":",
"a",
".",
"Jenkins",
",",
"Base",
":",
"\"",
"\"",
",",
"Id",
":",
"localHash",
",",
"Raw",
":",
"new",
"(",
"FingerPrintResponse",
")",
"}",
"\n\n",
"valid",
",",
"err",
":=",
"fp",
".",
"ValidateForBuild",
"(",
"a",
".",
"FileName",
",",
"a",
".",
"Build",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"valid",
"{",
"return",
"false",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // Compare Remote and local MD5 | [
"Compare",
"Remote",
"and",
"local",
"MD5"
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/artifact.go#L87-L101 |
149,104 | bndr/gojenkins | artifact.go | getMD5local | func (a Artifact) getMD5local(path string) string {
h := md5.New()
localFile, err := os.Open(path)
if err != nil {
return ""
}
buffer := make([]byte, 2^20)
n, err := localFile.Read(buffer)
defer localFile.Close()
for err == nil {
io.WriteString(h, string(buffer[0:n]))
n, err = localFile.Read(buffer)
}
return fmt.Sprintf("%x", h.Sum(nil))
} | go | func (a Artifact) getMD5local(path string) string {
h := md5.New()
localFile, err := os.Open(path)
if err != nil {
return ""
}
buffer := make([]byte, 2^20)
n, err := localFile.Read(buffer)
defer localFile.Close()
for err == nil {
io.WriteString(h, string(buffer[0:n]))
n, err = localFile.Read(buffer)
}
return fmt.Sprintf("%x", h.Sum(nil))
} | [
"func",
"(",
"a",
"Artifact",
")",
"getMD5local",
"(",
"path",
"string",
")",
"string",
"{",
"h",
":=",
"md5",
".",
"New",
"(",
")",
"\n",
"localFile",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"buffer",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
"^",
"20",
")",
"\n",
"n",
",",
"err",
":=",
"localFile",
".",
"Read",
"(",
"buffer",
")",
"\n",
"defer",
"localFile",
".",
"Close",
"(",
")",
"\n",
"for",
"err",
"==",
"nil",
"{",
"io",
".",
"WriteString",
"(",
"h",
",",
"string",
"(",
"buffer",
"[",
"0",
":",
"n",
"]",
")",
")",
"\n",
"n",
",",
"err",
"=",
"localFile",
".",
"Read",
"(",
"buffer",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"h",
".",
"Sum",
"(",
"nil",
")",
")",
"\n",
"}"
] | // Get Local MD5 | [
"Get",
"Local",
"MD5"
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/artifact.go#L104-L118 |
149,105 | bndr/gojenkins | job.go | GetAllBuildIds | func (j *Job) GetAllBuildIds() ([]JobBuild, error) {
var buildsResp struct {
Builds []JobBuild `json:"allBuilds"`
}
_, err := j.Jenkins.Requester.GetJSON(j.Base, &buildsResp, map[string]string{"tree": "allBuilds[number,url]"})
if err != nil {
return nil, err
}
return buildsResp.Builds, nil
} | go | func (j *Job) GetAllBuildIds() ([]JobBuild, error) {
var buildsResp struct {
Builds []JobBuild `json:"allBuilds"`
}
_, err := j.Jenkins.Requester.GetJSON(j.Base, &buildsResp, map[string]string{"tree": "allBuilds[number,url]"})
if err != nil {
return nil, err
}
return buildsResp.Builds, nil
} | [
"func",
"(",
"j",
"*",
"Job",
")",
"GetAllBuildIds",
"(",
")",
"(",
"[",
"]",
"JobBuild",
",",
"error",
")",
"{",
"var",
"buildsResp",
"struct",
"{",
"Builds",
"[",
"]",
"JobBuild",
"`json:\"allBuilds\"`",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"j",
".",
"Jenkins",
".",
"Requester",
".",
"GetJSON",
"(",
"j",
".",
"Base",
",",
"&",
"buildsResp",
",",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"buildsResp",
".",
"Builds",
",",
"nil",
"\n",
"}"
] | // Returns All Builds with Number and URL | [
"Returns",
"All",
"Builds",
"with",
"Number",
"and",
"URL"
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/job.go#L192-L201 |
149,106 | bndr/gojenkins | pipeline.go | update | func (run *PipelineRun) update() {
href := run.URLs["self"]["href"]
if matches := baseURLRegex.FindStringSubmatch(href); len(matches) > 1 {
run.Base = matches[1]
}
for i := range run.Stages {
run.Stages[i].Run = run
href := run.Stages[i].URLs["self"]["href"]
if matches := baseURLRegex.FindStringSubmatch(href); len(matches) > 1 {
run.Stages[i].Base = matches[1]
}
}
} | go | func (run *PipelineRun) update() {
href := run.URLs["self"]["href"]
if matches := baseURLRegex.FindStringSubmatch(href); len(matches) > 1 {
run.Base = matches[1]
}
for i := range run.Stages {
run.Stages[i].Run = run
href := run.Stages[i].URLs["self"]["href"]
if matches := baseURLRegex.FindStringSubmatch(href); len(matches) > 1 {
run.Stages[i].Base = matches[1]
}
}
} | [
"func",
"(",
"run",
"*",
"PipelineRun",
")",
"update",
"(",
")",
"{",
"href",
":=",
"run",
".",
"URLs",
"[",
"\"",
"\"",
"]",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"matches",
":=",
"baseURLRegex",
".",
"FindStringSubmatch",
"(",
"href",
")",
";",
"len",
"(",
"matches",
")",
">",
"1",
"{",
"run",
".",
"Base",
"=",
"matches",
"[",
"1",
"]",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"run",
".",
"Stages",
"{",
"run",
".",
"Stages",
"[",
"i",
"]",
".",
"Run",
"=",
"run",
"\n",
"href",
":=",
"run",
".",
"Stages",
"[",
"i",
"]",
".",
"URLs",
"[",
"\"",
"\"",
"]",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"matches",
":=",
"baseURLRegex",
".",
"FindStringSubmatch",
"(",
"href",
")",
";",
"len",
"(",
"matches",
")",
">",
"1",
"{",
"run",
".",
"Stages",
"[",
"i",
"]",
".",
"Base",
"=",
"matches",
"[",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // utility function to fill in the Base fields under PipelineRun | [
"utility",
"function",
"to",
"fill",
"in",
"the",
"Base",
"fields",
"under",
"PipelineRun"
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/pipeline.go#L86-L98 |
149,107 | bndr/gojenkins | views.go | AddJob | func (v *View) AddJob(name string) (bool, error) {
url := "/addJobToView"
qr := map[string]string{"name": name}
resp, err := v.Jenkins.Requester.Post(v.Base+url, nil, nil, qr)
if err != nil {
return false, err
}
if resp.StatusCode == 200 {
return true, nil
}
return false, errors.New(strconv.Itoa(resp.StatusCode))
} | go | func (v *View) AddJob(name string) (bool, error) {
url := "/addJobToView"
qr := map[string]string{"name": name}
resp, err := v.Jenkins.Requester.Post(v.Base+url, nil, nil, qr)
if err != nil {
return false, err
}
if resp.StatusCode == 200 {
return true, nil
}
return false, errors.New(strconv.Itoa(resp.StatusCode))
} | [
"func",
"(",
"v",
"*",
"View",
")",
"AddJob",
"(",
"name",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"url",
":=",
"\"",
"\"",
"\n",
"qr",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"name",
"}",
"\n",
"resp",
",",
"err",
":=",
"v",
".",
"Jenkins",
".",
"Requester",
".",
"Post",
"(",
"v",
".",
"Base",
"+",
"url",
",",
"nil",
",",
"nil",
",",
"qr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"resp",
".",
"StatusCode",
"==",
"200",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"errors",
".",
"New",
"(",
"strconv",
".",
"Itoa",
"(",
"resp",
".",
"StatusCode",
")",
")",
"\n",
"}"
] | // Returns True if successfully added Job, otherwise false | [
"Returns",
"True",
"if",
"successfully",
"added",
"Job",
"otherwise",
"false"
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/views.go#L45-L56 |
149,108 | bndr/gojenkins | build_history.go | parseBuildHistory | func parseBuildHistory(d io.Reader) []*History {
z := html.NewTokenizer(d)
depth := 0
buildRowCellDepth := -1
builds := make([]*History, 0)
isInsideDisplayName := false
var curBuild *History
for {
tt := z.Next()
switch tt {
case html.ErrorToken:
if z.Err() == io.EOF {
return builds
}
case html.SelfClosingTagToken:
tn, hasAttr := z.TagName()
// fmt.Println("START__", string(tn), hasAttr)
if hasAttr {
a := attr(z)
// <img src="/static/f2881562/images/16x16/red.png" alt="Failed > Console Output" tooltip="Failed > Console Output" style="width: 16px; height: 16px; " class="icon-red icon-sm" />
if string(tn) == "img" {
if hasCSSClass(a, "icon-sm") && buildRowCellDepth > -1 {
if alt, found := a["alt"]; found {
curBuild.BuildStatus = strings.Fields(alt)[0]
}
}
}
}
case html.StartTagToken:
depth++
tn, hasAttr := z.TagName()
// fmt.Println("START__", string(tn), hasAttr)
if hasAttr {
a := attr(z)
// <td class="build-row-cell">
if string(tn) == "td" {
if hasCSSClass(a, "build-row-cell") {
buildRowCellDepth = depth
curBuild = &History{}
builds = append(builds, curBuild)
}
}
// <a update-parent-class=".build-row" href="/job/appscode/job/43/job/build-binary/227/" class="tip model-link inside build-link display-name">#227</a>
if string(tn) == "a" {
if hasCSSClass(a, "display-name") && buildRowCellDepth > -1 {
if href, found := a["href"]; found {
parts := strings.Split(href, "/")
if num, err := strconv.Atoi(parts[len(parts)-2]); err == nil {
curBuild.BuildNumber = num
isInsideDisplayName = true
}
}
}
}
// <div time="1469024602546" class="pane build-details"> ... </div>
if string(tn) == "div" {
if hasCSSClass(a, "build-details") && buildRowCellDepth > -1 {
if t, found := a["time"]; found {
if msec, err := strconv.ParseInt(t, 10, 0); err == nil {
curBuild.BuildTimestamp = msec / 1000
}
}
}
}
}
case html.TextToken:
if isInsideDisplayName {
curBuild.BuildDisplayName = z.Token().Data
isInsideDisplayName = false
}
case html.EndTagToken:
tn, _ := z.TagName()
if string(tn) == "td" && depth == buildRowCellDepth {
buildRowCellDepth = -1
curBuild = nil
}
depth--
}
}
} | go | func parseBuildHistory(d io.Reader) []*History {
z := html.NewTokenizer(d)
depth := 0
buildRowCellDepth := -1
builds := make([]*History, 0)
isInsideDisplayName := false
var curBuild *History
for {
tt := z.Next()
switch tt {
case html.ErrorToken:
if z.Err() == io.EOF {
return builds
}
case html.SelfClosingTagToken:
tn, hasAttr := z.TagName()
// fmt.Println("START__", string(tn), hasAttr)
if hasAttr {
a := attr(z)
// <img src="/static/f2881562/images/16x16/red.png" alt="Failed > Console Output" tooltip="Failed > Console Output" style="width: 16px; height: 16px; " class="icon-red icon-sm" />
if string(tn) == "img" {
if hasCSSClass(a, "icon-sm") && buildRowCellDepth > -1 {
if alt, found := a["alt"]; found {
curBuild.BuildStatus = strings.Fields(alt)[0]
}
}
}
}
case html.StartTagToken:
depth++
tn, hasAttr := z.TagName()
// fmt.Println("START__", string(tn), hasAttr)
if hasAttr {
a := attr(z)
// <td class="build-row-cell">
if string(tn) == "td" {
if hasCSSClass(a, "build-row-cell") {
buildRowCellDepth = depth
curBuild = &History{}
builds = append(builds, curBuild)
}
}
// <a update-parent-class=".build-row" href="/job/appscode/job/43/job/build-binary/227/" class="tip model-link inside build-link display-name">#227</a>
if string(tn) == "a" {
if hasCSSClass(a, "display-name") && buildRowCellDepth > -1 {
if href, found := a["href"]; found {
parts := strings.Split(href, "/")
if num, err := strconv.Atoi(parts[len(parts)-2]); err == nil {
curBuild.BuildNumber = num
isInsideDisplayName = true
}
}
}
}
// <div time="1469024602546" class="pane build-details"> ... </div>
if string(tn) == "div" {
if hasCSSClass(a, "build-details") && buildRowCellDepth > -1 {
if t, found := a["time"]; found {
if msec, err := strconv.ParseInt(t, 10, 0); err == nil {
curBuild.BuildTimestamp = msec / 1000
}
}
}
}
}
case html.TextToken:
if isInsideDisplayName {
curBuild.BuildDisplayName = z.Token().Data
isInsideDisplayName = false
}
case html.EndTagToken:
tn, _ := z.TagName()
if string(tn) == "td" && depth == buildRowCellDepth {
buildRowCellDepth = -1
curBuild = nil
}
depth--
}
}
} | [
"func",
"parseBuildHistory",
"(",
"d",
"io",
".",
"Reader",
")",
"[",
"]",
"*",
"History",
"{",
"z",
":=",
"html",
".",
"NewTokenizer",
"(",
"d",
")",
"\n",
"depth",
":=",
"0",
"\n",
"buildRowCellDepth",
":=",
"-",
"1",
"\n",
"builds",
":=",
"make",
"(",
"[",
"]",
"*",
"History",
",",
"0",
")",
"\n",
"isInsideDisplayName",
":=",
"false",
"\n",
"var",
"curBuild",
"*",
"History",
"\n",
"for",
"{",
"tt",
":=",
"z",
".",
"Next",
"(",
")",
"\n",
"switch",
"tt",
"{",
"case",
"html",
".",
"ErrorToken",
":",
"if",
"z",
".",
"Err",
"(",
")",
"==",
"io",
".",
"EOF",
"{",
"return",
"builds",
"\n",
"}",
"\n",
"case",
"html",
".",
"SelfClosingTagToken",
":",
"tn",
",",
"hasAttr",
":=",
"z",
".",
"TagName",
"(",
")",
"\n",
"// fmt.Println(\"START__\", string(tn), hasAttr)",
"if",
"hasAttr",
"{",
"a",
":=",
"attr",
"(",
"z",
")",
"\n",
"// <img src=\"/static/f2881562/images/16x16/red.png\" alt=\"Failed > Console Output\" tooltip=\"Failed > Console Output\" style=\"width: 16px; height: 16px; \" class=\"icon-red icon-sm\" />",
"if",
"string",
"(",
"tn",
")",
"==",
"\"",
"\"",
"{",
"if",
"hasCSSClass",
"(",
"a",
",",
"\"",
"\"",
")",
"&&",
"buildRowCellDepth",
">",
"-",
"1",
"{",
"if",
"alt",
",",
"found",
":=",
"a",
"[",
"\"",
"\"",
"]",
";",
"found",
"{",
"curBuild",
".",
"BuildStatus",
"=",
"strings",
".",
"Fields",
"(",
"alt",
")",
"[",
"0",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"html",
".",
"StartTagToken",
":",
"depth",
"++",
"\n",
"tn",
",",
"hasAttr",
":=",
"z",
".",
"TagName",
"(",
")",
"\n",
"// fmt.Println(\"START__\", string(tn), hasAttr)",
"if",
"hasAttr",
"{",
"a",
":=",
"attr",
"(",
"z",
")",
"\n",
"// <td class=\"build-row-cell\">",
"if",
"string",
"(",
"tn",
")",
"==",
"\"",
"\"",
"{",
"if",
"hasCSSClass",
"(",
"a",
",",
"\"",
"\"",
")",
"{",
"buildRowCellDepth",
"=",
"depth",
"\n",
"curBuild",
"=",
"&",
"History",
"{",
"}",
"\n",
"builds",
"=",
"append",
"(",
"builds",
",",
"curBuild",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// <a update-parent-class=\".build-row\" href=\"/job/appscode/job/43/job/build-binary/227/\" class=\"tip model-link inside build-link display-name\">#227</a>",
"if",
"string",
"(",
"tn",
")",
"==",
"\"",
"\"",
"{",
"if",
"hasCSSClass",
"(",
"a",
",",
"\"",
"\"",
")",
"&&",
"buildRowCellDepth",
">",
"-",
"1",
"{",
"if",
"href",
",",
"found",
":=",
"a",
"[",
"\"",
"\"",
"]",
";",
"found",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"href",
",",
"\"",
"\"",
")",
"\n",
"if",
"num",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"2",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"curBuild",
".",
"BuildNumber",
"=",
"num",
"\n",
"isInsideDisplayName",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"// <div time=\"1469024602546\" class=\"pane build-details\"> ... </div>",
"if",
"string",
"(",
"tn",
")",
"==",
"\"",
"\"",
"{",
"if",
"hasCSSClass",
"(",
"a",
",",
"\"",
"\"",
")",
"&&",
"buildRowCellDepth",
">",
"-",
"1",
"{",
"if",
"t",
",",
"found",
":=",
"a",
"[",
"\"",
"\"",
"]",
";",
"found",
"{",
"if",
"msec",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"t",
",",
"10",
",",
"0",
")",
";",
"err",
"==",
"nil",
"{",
"curBuild",
".",
"BuildTimestamp",
"=",
"msec",
"/",
"1000",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"html",
".",
"TextToken",
":",
"if",
"isInsideDisplayName",
"{",
"curBuild",
".",
"BuildDisplayName",
"=",
"z",
".",
"Token",
"(",
")",
".",
"Data",
"\n",
"isInsideDisplayName",
"=",
"false",
"\n",
"}",
"\n",
"case",
"html",
".",
"EndTagToken",
":",
"tn",
",",
"_",
":=",
"z",
".",
"TagName",
"(",
")",
"\n",
"if",
"string",
"(",
"tn",
")",
"==",
"\"",
"\"",
"&&",
"depth",
"==",
"buildRowCellDepth",
"{",
"buildRowCellDepth",
"=",
"-",
"1",
"\n",
"curBuild",
"=",
"nil",
"\n",
"}",
"\n",
"depth",
"--",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Parse jenkins ajax response in order find the current jenkins build history | [
"Parse",
"jenkins",
"ajax",
"response",
"in",
"order",
"find",
"the",
"current",
"jenkins",
"build",
"history"
] | de43c03cf849dd63a9737df6e05791c7a176c93d | https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/build_history.go#L12-L91 |
149,109 | jlaffaye/ftp | scanner.go | NextFields | func (s *scanner) NextFields(count int) []string {
fields := make([]string, 0, count)
for i := 0; i < count; i++ {
if field := s.Next(); field != "" {
fields = append(fields, field)
} else {
break
}
}
return fields
} | go | func (s *scanner) NextFields(count int) []string {
fields := make([]string, 0, count)
for i := 0; i < count; i++ {
if field := s.Next(); field != "" {
fields = append(fields, field)
} else {
break
}
}
return fields
} | [
"func",
"(",
"s",
"*",
"scanner",
")",
"NextFields",
"(",
"count",
"int",
")",
"[",
"]",
"string",
"{",
"fields",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"count",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
"{",
"if",
"field",
":=",
"s",
".",
"Next",
"(",
")",
";",
"field",
"!=",
"\"",
"\"",
"{",
"fields",
"=",
"append",
"(",
"fields",
",",
"field",
")",
"\n",
"}",
"else",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fields",
"\n",
"}"
] | // NextFields returns the next `count` fields | [
"NextFields",
"returns",
"the",
"next",
"count",
"fields"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/scanner.go#L17-L27 |
149,110 | jlaffaye/ftp | scanner.go | Next | func (s *scanner) Next() string {
sLen := len(s.bytes)
// skip trailing whitespace
for s.position < sLen {
if s.bytes[s.position] != ' ' {
break
}
s.position++
}
start := s.position
// skip non-whitespace
for s.position < sLen {
if s.bytes[s.position] == ' ' {
s.position++
return string(s.bytes[start : s.position-1])
}
s.position++
}
return string(s.bytes[start:s.position])
} | go | func (s *scanner) Next() string {
sLen := len(s.bytes)
// skip trailing whitespace
for s.position < sLen {
if s.bytes[s.position] != ' ' {
break
}
s.position++
}
start := s.position
// skip non-whitespace
for s.position < sLen {
if s.bytes[s.position] == ' ' {
s.position++
return string(s.bytes[start : s.position-1])
}
s.position++
}
return string(s.bytes[start:s.position])
} | [
"func",
"(",
"s",
"*",
"scanner",
")",
"Next",
"(",
")",
"string",
"{",
"sLen",
":=",
"len",
"(",
"s",
".",
"bytes",
")",
"\n\n",
"// skip trailing whitespace",
"for",
"s",
".",
"position",
"<",
"sLen",
"{",
"if",
"s",
".",
"bytes",
"[",
"s",
".",
"position",
"]",
"!=",
"' '",
"{",
"break",
"\n",
"}",
"\n",
"s",
".",
"position",
"++",
"\n",
"}",
"\n\n",
"start",
":=",
"s",
".",
"position",
"\n\n",
"// skip non-whitespace",
"for",
"s",
".",
"position",
"<",
"sLen",
"{",
"if",
"s",
".",
"bytes",
"[",
"s",
".",
"position",
"]",
"==",
"' '",
"{",
"s",
".",
"position",
"++",
"\n",
"return",
"string",
"(",
"s",
".",
"bytes",
"[",
"start",
":",
"s",
".",
"position",
"-",
"1",
"]",
")",
"\n",
"}",
"\n",
"s",
".",
"position",
"++",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"s",
".",
"bytes",
"[",
"start",
":",
"s",
".",
"position",
"]",
")",
"\n",
"}"
] | // Next returns the next field | [
"Next",
"returns",
"the",
"next",
"field"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/scanner.go#L30-L53 |
149,111 | jlaffaye/ftp | scanner.go | Remaining | func (s *scanner) Remaining() string {
return string(s.bytes[s.position:len(s.bytes)])
} | go | func (s *scanner) Remaining() string {
return string(s.bytes[s.position:len(s.bytes)])
} | [
"func",
"(",
"s",
"*",
"scanner",
")",
"Remaining",
"(",
")",
"string",
"{",
"return",
"string",
"(",
"s",
".",
"bytes",
"[",
"s",
".",
"position",
":",
"len",
"(",
"s",
".",
"bytes",
")",
"]",
")",
"\n",
"}"
] | // Remaining returns the remaining string | [
"Remaining",
"returns",
"the",
"remaining",
"string"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/scanner.go#L56-L58 |
149,112 | jlaffaye/ftp | ftp.go | Dial | func Dial(addr string, options ...DialOption) (*ServerConn, error) {
do := &dialOptions{}
for _, option := range options {
option.setup(do)
}
if do.location == nil {
do.location = time.UTC
}
tconn := do.conn
if tconn == nil {
var err error
if do.dialFunc != nil {
tconn, err = do.dialFunc("tcp", addr)
} else {
ctx := do.context
if ctx == nil {
ctx = context.Background()
}
tconn, err = do.dialer.DialContext(ctx, "tcp", addr)
}
if err != nil {
return nil, err
}
}
// Use the resolved IP address in case addr contains a domain name
// If we use the domain name, we might not resolve to the same IP.
remoteAddr := tconn.RemoteAddr().(*net.TCPAddr)
var sourceConn io.ReadWriteCloser = tconn
if do.debugOutput != nil {
sourceConn = newDebugWrapper(tconn, do.debugOutput)
}
c := &ServerConn{
options: do,
features: make(map[string]string),
conn: textproto.NewConn(sourceConn),
host: remoteAddr.IP.String(),
}
_, _, err := c.conn.ReadResponse(StatusReady)
if err != nil {
c.Quit()
return nil, err
}
err = c.feat()
if err != nil {
c.Quit()
return nil, err
}
if _, mlstSupported := c.features["MLST"]; mlstSupported {
c.mlstSupported = true
}
return c, nil
} | go | func Dial(addr string, options ...DialOption) (*ServerConn, error) {
do := &dialOptions{}
for _, option := range options {
option.setup(do)
}
if do.location == nil {
do.location = time.UTC
}
tconn := do.conn
if tconn == nil {
var err error
if do.dialFunc != nil {
tconn, err = do.dialFunc("tcp", addr)
} else {
ctx := do.context
if ctx == nil {
ctx = context.Background()
}
tconn, err = do.dialer.DialContext(ctx, "tcp", addr)
}
if err != nil {
return nil, err
}
}
// Use the resolved IP address in case addr contains a domain name
// If we use the domain name, we might not resolve to the same IP.
remoteAddr := tconn.RemoteAddr().(*net.TCPAddr)
var sourceConn io.ReadWriteCloser = tconn
if do.debugOutput != nil {
sourceConn = newDebugWrapper(tconn, do.debugOutput)
}
c := &ServerConn{
options: do,
features: make(map[string]string),
conn: textproto.NewConn(sourceConn),
host: remoteAddr.IP.String(),
}
_, _, err := c.conn.ReadResponse(StatusReady)
if err != nil {
c.Quit()
return nil, err
}
err = c.feat()
if err != nil {
c.Quit()
return nil, err
}
if _, mlstSupported := c.features["MLST"]; mlstSupported {
c.mlstSupported = true
}
return c, nil
} | [
"func",
"Dial",
"(",
"addr",
"string",
",",
"options",
"...",
"DialOption",
")",
"(",
"*",
"ServerConn",
",",
"error",
")",
"{",
"do",
":=",
"&",
"dialOptions",
"{",
"}",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"option",
".",
"setup",
"(",
"do",
")",
"\n",
"}",
"\n\n",
"if",
"do",
".",
"location",
"==",
"nil",
"{",
"do",
".",
"location",
"=",
"time",
".",
"UTC",
"\n",
"}",
"\n\n",
"tconn",
":=",
"do",
".",
"conn",
"\n",
"if",
"tconn",
"==",
"nil",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"do",
".",
"dialFunc",
"!=",
"nil",
"{",
"tconn",
",",
"err",
"=",
"do",
".",
"dialFunc",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"}",
"else",
"{",
"ctx",
":=",
"do",
".",
"context",
"\n\n",
"if",
"ctx",
"==",
"nil",
"{",
"ctx",
"=",
"context",
".",
"Background",
"(",
")",
"\n",
"}",
"\n\n",
"tconn",
",",
"err",
"=",
"do",
".",
"dialer",
".",
"DialContext",
"(",
"ctx",
",",
"\"",
"\"",
",",
"addr",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Use the resolved IP address in case addr contains a domain name",
"// If we use the domain name, we might not resolve to the same IP.",
"remoteAddr",
":=",
"tconn",
".",
"RemoteAddr",
"(",
")",
".",
"(",
"*",
"net",
".",
"TCPAddr",
")",
"\n\n",
"var",
"sourceConn",
"io",
".",
"ReadWriteCloser",
"=",
"tconn",
"\n",
"if",
"do",
".",
"debugOutput",
"!=",
"nil",
"{",
"sourceConn",
"=",
"newDebugWrapper",
"(",
"tconn",
",",
"do",
".",
"debugOutput",
")",
"\n",
"}",
"\n\n",
"c",
":=",
"&",
"ServerConn",
"{",
"options",
":",
"do",
",",
"features",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"conn",
":",
"textproto",
".",
"NewConn",
"(",
"sourceConn",
")",
",",
"host",
":",
"remoteAddr",
".",
"IP",
".",
"String",
"(",
")",
",",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"conn",
".",
"ReadResponse",
"(",
"StatusReady",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"Quit",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"c",
".",
"feat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"Quit",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"mlstSupported",
":=",
"c",
".",
"features",
"[",
"\"",
"\"",
"]",
";",
"mlstSupported",
"{",
"c",
".",
"mlstSupported",
"=",
"true",
"\n",
"}",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // Dial connects to the specified address with optinal options | [
"Dial",
"connects",
"to",
"the",
"specified",
"address",
"with",
"optinal",
"options"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L76-L140 |
149,113 | jlaffaye/ftp | ftp.go | DialWithTimeout | func DialWithTimeout(timeout time.Duration) DialOption {
return DialOption{func(do *dialOptions) {
do.dialer.Timeout = timeout
}}
} | go | func DialWithTimeout(timeout time.Duration) DialOption {
return DialOption{func(do *dialOptions) {
do.dialer.Timeout = timeout
}}
} | [
"func",
"DialWithTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"dialer",
".",
"Timeout",
"=",
"timeout",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithTimeout returns a DialOption that configures the ServerConn with specified timeout | [
"DialWithTimeout",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"with",
"specified",
"timeout"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L143-L147 |
149,114 | jlaffaye/ftp | ftp.go | DialWithDialer | func DialWithDialer(dialer net.Dialer) DialOption {
return DialOption{func(do *dialOptions) {
do.dialer = dialer
}}
} | go | func DialWithDialer(dialer net.Dialer) DialOption {
return DialOption{func(do *dialOptions) {
do.dialer = dialer
}}
} | [
"func",
"DialWithDialer",
"(",
"dialer",
"net",
".",
"Dialer",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"dialer",
"=",
"dialer",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithDialer returns a DialOption that configures the ServerConn with specified net.Dialer | [
"DialWithDialer",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"with",
"specified",
"net",
".",
"Dialer"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L150-L154 |
149,115 | jlaffaye/ftp | ftp.go | DialWithNetConn | func DialWithNetConn(conn net.Conn) DialOption {
return DialOption{func(do *dialOptions) {
do.conn = conn
}}
} | go | func DialWithNetConn(conn net.Conn) DialOption {
return DialOption{func(do *dialOptions) {
do.conn = conn
}}
} | [
"func",
"DialWithNetConn",
"(",
"conn",
"net",
".",
"Conn",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"conn",
"=",
"conn",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithNetConn returns a DialOption that configures the ServerConn with the underlying net.Conn | [
"DialWithNetConn",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"with",
"the",
"underlying",
"net",
".",
"Conn"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L157-L161 |
149,116 | jlaffaye/ftp | ftp.go | DialWithDisabledEPSV | func DialWithDisabledEPSV(disabled bool) DialOption {
return DialOption{func(do *dialOptions) {
do.disableEPSV = disabled
}}
} | go | func DialWithDisabledEPSV(disabled bool) DialOption {
return DialOption{func(do *dialOptions) {
do.disableEPSV = disabled
}}
} | [
"func",
"DialWithDisabledEPSV",
"(",
"disabled",
"bool",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"disableEPSV",
"=",
"disabled",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithDisabledEPSV returns a DialOption that configures the ServerConn with EPSV disabled
// Note that EPSV is only used when advertised in the server features. | [
"DialWithDisabledEPSV",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"with",
"EPSV",
"disabled",
"Note",
"that",
"EPSV",
"is",
"only",
"used",
"when",
"advertised",
"in",
"the",
"server",
"features",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L165-L169 |
149,117 | jlaffaye/ftp | ftp.go | DialWithLocation | func DialWithLocation(location *time.Location) DialOption {
return DialOption{func(do *dialOptions) {
do.location = location
}}
} | go | func DialWithLocation(location *time.Location) DialOption {
return DialOption{func(do *dialOptions) {
do.location = location
}}
} | [
"func",
"DialWithLocation",
"(",
"location",
"*",
"time",
".",
"Location",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"location",
"=",
"location",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithLocation returns a DialOption that configures the ServerConn with specified time.Location
// The lococation is used to parse the dates sent by the server which are in server's timezone | [
"DialWithLocation",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"with",
"specified",
"time",
".",
"Location",
"The",
"lococation",
"is",
"used",
"to",
"parse",
"the",
"dates",
"sent",
"by",
"the",
"server",
"which",
"are",
"in",
"server",
"s",
"timezone"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L173-L177 |
149,118 | jlaffaye/ftp | ftp.go | DialWithContext | func DialWithContext(ctx context.Context) DialOption {
return DialOption{func(do *dialOptions) {
do.context = ctx
}}
} | go | func DialWithContext(ctx context.Context) DialOption {
return DialOption{func(do *dialOptions) {
do.context = ctx
}}
} | [
"func",
"DialWithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"context",
"=",
"ctx",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithContext returns a DialOption that configures the ServerConn with specified context
// The context will be used for the initial connection setup | [
"DialWithContext",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"with",
"specified",
"context",
"The",
"context",
"will",
"be",
"used",
"for",
"the",
"initial",
"connection",
"setup"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L181-L185 |
149,119 | jlaffaye/ftp | ftp.go | DialWithTLS | func DialWithTLS(tlsConfig tls.Config) DialOption {
return DialOption{func(do *dialOptions) {
do.tlsConfig = tlsConfig
}}
} | go | func DialWithTLS(tlsConfig tls.Config) DialOption {
return DialOption{func(do *dialOptions) {
do.tlsConfig = tlsConfig
}}
} | [
"func",
"DialWithTLS",
"(",
"tlsConfig",
"tls",
".",
"Config",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"tlsConfig",
"=",
"tlsConfig",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithTLS returns a DialOption that configures the ServerConn with specified TLS config | [
"DialWithTLS",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"with",
"specified",
"TLS",
"config"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L188-L192 |
149,120 | jlaffaye/ftp | ftp.go | DialWithDebugOutput | func DialWithDebugOutput(w io.Writer) DialOption {
return DialOption{func(do *dialOptions) {
do.debugOutput = w
}}
} | go | func DialWithDebugOutput(w io.Writer) DialOption {
return DialOption{func(do *dialOptions) {
do.debugOutput = w
}}
} | [
"func",
"DialWithDebugOutput",
"(",
"w",
"io",
".",
"Writer",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"debugOutput",
"=",
"w",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithDebugOutput returns a DialOption that configures the ServerConn to write to the Writer
// everything it reads from the server | [
"DialWithDebugOutput",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"to",
"write",
"to",
"the",
"Writer",
"everything",
"it",
"reads",
"from",
"the",
"server"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L196-L200 |
149,121 | jlaffaye/ftp | ftp.go | DialWithDialFunc | func DialWithDialFunc(f func(network, address string) (net.Conn, error)) DialOption {
return DialOption{func(do *dialOptions) {
do.dialFunc = f
}}
} | go | func DialWithDialFunc(f func(network, address string) (net.Conn, error)) DialOption {
return DialOption{func(do *dialOptions) {
do.dialFunc = f
}}
} | [
"func",
"DialWithDialFunc",
"(",
"f",
"func",
"(",
"network",
",",
"address",
"string",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
")",
"DialOption",
"{",
"return",
"DialOption",
"{",
"func",
"(",
"do",
"*",
"dialOptions",
")",
"{",
"do",
".",
"dialFunc",
"=",
"f",
"\n",
"}",
"}",
"\n",
"}"
] | // DialWithDialFunc returns a DialOption that configures the ServerConn to use the
// specified function to establish both control and data connections
//
// If used together with the DialWithNetConn option, the DialWithNetConn
// takes precedence for the control connection, while data connections will
// be established using function specified with the DialWithDialFunc option | [
"DialWithDialFunc",
"returns",
"a",
"DialOption",
"that",
"configures",
"the",
"ServerConn",
"to",
"use",
"the",
"specified",
"function",
"to",
"establish",
"both",
"control",
"and",
"data",
"connections",
"If",
"used",
"together",
"with",
"the",
"DialWithNetConn",
"option",
"the",
"DialWithNetConn",
"takes",
"precedence",
"for",
"the",
"control",
"connection",
"while",
"data",
"connections",
"will",
"be",
"established",
"using",
"function",
"specified",
"with",
"the",
"DialWithDialFunc",
"option"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L208-L212 |
149,122 | jlaffaye/ftp | ftp.go | feat | func (c *ServerConn) feat() error {
code, message, err := c.cmd(-1, "FEAT")
if err != nil {
return err
}
if code != StatusSystem {
// The server does not support the FEAT command. This is not an
// error: we consider that there is no additional feature.
return nil
}
lines := strings.Split(message, "\n")
for _, line := range lines {
if !strings.HasPrefix(line, " ") {
continue
}
line = strings.TrimSpace(line)
featureElements := strings.SplitN(line, " ", 2)
command := featureElements[0]
var commandDesc string
if len(featureElements) == 2 {
commandDesc = featureElements[1]
}
c.features[command] = commandDesc
}
return nil
} | go | func (c *ServerConn) feat() error {
code, message, err := c.cmd(-1, "FEAT")
if err != nil {
return err
}
if code != StatusSystem {
// The server does not support the FEAT command. This is not an
// error: we consider that there is no additional feature.
return nil
}
lines := strings.Split(message, "\n")
for _, line := range lines {
if !strings.HasPrefix(line, " ") {
continue
}
line = strings.TrimSpace(line)
featureElements := strings.SplitN(line, " ", 2)
command := featureElements[0]
var commandDesc string
if len(featureElements) == 2 {
commandDesc = featureElements[1]
}
c.features[command] = commandDesc
}
return nil
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"feat",
"(",
")",
"error",
"{",
"code",
",",
"message",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"-",
"1",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"code",
"!=",
"StatusSystem",
"{",
"// The server does not support the FEAT command. This is not an",
"// error: we consider that there is no additional feature.",
"return",
"nil",
"\n",
"}",
"\n\n",
"lines",
":=",
"strings",
".",
"Split",
"(",
"message",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"_",
",",
"line",
":=",
"range",
"lines",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"line",
",",
"\"",
"\"",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"line",
"=",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
"\n",
"featureElements",
":=",
"strings",
".",
"SplitN",
"(",
"line",
",",
"\"",
"\"",
",",
"2",
")",
"\n\n",
"command",
":=",
"featureElements",
"[",
"0",
"]",
"\n\n",
"var",
"commandDesc",
"string",
"\n",
"if",
"len",
"(",
"featureElements",
")",
"==",
"2",
"{",
"commandDesc",
"=",
"featureElements",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"c",
".",
"features",
"[",
"command",
"]",
"=",
"commandDesc",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // feat issues a FEAT FTP command to list the additional commands supported by
// the remote FTP server.
// FEAT is described in RFC 2389 | [
"feat",
"issues",
"a",
"FEAT",
"FTP",
"command",
"to",
"list",
"the",
"additional",
"commands",
"supported",
"by",
"the",
"remote",
"FTP",
"server",
".",
"FEAT",
"is",
"described",
"in",
"RFC",
"2389"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L262-L294 |
149,123 | jlaffaye/ftp | ftp.go | setUTF8 | func (c *ServerConn) setUTF8() error {
if _, ok := c.features["UTF8"]; !ok {
return nil
}
code, message, err := c.cmd(-1, "OPTS UTF8 ON")
if err != nil {
return err
}
// Workaround for FTP servers, that does not support this option.
if code == StatusBadArguments {
return nil
}
// The ftpd "filezilla-server" has FEAT support for UTF8, but always returns
// "202 UTF8 mode is always enabled. No need to send this command." when
// trying to use it. That's OK
if code == StatusCommandNotImplemented {
return nil
}
if code != StatusCommandOK {
return errors.New(message)
}
return nil
} | go | func (c *ServerConn) setUTF8() error {
if _, ok := c.features["UTF8"]; !ok {
return nil
}
code, message, err := c.cmd(-1, "OPTS UTF8 ON")
if err != nil {
return err
}
// Workaround for FTP servers, that does not support this option.
if code == StatusBadArguments {
return nil
}
// The ftpd "filezilla-server" has FEAT support for UTF8, but always returns
// "202 UTF8 mode is always enabled. No need to send this command." when
// trying to use it. That's OK
if code == StatusCommandNotImplemented {
return nil
}
if code != StatusCommandOK {
return errors.New(message)
}
return nil
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"setUTF8",
"(",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"features",
"[",
"\"",
"\"",
"]",
";",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"code",
",",
"message",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"-",
"1",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Workaround for FTP servers, that does not support this option.",
"if",
"code",
"==",
"StatusBadArguments",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// The ftpd \"filezilla-server\" has FEAT support for UTF8, but always returns",
"// \"202 UTF8 mode is always enabled. No need to send this command.\" when",
"// trying to use it. That's OK",
"if",
"code",
"==",
"StatusCommandNotImplemented",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"code",
"!=",
"StatusCommandOK",
"{",
"return",
"errors",
".",
"New",
"(",
"message",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // setUTF8 issues an "OPTS UTF8 ON" command. | [
"setUTF8",
"issues",
"an",
"OPTS",
"UTF8",
"ON",
"command",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L297-L324 |
149,124 | jlaffaye/ftp | ftp.go | epsv | func (c *ServerConn) epsv() (port int, err error) {
_, line, err := c.cmd(StatusExtendedPassiveMode, "EPSV")
if err != nil {
return
}
start := strings.Index(line, "|||")
end := strings.LastIndex(line, "|")
if start == -1 || end == -1 {
err = errors.New("invalid EPSV response format")
return
}
port, err = strconv.Atoi(line[start+3 : end])
return
} | go | func (c *ServerConn) epsv() (port int, err error) {
_, line, err := c.cmd(StatusExtendedPassiveMode, "EPSV")
if err != nil {
return
}
start := strings.Index(line, "|||")
end := strings.LastIndex(line, "|")
if start == -1 || end == -1 {
err = errors.New("invalid EPSV response format")
return
}
port, err = strconv.Atoi(line[start+3 : end])
return
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"epsv",
"(",
")",
"(",
"port",
"int",
",",
"err",
"error",
")",
"{",
"_",
",",
"line",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusExtendedPassiveMode",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"start",
":=",
"strings",
".",
"Index",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"end",
":=",
"strings",
".",
"LastIndex",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"if",
"start",
"==",
"-",
"1",
"||",
"end",
"==",
"-",
"1",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"port",
",",
"err",
"=",
"strconv",
".",
"Atoi",
"(",
"line",
"[",
"start",
"+",
"3",
":",
"end",
"]",
")",
"\n",
"return",
"\n",
"}"
] | // epsv issues an "EPSV" command to get a port number for a data connection. | [
"epsv",
"issues",
"an",
"EPSV",
"command",
"to",
"get",
"a",
"port",
"number",
"for",
"a",
"data",
"connection",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L327-L341 |
149,125 | jlaffaye/ftp | ftp.go | pasv | func (c *ServerConn) pasv() (host string, port int, err error) {
_, line, err := c.cmd(StatusPassiveMode, "PASV")
if err != nil {
return
}
// PASV response format : 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
start := strings.Index(line, "(")
end := strings.LastIndex(line, ")")
if start == -1 || end == -1 {
err = errors.New("invalid PASV response format")
return
}
// We have to split the response string
pasvData := strings.Split(line[start+1:end], ",")
if len(pasvData) < 6 {
err = errors.New("invalid PASV response format")
return
}
// Let's compute the port number
portPart1, err1 := strconv.Atoi(pasvData[4])
if err1 != nil {
err = err1
return
}
portPart2, err2 := strconv.Atoi(pasvData[5])
if err2 != nil {
err = err2
return
}
// Recompose port
port = portPart1*256 + portPart2
// Make the IP address to connect to
host = strings.Join(pasvData[0:4], ".")
return
} | go | func (c *ServerConn) pasv() (host string, port int, err error) {
_, line, err := c.cmd(StatusPassiveMode, "PASV")
if err != nil {
return
}
// PASV response format : 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
start := strings.Index(line, "(")
end := strings.LastIndex(line, ")")
if start == -1 || end == -1 {
err = errors.New("invalid PASV response format")
return
}
// We have to split the response string
pasvData := strings.Split(line[start+1:end], ",")
if len(pasvData) < 6 {
err = errors.New("invalid PASV response format")
return
}
// Let's compute the port number
portPart1, err1 := strconv.Atoi(pasvData[4])
if err1 != nil {
err = err1
return
}
portPart2, err2 := strconv.Atoi(pasvData[5])
if err2 != nil {
err = err2
return
}
// Recompose port
port = portPart1*256 + portPart2
// Make the IP address to connect to
host = strings.Join(pasvData[0:4], ".")
return
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"pasv",
"(",
")",
"(",
"host",
"string",
",",
"port",
"int",
",",
"err",
"error",
")",
"{",
"_",
",",
"line",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusPassiveMode",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// PASV response format : 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).",
"start",
":=",
"strings",
".",
"Index",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"end",
":=",
"strings",
".",
"LastIndex",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"if",
"start",
"==",
"-",
"1",
"||",
"end",
"==",
"-",
"1",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// We have to split the response string",
"pasvData",
":=",
"strings",
".",
"Split",
"(",
"line",
"[",
"start",
"+",
"1",
":",
"end",
"]",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"pasvData",
")",
"<",
"6",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Let's compute the port number",
"portPart1",
",",
"err1",
":=",
"strconv",
".",
"Atoi",
"(",
"pasvData",
"[",
"4",
"]",
")",
"\n",
"if",
"err1",
"!=",
"nil",
"{",
"err",
"=",
"err1",
"\n",
"return",
"\n",
"}",
"\n\n",
"portPart2",
",",
"err2",
":=",
"strconv",
".",
"Atoi",
"(",
"pasvData",
"[",
"5",
"]",
")",
"\n",
"if",
"err2",
"!=",
"nil",
"{",
"err",
"=",
"err2",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Recompose port",
"port",
"=",
"portPart1",
"*",
"256",
"+",
"portPart2",
"\n\n",
"// Make the IP address to connect to",
"host",
"=",
"strings",
".",
"Join",
"(",
"pasvData",
"[",
"0",
":",
"4",
"]",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}"
] | // pasv issues a "PASV" command to get a port number for a data connection. | [
"pasv",
"issues",
"a",
"PASV",
"command",
"to",
"get",
"a",
"port",
"number",
"for",
"a",
"data",
"connection",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L344-L385 |
149,126 | jlaffaye/ftp | ftp.go | getDataConnPort | func (c *ServerConn) getDataConnPort() (string, int, error) {
if !c.options.disableEPSV && !c.skipEPSV {
if port, err := c.epsv(); err == nil {
return c.host, port, nil
}
// if there is an error, skip EPSV for the next attempts
c.skipEPSV = true
}
return c.pasv()
} | go | func (c *ServerConn) getDataConnPort() (string, int, error) {
if !c.options.disableEPSV && !c.skipEPSV {
if port, err := c.epsv(); err == nil {
return c.host, port, nil
}
// if there is an error, skip EPSV for the next attempts
c.skipEPSV = true
}
return c.pasv()
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"getDataConnPort",
"(",
")",
"(",
"string",
",",
"int",
",",
"error",
")",
"{",
"if",
"!",
"c",
".",
"options",
".",
"disableEPSV",
"&&",
"!",
"c",
".",
"skipEPSV",
"{",
"if",
"port",
",",
"err",
":=",
"c",
".",
"epsv",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"c",
".",
"host",
",",
"port",
",",
"nil",
"\n",
"}",
"\n\n",
"// if there is an error, skip EPSV for the next attempts",
"c",
".",
"skipEPSV",
"=",
"true",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"pasv",
"(",
")",
"\n",
"}"
] | // getDataConnPort returns a host, port for a new data connection
// it uses the best available method to do so | [
"getDataConnPort",
"returns",
"a",
"host",
"port",
"for",
"a",
"new",
"data",
"connection",
"it",
"uses",
"the",
"best",
"available",
"method",
"to",
"do",
"so"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L389-L400 |
149,127 | jlaffaye/ftp | ftp.go | openDataConn | func (c *ServerConn) openDataConn() (net.Conn, error) {
host, port, err := c.getDataConnPort()
if err != nil {
return nil, err
}
addr := net.JoinHostPort(host, strconv.Itoa(port))
if c.options.dialFunc != nil {
return c.options.dialFunc("tcp", addr)
}
return c.options.dialer.Dial("tcp", addr)
} | go | func (c *ServerConn) openDataConn() (net.Conn, error) {
host, port, err := c.getDataConnPort()
if err != nil {
return nil, err
}
addr := net.JoinHostPort(host, strconv.Itoa(port))
if c.options.dialFunc != nil {
return c.options.dialFunc("tcp", addr)
}
return c.options.dialer.Dial("tcp", addr)
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"openDataConn",
"(",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"host",
",",
"port",
",",
"err",
":=",
"c",
".",
"getDataConnPort",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"addr",
":=",
"net",
".",
"JoinHostPort",
"(",
"host",
",",
"strconv",
".",
"Itoa",
"(",
"port",
")",
")",
"\n",
"if",
"c",
".",
"options",
".",
"dialFunc",
"!=",
"nil",
"{",
"return",
"c",
".",
"options",
".",
"dialFunc",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"options",
".",
"dialer",
".",
"Dial",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"}"
] | // openDataConn creates a new FTP data connection. | [
"openDataConn",
"creates",
"a",
"new",
"FTP",
"data",
"connection",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L403-L415 |
149,128 | jlaffaye/ftp | ftp.go | cmd | func (c *ServerConn) cmd(expected int, format string, args ...interface{}) (int, string, error) {
_, err := c.conn.Cmd(format, args...)
if err != nil {
return 0, "", err
}
return c.conn.ReadResponse(expected)
} | go | func (c *ServerConn) cmd(expected int, format string, args ...interface{}) (int, string, error) {
_, err := c.conn.Cmd(format, args...)
if err != nil {
return 0, "", err
}
return c.conn.ReadResponse(expected)
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"cmd",
"(",
"expected",
"int",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"string",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"c",
".",
"conn",
".",
"Cmd",
"(",
"format",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"conn",
".",
"ReadResponse",
"(",
"expected",
")",
"\n",
"}"
] | // cmd is a helper function to execute a command and check for the expected FTP
// return code | [
"cmd",
"is",
"a",
"helper",
"function",
"to",
"execute",
"a",
"command",
"and",
"check",
"for",
"the",
"expected",
"FTP",
"return",
"code"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L419-L426 |
149,129 | jlaffaye/ftp | ftp.go | cmdDataConnFrom | func (c *ServerConn) cmdDataConnFrom(offset uint64, format string, args ...interface{}) (net.Conn, error) {
conn, err := c.openDataConn()
if err != nil {
return nil, err
}
if offset != 0 {
_, _, err := c.cmd(StatusRequestFilePending, "REST %d", offset)
if err != nil {
conn.Close()
return nil, err
}
}
_, err = c.conn.Cmd(format, args...)
if err != nil {
conn.Close()
return nil, err
}
code, msg, err := c.conn.ReadResponse(-1)
if err != nil {
conn.Close()
return nil, err
}
if code != StatusAlreadyOpen && code != StatusAboutToSend {
conn.Close()
return nil, &textproto.Error{Code: code, Msg: msg}
}
return conn, nil
} | go | func (c *ServerConn) cmdDataConnFrom(offset uint64, format string, args ...interface{}) (net.Conn, error) {
conn, err := c.openDataConn()
if err != nil {
return nil, err
}
if offset != 0 {
_, _, err := c.cmd(StatusRequestFilePending, "REST %d", offset)
if err != nil {
conn.Close()
return nil, err
}
}
_, err = c.conn.Cmd(format, args...)
if err != nil {
conn.Close()
return nil, err
}
code, msg, err := c.conn.ReadResponse(-1)
if err != nil {
conn.Close()
return nil, err
}
if code != StatusAlreadyOpen && code != StatusAboutToSend {
conn.Close()
return nil, &textproto.Error{Code: code, Msg: msg}
}
return conn, nil
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"cmdDataConnFrom",
"(",
"offset",
"uint64",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"c",
".",
"openDataConn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"offset",
"!=",
"0",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusRequestFilePending",
",",
"\"",
"\"",
",",
"offset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"c",
".",
"conn",
".",
"Cmd",
"(",
"format",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"code",
",",
"msg",
",",
"err",
":=",
"c",
".",
"conn",
".",
"ReadResponse",
"(",
"-",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"code",
"!=",
"StatusAlreadyOpen",
"&&",
"code",
"!=",
"StatusAboutToSend",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"&",
"textproto",
".",
"Error",
"{",
"Code",
":",
"code",
",",
"Msg",
":",
"msg",
"}",
"\n",
"}",
"\n\n",
"return",
"conn",
",",
"nil",
"\n",
"}"
] | // cmdDataConnFrom executes a command which require a FTP data connection.
// Issues a REST FTP command to specify the number of bytes to skip for the transfer. | [
"cmdDataConnFrom",
"executes",
"a",
"command",
"which",
"require",
"a",
"FTP",
"data",
"connection",
".",
"Issues",
"a",
"REST",
"FTP",
"command",
"to",
"specify",
"the",
"number",
"of",
"bytes",
"to",
"skip",
"for",
"the",
"transfer",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L430-L461 |
149,130 | jlaffaye/ftp | ftp.go | NameList | func (c *ServerConn) NameList(path string) (entries []string, err error) {
conn, err := c.cmdDataConnFrom(0, "NLST %s", path)
if err != nil {
return
}
r := &Response{conn: conn, c: c}
defer r.Close()
scanner := bufio.NewScanner(r)
for scanner.Scan() {
entries = append(entries, scanner.Text())
}
if err = scanner.Err(); err != nil {
return entries, err
}
return
} | go | func (c *ServerConn) NameList(path string) (entries []string, err error) {
conn, err := c.cmdDataConnFrom(0, "NLST %s", path)
if err != nil {
return
}
r := &Response{conn: conn, c: c}
defer r.Close()
scanner := bufio.NewScanner(r)
for scanner.Scan() {
entries = append(entries, scanner.Text())
}
if err = scanner.Err(); err != nil {
return entries, err
}
return
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"NameList",
"(",
"path",
"string",
")",
"(",
"entries",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"c",
".",
"cmdDataConnFrom",
"(",
"0",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"r",
":=",
"&",
"Response",
"{",
"conn",
":",
"conn",
",",
"c",
":",
"c",
"}",
"\n",
"defer",
"r",
".",
"Close",
"(",
")",
"\n\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"r",
")",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"entries",
"=",
"append",
"(",
"entries",
",",
"scanner",
".",
"Text",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"=",
"scanner",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"entries",
",",
"err",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // NameList issues an NLST FTP command. | [
"NameList",
"issues",
"an",
"NLST",
"FTP",
"command",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L464-L481 |
149,131 | jlaffaye/ftp | ftp.go | List | func (c *ServerConn) List(path string) (entries []*Entry, err error) {
var cmd string
var parser parseFunc
if c.mlstSupported {
cmd = "MLSD"
parser = parseRFC3659ListLine
} else {
cmd = "LIST"
parser = parseListLine
}
conn, err := c.cmdDataConnFrom(0, "%s %s", cmd, path)
if err != nil {
return
}
r := &Response{conn: conn, c: c}
defer r.Close()
scanner := bufio.NewScanner(r)
now := time.Now()
for scanner.Scan() {
entry, err := parser(scanner.Text(), now, c.options.location)
if err == nil {
entries = append(entries, entry)
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return
} | go | func (c *ServerConn) List(path string) (entries []*Entry, err error) {
var cmd string
var parser parseFunc
if c.mlstSupported {
cmd = "MLSD"
parser = parseRFC3659ListLine
} else {
cmd = "LIST"
parser = parseListLine
}
conn, err := c.cmdDataConnFrom(0, "%s %s", cmd, path)
if err != nil {
return
}
r := &Response{conn: conn, c: c}
defer r.Close()
scanner := bufio.NewScanner(r)
now := time.Now()
for scanner.Scan() {
entry, err := parser(scanner.Text(), now, c.options.location)
if err == nil {
entries = append(entries, entry)
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"List",
"(",
"path",
"string",
")",
"(",
"entries",
"[",
"]",
"*",
"Entry",
",",
"err",
"error",
")",
"{",
"var",
"cmd",
"string",
"\n",
"var",
"parser",
"parseFunc",
"\n\n",
"if",
"c",
".",
"mlstSupported",
"{",
"cmd",
"=",
"\"",
"\"",
"\n",
"parser",
"=",
"parseRFC3659ListLine",
"\n",
"}",
"else",
"{",
"cmd",
"=",
"\"",
"\"",
"\n",
"parser",
"=",
"parseListLine",
"\n",
"}",
"\n\n",
"conn",
",",
"err",
":=",
"c",
".",
"cmdDataConnFrom",
"(",
"0",
",",
"\"",
"\"",
",",
"cmd",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"r",
":=",
"&",
"Response",
"{",
"conn",
":",
"conn",
",",
"c",
":",
"c",
"}",
"\n",
"defer",
"r",
".",
"Close",
"(",
")",
"\n\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"r",
")",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"entry",
",",
"err",
":=",
"parser",
"(",
"scanner",
".",
"Text",
"(",
")",
",",
"now",
",",
"c",
".",
"options",
".",
"location",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"entries",
"=",
"append",
"(",
"entries",
",",
"entry",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"scanner",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // List issues a LIST FTP command. | [
"List",
"issues",
"a",
"LIST",
"FTP",
"command",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L484-L516 |
149,132 | jlaffaye/ftp | ftp.go | ChangeDirToParent | func (c *ServerConn) ChangeDirToParent() error {
_, _, err := c.cmd(StatusRequestedFileActionOK, "CDUP")
return err
} | go | func (c *ServerConn) ChangeDirToParent() error {
_, _, err := c.cmd(StatusRequestedFileActionOK, "CDUP")
return err
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"ChangeDirToParent",
"(",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusRequestedFileActionOK",
",",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ChangeDirToParent issues a CDUP FTP command, which changes the current
// directory to the parent directory. This is similar to a call to ChangeDir
// with a path set to "..". | [
"ChangeDirToParent",
"issues",
"a",
"CDUP",
"FTP",
"command",
"which",
"changes",
"the",
"current",
"directory",
"to",
"the",
"parent",
"directory",
".",
"This",
"is",
"similar",
"to",
"a",
"call",
"to",
"ChangeDir",
"with",
"a",
"path",
"set",
"to",
"..",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L528-L531 |
149,133 | jlaffaye/ftp | ftp.go | CurrentDir | func (c *ServerConn) CurrentDir() (string, error) {
_, msg, err := c.cmd(StatusPathCreated, "PWD")
if err != nil {
return "", err
}
start := strings.Index(msg, "\"")
end := strings.LastIndex(msg, "\"")
if start == -1 || end == -1 {
return "", errors.New("unsuported PWD response format")
}
return msg[start+1 : end], nil
} | go | func (c *ServerConn) CurrentDir() (string, error) {
_, msg, err := c.cmd(StatusPathCreated, "PWD")
if err != nil {
return "", err
}
start := strings.Index(msg, "\"")
end := strings.LastIndex(msg, "\"")
if start == -1 || end == -1 {
return "", errors.New("unsuported PWD response format")
}
return msg[start+1 : end], nil
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"CurrentDir",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"_",
",",
"msg",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusPathCreated",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"start",
":=",
"strings",
".",
"Index",
"(",
"msg",
",",
"\"",
"\\\"",
"\"",
")",
"\n",
"end",
":=",
"strings",
".",
"LastIndex",
"(",
"msg",
",",
"\"",
"\\\"",
"\"",
")",
"\n\n",
"if",
"start",
"==",
"-",
"1",
"||",
"end",
"==",
"-",
"1",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"msg",
"[",
"start",
"+",
"1",
":",
"end",
"]",
",",
"nil",
"\n",
"}"
] | // CurrentDir issues a PWD FTP command, which Returns the path of the current
// directory. | [
"CurrentDir",
"issues",
"a",
"PWD",
"FTP",
"command",
"which",
"Returns",
"the",
"path",
"of",
"the",
"current",
"directory",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L535-L549 |
149,134 | jlaffaye/ftp | ftp.go | FileSize | func (c *ServerConn) FileSize(path string) (int64, error) {
_, msg, err := c.cmd(StatusFile, "SIZE %s", path)
if err != nil {
return 0, err
}
return strconv.ParseInt(msg, 10, 64)
} | go | func (c *ServerConn) FileSize(path string) (int64, error) {
_, msg, err := c.cmd(StatusFile, "SIZE %s", path)
if err != nil {
return 0, err
}
return strconv.ParseInt(msg, 10, 64)
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"FileSize",
"(",
"path",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"_",
",",
"msg",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusFile",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"strconv",
".",
"ParseInt",
"(",
"msg",
",",
"10",
",",
"64",
")",
"\n",
"}"
] | // FileSize issues a SIZE FTP command, which Returns the size of the file | [
"FileSize",
"issues",
"a",
"SIZE",
"FTP",
"command",
"which",
"Returns",
"the",
"size",
"of",
"the",
"file"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L552-L559 |
149,135 | jlaffaye/ftp | ftp.go | Retr | func (c *ServerConn) Retr(path string) (*Response, error) {
return c.RetrFrom(path, 0)
} | go | func (c *ServerConn) Retr(path string) (*Response, error) {
return c.RetrFrom(path, 0)
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"Retr",
"(",
"path",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"return",
"c",
".",
"RetrFrom",
"(",
"path",
",",
"0",
")",
"\n",
"}"
] | // Retr issues a RETR FTP command to fetch the specified file from the remote
// FTP server.
//
// The returned ReadCloser must be closed to cleanup the FTP data connection. | [
"Retr",
"issues",
"a",
"RETR",
"FTP",
"command",
"to",
"fetch",
"the",
"specified",
"file",
"from",
"the",
"remote",
"FTP",
"server",
".",
"The",
"returned",
"ReadCloser",
"must",
"be",
"closed",
"to",
"cleanup",
"the",
"FTP",
"data",
"connection",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L565-L567 |
149,136 | jlaffaye/ftp | ftp.go | RetrFrom | func (c *ServerConn) RetrFrom(path string, offset uint64) (*Response, error) {
conn, err := c.cmdDataConnFrom(offset, "RETR %s", path)
if err != nil {
return nil, err
}
return &Response{conn: conn, c: c}, nil
} | go | func (c *ServerConn) RetrFrom(path string, offset uint64) (*Response, error) {
conn, err := c.cmdDataConnFrom(offset, "RETR %s", path)
if err != nil {
return nil, err
}
return &Response{conn: conn, c: c}, nil
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"RetrFrom",
"(",
"path",
"string",
",",
"offset",
"uint64",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"c",
".",
"cmdDataConnFrom",
"(",
"offset",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Response",
"{",
"conn",
":",
"conn",
",",
"c",
":",
"c",
"}",
",",
"nil",
"\n",
"}"
] | // RetrFrom issues a RETR FTP command to fetch the specified file from the remote
// FTP server, the server will not send the offset first bytes of the file.
//
// The returned ReadCloser must be closed to cleanup the FTP data connection. | [
"RetrFrom",
"issues",
"a",
"RETR",
"FTP",
"command",
"to",
"fetch",
"the",
"specified",
"file",
"from",
"the",
"remote",
"FTP",
"server",
"the",
"server",
"will",
"not",
"send",
"the",
"offset",
"first",
"bytes",
"of",
"the",
"file",
".",
"The",
"returned",
"ReadCloser",
"must",
"be",
"closed",
"to",
"cleanup",
"the",
"FTP",
"data",
"connection",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L573-L580 |
149,137 | jlaffaye/ftp | ftp.go | Rename | func (c *ServerConn) Rename(from, to string) error {
_, _, err := c.cmd(StatusRequestFilePending, "RNFR %s", from)
if err != nil {
return err
}
_, _, err = c.cmd(StatusRequestedFileActionOK, "RNTO %s", to)
return err
} | go | func (c *ServerConn) Rename(from, to string) error {
_, _, err := c.cmd(StatusRequestFilePending, "RNFR %s", from)
if err != nil {
return err
}
_, _, err = c.cmd(StatusRequestedFileActionOK, "RNTO %s", to)
return err
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"Rename",
"(",
"from",
",",
"to",
"string",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusRequestFilePending",
",",
"\"",
"\"",
",",
"from",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
"=",
"c",
".",
"cmd",
"(",
"StatusRequestedFileActionOK",
",",
"\"",
"\"",
",",
"to",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Rename renames a file on the remote FTP server. | [
"Rename",
"renames",
"a",
"file",
"on",
"the",
"remote",
"FTP",
"server",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L612-L620 |
149,138 | jlaffaye/ftp | ftp.go | Delete | func (c *ServerConn) Delete(path string) error {
_, _, err := c.cmd(StatusRequestedFileActionOK, "DELE %s", path)
return err
} | go | func (c *ServerConn) Delete(path string) error {
_, _, err := c.cmd(StatusRequestedFileActionOK, "DELE %s", path)
return err
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"Delete",
"(",
"path",
"string",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusRequestedFileActionOK",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Delete issues a DELE FTP command to delete the specified file from the
// remote FTP server. | [
"Delete",
"issues",
"a",
"DELE",
"FTP",
"command",
"to",
"delete",
"the",
"specified",
"file",
"from",
"the",
"remote",
"FTP",
"server",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L624-L627 |
149,139 | jlaffaye/ftp | ftp.go | RemoveDirRecur | func (c *ServerConn) RemoveDirRecur(path string) error {
err := c.ChangeDir(path)
if err != nil {
return err
}
currentDir, err := c.CurrentDir()
if err != nil {
return err
}
entries, err := c.List(currentDir)
if err != nil {
return err
}
for _, entry := range entries {
if entry.Name != ".." && entry.Name != "." {
if entry.Type == EntryTypeFolder {
err = c.RemoveDirRecur(currentDir + "/" + entry.Name)
if err != nil {
return err
}
} else {
err = c.Delete(entry.Name)
if err != nil {
return err
}
}
}
}
err = c.ChangeDirToParent()
if err != nil {
return err
}
err = c.RemoveDir(currentDir)
return err
} | go | func (c *ServerConn) RemoveDirRecur(path string) error {
err := c.ChangeDir(path)
if err != nil {
return err
}
currentDir, err := c.CurrentDir()
if err != nil {
return err
}
entries, err := c.List(currentDir)
if err != nil {
return err
}
for _, entry := range entries {
if entry.Name != ".." && entry.Name != "." {
if entry.Type == EntryTypeFolder {
err = c.RemoveDirRecur(currentDir + "/" + entry.Name)
if err != nil {
return err
}
} else {
err = c.Delete(entry.Name)
if err != nil {
return err
}
}
}
}
err = c.ChangeDirToParent()
if err != nil {
return err
}
err = c.RemoveDir(currentDir)
return err
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"RemoveDirRecur",
"(",
"path",
"string",
")",
"error",
"{",
"err",
":=",
"c",
".",
"ChangeDir",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"currentDir",
",",
"err",
":=",
"c",
".",
"CurrentDir",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"entries",
",",
"err",
":=",
"c",
".",
"List",
"(",
"currentDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"entry",
":=",
"range",
"entries",
"{",
"if",
"entry",
".",
"Name",
"!=",
"\"",
"\"",
"&&",
"entry",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"if",
"entry",
".",
"Type",
"==",
"EntryTypeFolder",
"{",
"err",
"=",
"c",
".",
"RemoveDirRecur",
"(",
"currentDir",
"+",
"\"",
"\"",
"+",
"entry",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"err",
"=",
"c",
".",
"Delete",
"(",
"entry",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"err",
"=",
"c",
".",
"ChangeDirToParent",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"c",
".",
"RemoveDir",
"(",
"currentDir",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // RemoveDirRecur deletes a non-empty folder recursively using
// RemoveDir and Delete | [
"RemoveDirRecur",
"deletes",
"a",
"non",
"-",
"empty",
"folder",
"recursively",
"using",
"RemoveDir",
"and",
"Delete"
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L631-L667 |
149,140 | jlaffaye/ftp | ftp.go | MakeDir | func (c *ServerConn) MakeDir(path string) error {
_, _, err := c.cmd(StatusPathCreated, "MKD %s", path)
return err
} | go | func (c *ServerConn) MakeDir(path string) error {
_, _, err := c.cmd(StatusPathCreated, "MKD %s", path)
return err
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"MakeDir",
"(",
"path",
"string",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusPathCreated",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // MakeDir issues a MKD FTP command to create the specified directory on the
// remote FTP server. | [
"MakeDir",
"issues",
"a",
"MKD",
"FTP",
"command",
"to",
"create",
"the",
"specified",
"directory",
"on",
"the",
"remote",
"FTP",
"server",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L671-L674 |
149,141 | jlaffaye/ftp | ftp.go | NoOp | func (c *ServerConn) NoOp() error {
_, _, err := c.cmd(StatusCommandOK, "NOOP")
return err
} | go | func (c *ServerConn) NoOp() error {
_, _, err := c.cmd(StatusCommandOK, "NOOP")
return err
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"NoOp",
"(",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusCommandOK",
",",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // NoOp issues a NOOP FTP command.
// NOOP has no effects and is usually used to prevent the remote FTP server to
// close the otherwise idle connection. | [
"NoOp",
"issues",
"a",
"NOOP",
"FTP",
"command",
".",
"NOOP",
"has",
"no",
"effects",
"and",
"is",
"usually",
"used",
"to",
"prevent",
"the",
"remote",
"FTP",
"server",
"to",
"close",
"the",
"otherwise",
"idle",
"connection",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L686-L689 |
149,142 | jlaffaye/ftp | ftp.go | Logout | func (c *ServerConn) Logout() error {
_, _, err := c.cmd(StatusReady, "REIN")
return err
} | go | func (c *ServerConn) Logout() error {
_, _, err := c.cmd(StatusReady, "REIN")
return err
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"Logout",
"(",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"cmd",
"(",
"StatusReady",
",",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Logout issues a REIN FTP command to logout the current user. | [
"Logout",
"issues",
"a",
"REIN",
"FTP",
"command",
"to",
"logout",
"the",
"current",
"user",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L692-L695 |
149,143 | jlaffaye/ftp | ftp.go | Quit | func (c *ServerConn) Quit() error {
c.conn.Cmd("QUIT")
return c.conn.Close()
} | go | func (c *ServerConn) Quit() error {
c.conn.Cmd("QUIT")
return c.conn.Close()
} | [
"func",
"(",
"c",
"*",
"ServerConn",
")",
"Quit",
"(",
")",
"error",
"{",
"c",
".",
"conn",
".",
"Cmd",
"(",
"\"",
"\"",
")",
"\n",
"return",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Quit issues a QUIT FTP command to properly close the connection from the
// remote FTP server. | [
"Quit",
"issues",
"a",
"QUIT",
"FTP",
"command",
"to",
"properly",
"close",
"the",
"connection",
"from",
"the",
"remote",
"FTP",
"server",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L699-L702 |
149,144 | jlaffaye/ftp | ftp.go | Read | func (r *Response) Read(buf []byte) (int, error) {
return r.conn.Read(buf)
} | go | func (r *Response) Read(buf []byte) (int, error) {
return r.conn.Read(buf)
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Read",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"r",
".",
"conn",
".",
"Read",
"(",
"buf",
")",
"\n",
"}"
] | // Read implements the io.Reader interface on a FTP data connection. | [
"Read",
"implements",
"the",
"io",
".",
"Reader",
"interface",
"on",
"a",
"FTP",
"data",
"connection",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L705-L707 |
149,145 | jlaffaye/ftp | ftp.go | Close | func (r *Response) Close() error {
if r.closed {
return nil
}
err := r.conn.Close()
_, _, err2 := r.c.conn.ReadResponse(StatusClosingDataConnection)
if err2 != nil {
err = err2
}
r.closed = true
return err
} | go | func (r *Response) Close() error {
if r.closed {
return nil
}
err := r.conn.Close()
_, _, err2 := r.c.conn.ReadResponse(StatusClosingDataConnection)
if err2 != nil {
err = err2
}
r.closed = true
return err
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"r",
".",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"err",
":=",
"r",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"_",
",",
"_",
",",
"err2",
":=",
"r",
".",
"c",
".",
"conn",
".",
"ReadResponse",
"(",
"StatusClosingDataConnection",
")",
"\n",
"if",
"err2",
"!=",
"nil",
"{",
"err",
"=",
"err2",
"\n",
"}",
"\n",
"r",
".",
"closed",
"=",
"true",
"\n",
"return",
"err",
"\n",
"}"
] | // Close implements the io.Closer interface on a FTP data connection.
// After the first call, Close will do nothing and return nil. | [
"Close",
"implements",
"the",
"io",
".",
"Closer",
"interface",
"on",
"a",
"FTP",
"data",
"connection",
".",
"After",
"the",
"first",
"call",
"Close",
"will",
"do",
"nothing",
"and",
"return",
"nil",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L711-L722 |
149,146 | jlaffaye/ftp | ftp.go | SetDeadline | func (r *Response) SetDeadline(t time.Time) error {
return r.conn.SetDeadline(t)
} | go | func (r *Response) SetDeadline(t time.Time) error {
return r.conn.SetDeadline(t)
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"return",
"r",
".",
"conn",
".",
"SetDeadline",
"(",
"t",
")",
"\n",
"}"
] | // SetDeadline sets the deadlines associated with the connection. | [
"SetDeadline",
"sets",
"the",
"deadlines",
"associated",
"with",
"the",
"connection",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L725-L727 |
149,147 | jlaffaye/ftp | parse.go | parseRFC3659ListLine | func parseRFC3659ListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
iSemicolon := strings.Index(line, ";")
iWhitespace := strings.Index(line, " ")
if iSemicolon < 0 || iSemicolon > iWhitespace {
return nil, errUnsupportedListLine
}
e := &Entry{
Name: line[iWhitespace+1:],
}
for _, field := range strings.Split(line[:iWhitespace-1], ";") {
i := strings.Index(field, "=")
if i < 1 {
return nil, errUnsupportedListLine
}
key := strings.ToLower(field[:i])
value := field[i+1:]
switch key {
case "modify":
var err error
e.Time, err = time.ParseInLocation("20060102150405", value, loc)
if err != nil {
return nil, err
}
case "type":
switch value {
case "dir", "cdir", "pdir":
e.Type = EntryTypeFolder
case "file":
e.Type = EntryTypeFile
}
case "size":
e.setSize(value)
}
}
return e, nil
} | go | func parseRFC3659ListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
iSemicolon := strings.Index(line, ";")
iWhitespace := strings.Index(line, " ")
if iSemicolon < 0 || iSemicolon > iWhitespace {
return nil, errUnsupportedListLine
}
e := &Entry{
Name: line[iWhitespace+1:],
}
for _, field := range strings.Split(line[:iWhitespace-1], ";") {
i := strings.Index(field, "=")
if i < 1 {
return nil, errUnsupportedListLine
}
key := strings.ToLower(field[:i])
value := field[i+1:]
switch key {
case "modify":
var err error
e.Time, err = time.ParseInLocation("20060102150405", value, loc)
if err != nil {
return nil, err
}
case "type":
switch value {
case "dir", "cdir", "pdir":
e.Type = EntryTypeFolder
case "file":
e.Type = EntryTypeFile
}
case "size":
e.setSize(value)
}
}
return e, nil
} | [
"func",
"parseRFC3659ListLine",
"(",
"line",
"string",
",",
"now",
"time",
".",
"Time",
",",
"loc",
"*",
"time",
".",
"Location",
")",
"(",
"*",
"Entry",
",",
"error",
")",
"{",
"iSemicolon",
":=",
"strings",
".",
"Index",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"iWhitespace",
":=",
"strings",
".",
"Index",
"(",
"line",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"iSemicolon",
"<",
"0",
"||",
"iSemicolon",
">",
"iWhitespace",
"{",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n\n",
"e",
":=",
"&",
"Entry",
"{",
"Name",
":",
"line",
"[",
"iWhitespace",
"+",
"1",
":",
"]",
",",
"}",
"\n\n",
"for",
"_",
",",
"field",
":=",
"range",
"strings",
".",
"Split",
"(",
"line",
"[",
":",
"iWhitespace",
"-",
"1",
"]",
",",
"\"",
"\"",
")",
"{",
"i",
":=",
"strings",
".",
"Index",
"(",
"field",
",",
"\"",
"\"",
")",
"\n",
"if",
"i",
"<",
"1",
"{",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n\n",
"key",
":=",
"strings",
".",
"ToLower",
"(",
"field",
"[",
":",
"i",
"]",
")",
"\n",
"value",
":=",
"field",
"[",
"i",
"+",
"1",
":",
"]",
"\n\n",
"switch",
"key",
"{",
"case",
"\"",
"\"",
":",
"var",
"err",
"error",
"\n",
"e",
".",
"Time",
",",
"err",
"=",
"time",
".",
"ParseInLocation",
"(",
"\"",
"\"",
",",
"value",
",",
"loc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"switch",
"value",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"e",
".",
"Type",
"=",
"EntryTypeFolder",
"\n",
"case",
"\"",
"\"",
":",
"e",
".",
"Type",
"=",
"EntryTypeFile",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"e",
".",
"setSize",
"(",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"e",
",",
"nil",
"\n",
"}"
] | // parseRFC3659ListLine parses the style of directory line defined in RFC 3659. | [
"parseRFC3659ListLine",
"parses",
"the",
"style",
"of",
"directory",
"line",
"defined",
"in",
"RFC",
"3659",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/parse.go#L30-L70 |
149,148 | jlaffaye/ftp | parse.go | parseLsListLine | func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
// Has the first field a length of 10 bytes?
if strings.IndexByte(line, ' ') != 10 {
return nil, errUnsupportedListLine
}
scanner := newScanner(line)
fields := scanner.NextFields(6)
if len(fields) < 6 {
return nil, errUnsupportedListLine
}
if fields[1] == "folder" && fields[2] == "0" {
e := &Entry{
Type: EntryTypeFolder,
Name: scanner.Remaining(),
}
if err := e.setTime(fields[3:6], now, loc); err != nil {
return nil, err
}
return e, nil
}
if fields[1] == "0" {
fields = append(fields, scanner.Next())
e := &Entry{
Type: EntryTypeFile,
Name: scanner.Remaining(),
}
if err := e.setSize(fields[2]); err != nil {
return nil, errUnsupportedListLine
}
if err := e.setTime(fields[4:7], now, loc); err != nil {
return nil, err
}
return e, nil
}
// Read two more fields
fields = append(fields, scanner.NextFields(2)...)
if len(fields) < 8 {
return nil, errUnsupportedListLine
}
e := &Entry{
Name: scanner.Remaining(),
}
switch fields[0][0] {
case '-':
e.Type = EntryTypeFile
if err := e.setSize(fields[4]); err != nil {
return nil, err
}
case 'd':
e.Type = EntryTypeFolder
case 'l':
e.Type = EntryTypeLink
default:
return nil, errUnknownListEntryType
}
if err := e.setTime(fields[5:8], now, loc); err != nil {
return nil, err
}
return e, nil
} | go | func parseLsListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
// Has the first field a length of 10 bytes?
if strings.IndexByte(line, ' ') != 10 {
return nil, errUnsupportedListLine
}
scanner := newScanner(line)
fields := scanner.NextFields(6)
if len(fields) < 6 {
return nil, errUnsupportedListLine
}
if fields[1] == "folder" && fields[2] == "0" {
e := &Entry{
Type: EntryTypeFolder,
Name: scanner.Remaining(),
}
if err := e.setTime(fields[3:6], now, loc); err != nil {
return nil, err
}
return e, nil
}
if fields[1] == "0" {
fields = append(fields, scanner.Next())
e := &Entry{
Type: EntryTypeFile,
Name: scanner.Remaining(),
}
if err := e.setSize(fields[2]); err != nil {
return nil, errUnsupportedListLine
}
if err := e.setTime(fields[4:7], now, loc); err != nil {
return nil, err
}
return e, nil
}
// Read two more fields
fields = append(fields, scanner.NextFields(2)...)
if len(fields) < 8 {
return nil, errUnsupportedListLine
}
e := &Entry{
Name: scanner.Remaining(),
}
switch fields[0][0] {
case '-':
e.Type = EntryTypeFile
if err := e.setSize(fields[4]); err != nil {
return nil, err
}
case 'd':
e.Type = EntryTypeFolder
case 'l':
e.Type = EntryTypeLink
default:
return nil, errUnknownListEntryType
}
if err := e.setTime(fields[5:8], now, loc); err != nil {
return nil, err
}
return e, nil
} | [
"func",
"parseLsListLine",
"(",
"line",
"string",
",",
"now",
"time",
".",
"Time",
",",
"loc",
"*",
"time",
".",
"Location",
")",
"(",
"*",
"Entry",
",",
"error",
")",
"{",
"// Has the first field a length of 10 bytes?",
"if",
"strings",
".",
"IndexByte",
"(",
"line",
",",
"' '",
")",
"!=",
"10",
"{",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n\n",
"scanner",
":=",
"newScanner",
"(",
"line",
")",
"\n",
"fields",
":=",
"scanner",
".",
"NextFields",
"(",
"6",
")",
"\n\n",
"if",
"len",
"(",
"fields",
")",
"<",
"6",
"{",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n\n",
"if",
"fields",
"[",
"1",
"]",
"==",
"\"",
"\"",
"&&",
"fields",
"[",
"2",
"]",
"==",
"\"",
"\"",
"{",
"e",
":=",
"&",
"Entry",
"{",
"Type",
":",
"EntryTypeFolder",
",",
"Name",
":",
"scanner",
".",
"Remaining",
"(",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"e",
".",
"setTime",
"(",
"fields",
"[",
"3",
":",
"6",
"]",
",",
"now",
",",
"loc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"e",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"fields",
"[",
"1",
"]",
"==",
"\"",
"\"",
"{",
"fields",
"=",
"append",
"(",
"fields",
",",
"scanner",
".",
"Next",
"(",
")",
")",
"\n",
"e",
":=",
"&",
"Entry",
"{",
"Type",
":",
"EntryTypeFile",
",",
"Name",
":",
"scanner",
".",
"Remaining",
"(",
")",
",",
"}",
"\n\n",
"if",
"err",
":=",
"e",
".",
"setSize",
"(",
"fields",
"[",
"2",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n",
"if",
"err",
":=",
"e",
".",
"setTime",
"(",
"fields",
"[",
"4",
":",
"7",
"]",
",",
"now",
",",
"loc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"e",
",",
"nil",
"\n",
"}",
"\n\n",
"// Read two more fields",
"fields",
"=",
"append",
"(",
"fields",
",",
"scanner",
".",
"NextFields",
"(",
"2",
")",
"...",
")",
"\n",
"if",
"len",
"(",
"fields",
")",
"<",
"8",
"{",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n\n",
"e",
":=",
"&",
"Entry",
"{",
"Name",
":",
"scanner",
".",
"Remaining",
"(",
")",
",",
"}",
"\n",
"switch",
"fields",
"[",
"0",
"]",
"[",
"0",
"]",
"{",
"case",
"'-'",
":",
"e",
".",
"Type",
"=",
"EntryTypeFile",
"\n",
"if",
"err",
":=",
"e",
".",
"setSize",
"(",
"fields",
"[",
"4",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"case",
"'d'",
":",
"e",
".",
"Type",
"=",
"EntryTypeFolder",
"\n",
"case",
"'l'",
":",
"e",
".",
"Type",
"=",
"EntryTypeLink",
"\n",
"default",
":",
"return",
"nil",
",",
"errUnknownListEntryType",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"e",
".",
"setTime",
"(",
"fields",
"[",
"5",
":",
"8",
"]",
",",
"now",
",",
"loc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"e",
",",
"nil",
"\n",
"}"
] | // parseLsListLine parses a directory line in a format based on the output of
// the UNIX ls command. | [
"parseLsListLine",
"parses",
"a",
"directory",
"line",
"in",
"a",
"format",
"based",
"on",
"the",
"output",
"of",
"the",
"UNIX",
"ls",
"command",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/parse.go#L74-L145 |
149,149 | jlaffaye/ftp | parse.go | parseDirListLine | func parseDirListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
e := &Entry{}
var err error
// Try various time formats that DIR might use, and stop when one works.
for _, format := range dirTimeFormats {
if len(line) > len(format) {
e.Time, err = time.ParseInLocation(format, line[:len(format)], loc)
if err == nil {
line = line[len(format):]
break
}
}
}
if err != nil {
// None of the time formats worked.
return nil, errUnsupportedListLine
}
line = strings.TrimLeft(line, " ")
if strings.HasPrefix(line, "<DIR>") {
e.Type = EntryTypeFolder
line = strings.TrimPrefix(line, "<DIR>")
} else {
space := strings.Index(line, " ")
if space == -1 {
return nil, errUnsupportedListLine
}
e.Size, err = strconv.ParseUint(line[:space], 10, 64)
if err != nil {
return nil, errUnsupportedListLine
}
e.Type = EntryTypeFile
line = line[space:]
}
e.Name = strings.TrimLeft(line, " ")
return e, nil
} | go | func parseDirListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
e := &Entry{}
var err error
// Try various time formats that DIR might use, and stop when one works.
for _, format := range dirTimeFormats {
if len(line) > len(format) {
e.Time, err = time.ParseInLocation(format, line[:len(format)], loc)
if err == nil {
line = line[len(format):]
break
}
}
}
if err != nil {
// None of the time formats worked.
return nil, errUnsupportedListLine
}
line = strings.TrimLeft(line, " ")
if strings.HasPrefix(line, "<DIR>") {
e.Type = EntryTypeFolder
line = strings.TrimPrefix(line, "<DIR>")
} else {
space := strings.Index(line, " ")
if space == -1 {
return nil, errUnsupportedListLine
}
e.Size, err = strconv.ParseUint(line[:space], 10, 64)
if err != nil {
return nil, errUnsupportedListLine
}
e.Type = EntryTypeFile
line = line[space:]
}
e.Name = strings.TrimLeft(line, " ")
return e, nil
} | [
"func",
"parseDirListLine",
"(",
"line",
"string",
",",
"now",
"time",
".",
"Time",
",",
"loc",
"*",
"time",
".",
"Location",
")",
"(",
"*",
"Entry",
",",
"error",
")",
"{",
"e",
":=",
"&",
"Entry",
"{",
"}",
"\n",
"var",
"err",
"error",
"\n\n",
"// Try various time formats that DIR might use, and stop when one works.",
"for",
"_",
",",
"format",
":=",
"range",
"dirTimeFormats",
"{",
"if",
"len",
"(",
"line",
")",
">",
"len",
"(",
"format",
")",
"{",
"e",
".",
"Time",
",",
"err",
"=",
"time",
".",
"ParseInLocation",
"(",
"format",
",",
"line",
"[",
":",
"len",
"(",
"format",
")",
"]",
",",
"loc",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"line",
"=",
"line",
"[",
"len",
"(",
"format",
")",
":",
"]",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// None of the time formats worked.",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n\n",
"line",
"=",
"strings",
".",
"TrimLeft",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"line",
",",
"\"",
"\"",
")",
"{",
"e",
".",
"Type",
"=",
"EntryTypeFolder",
"\n",
"line",
"=",
"strings",
".",
"TrimPrefix",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"space",
":=",
"strings",
".",
"Index",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"if",
"space",
"==",
"-",
"1",
"{",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n",
"e",
".",
"Size",
",",
"err",
"=",
"strconv",
".",
"ParseUint",
"(",
"line",
"[",
":",
"space",
"]",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}",
"\n",
"e",
".",
"Type",
"=",
"EntryTypeFile",
"\n",
"line",
"=",
"line",
"[",
"space",
":",
"]",
"\n",
"}",
"\n\n",
"e",
".",
"Name",
"=",
"strings",
".",
"TrimLeft",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"return",
"e",
",",
"nil",
"\n",
"}"
] | // parseDirListLine parses a directory line in a format based on the output of
// the MS-DOS DIR command. | [
"parseDirListLine",
"parses",
"a",
"directory",
"line",
"in",
"a",
"format",
"based",
"on",
"the",
"output",
"of",
"the",
"MS",
"-",
"DOS",
"DIR",
"command",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/parse.go#L149-L187 |
149,150 | jlaffaye/ftp | parse.go | parseListLine | func parseListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
for _, f := range listLineParsers {
e, err := f(line, now, loc)
if err != errUnsupportedListLine {
return e, err
}
}
return nil, errUnsupportedListLine
} | go | func parseListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
for _, f := range listLineParsers {
e, err := f(line, now, loc)
if err != errUnsupportedListLine {
return e, err
}
}
return nil, errUnsupportedListLine
} | [
"func",
"parseListLine",
"(",
"line",
"string",
",",
"now",
"time",
".",
"Time",
",",
"loc",
"*",
"time",
".",
"Location",
")",
"(",
"*",
"Entry",
",",
"error",
")",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"listLineParsers",
"{",
"e",
",",
"err",
":=",
"f",
"(",
"line",
",",
"now",
",",
"loc",
")",
"\n",
"if",
"err",
"!=",
"errUnsupportedListLine",
"{",
"return",
"e",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errUnsupportedListLine",
"\n",
"}"
] | // parseListLine parses the various non-standard format returned by the LIST
// FTP command. | [
"parseListLine",
"parses",
"the",
"various",
"non",
"-",
"standard",
"format",
"returned",
"by",
"the",
"LIST",
"FTP",
"command",
"."
] | 6a014d5e22e6a0b7c1fcb65f59872e4dd1227111 | https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/parse.go#L212-L220 |
149,151 | Shopify/ejson | ejson.go | GenerateKeypair | func GenerateKeypair() (pub string, priv string, err error) {
var kp crypto.Keypair
if err := kp.Generate(); err != nil {
return "", "", err
}
return kp.PublicString(), kp.PrivateString(), nil
} | go | func GenerateKeypair() (pub string, priv string, err error) {
var kp crypto.Keypair
if err := kp.Generate(); err != nil {
return "", "", err
}
return kp.PublicString(), kp.PrivateString(), nil
} | [
"func",
"GenerateKeypair",
"(",
")",
"(",
"pub",
"string",
",",
"priv",
"string",
",",
"err",
"error",
")",
"{",
"var",
"kp",
"crypto",
".",
"Keypair",
"\n",
"if",
"err",
":=",
"kp",
".",
"Generate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"kp",
".",
"PublicString",
"(",
")",
",",
"kp",
".",
"PrivateString",
"(",
")",
",",
"nil",
"\n",
"}"
] | // GenerateKeypair is used to create a new ejson keypair. It returns the keys as
// hex-encoded strings, suitable for printing to the screen. hex.DecodeString
// can be used to load the true representation if necessary. | [
"GenerateKeypair",
"is",
"used",
"to",
"create",
"a",
"new",
"ejson",
"keypair",
".",
"It",
"returns",
"the",
"keys",
"as",
"hex",
"-",
"encoded",
"strings",
"suitable",
"for",
"printing",
"to",
"the",
"screen",
".",
"hex",
".",
"DecodeString",
"can",
"be",
"used",
"to",
"load",
"the",
"true",
"representation",
"if",
"necessary",
"."
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/ejson.go#L22-L28 |
149,152 | Shopify/ejson | ejson.go | Encrypt | func Encrypt(in io.Reader, out io.Writer) (int, error) {
data, err := ioutil.ReadAll(in)
if err != nil {
return -1, err
}
var myKP crypto.Keypair
if err = myKP.Generate(); err != nil {
return -1, err
}
pubkey, err := json.ExtractPublicKey(data)
if err != nil {
return -1, err
}
encrypter := myKP.Encrypter(pubkey)
walker := json.Walker{
Action: encrypter.Encrypt,
}
newdata, err := walker.Walk(data)
if err != nil {
return -1, err
}
return out.Write(newdata)
} | go | func Encrypt(in io.Reader, out io.Writer) (int, error) {
data, err := ioutil.ReadAll(in)
if err != nil {
return -1, err
}
var myKP crypto.Keypair
if err = myKP.Generate(); err != nil {
return -1, err
}
pubkey, err := json.ExtractPublicKey(data)
if err != nil {
return -1, err
}
encrypter := myKP.Encrypter(pubkey)
walker := json.Walker{
Action: encrypter.Encrypt,
}
newdata, err := walker.Walk(data)
if err != nil {
return -1, err
}
return out.Write(newdata)
} | [
"func",
"Encrypt",
"(",
"in",
"io",
".",
"Reader",
",",
"out",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"myKP",
"crypto",
".",
"Keypair",
"\n",
"if",
"err",
"=",
"myKP",
".",
"Generate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"pubkey",
",",
"err",
":=",
"json",
".",
"ExtractPublicKey",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"encrypter",
":=",
"myKP",
".",
"Encrypter",
"(",
"pubkey",
")",
"\n",
"walker",
":=",
"json",
".",
"Walker",
"{",
"Action",
":",
"encrypter",
".",
"Encrypt",
",",
"}",
"\n\n",
"newdata",
",",
"err",
":=",
"walker",
".",
"Walk",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"out",
".",
"Write",
"(",
"newdata",
")",
"\n",
"}"
] | // Encrypt reads all contents from 'in', extracts the pubkey
// and performs the requested encryption operation, writing
// the resulting data to 'out'.
// Returns the number of bytes written and any error that might have
// occurred. | [
"Encrypt",
"reads",
"all",
"contents",
"from",
"in",
"extracts",
"the",
"pubkey",
"and",
"performs",
"the",
"requested",
"encryption",
"operation",
"writing",
"the",
"resulting",
"data",
"to",
"out",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"might",
"have",
"occurred",
"."
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/ejson.go#L35-L62 |
149,153 | Shopify/ejson | ejson.go | Decrypt | func Decrypt(in io.Reader, out io.Writer, keydir string, userSuppliedPrivateKey string) error {
data, err := ioutil.ReadAll(in)
if err != nil {
return err
}
pubkey, err := json.ExtractPublicKey(data)
if err != nil {
return err
}
privkey, err := findPrivateKey(pubkey, keydir, userSuppliedPrivateKey)
if err != nil {
return err
}
myKP := crypto.Keypair{
Public: pubkey,
Private: privkey,
}
decrypter := myKP.Decrypter()
walker := json.Walker{
Action: decrypter.Decrypt,
}
newdata, err := walker.Walk(data)
if err != nil {
return err
}
_, err = out.Write(newdata)
return err
} | go | func Decrypt(in io.Reader, out io.Writer, keydir string, userSuppliedPrivateKey string) error {
data, err := ioutil.ReadAll(in)
if err != nil {
return err
}
pubkey, err := json.ExtractPublicKey(data)
if err != nil {
return err
}
privkey, err := findPrivateKey(pubkey, keydir, userSuppliedPrivateKey)
if err != nil {
return err
}
myKP := crypto.Keypair{
Public: pubkey,
Private: privkey,
}
decrypter := myKP.Decrypter()
walker := json.Walker{
Action: decrypter.Decrypt,
}
newdata, err := walker.Walk(data)
if err != nil {
return err
}
_, err = out.Write(newdata)
return err
} | [
"func",
"Decrypt",
"(",
"in",
"io",
".",
"Reader",
",",
"out",
"io",
".",
"Writer",
",",
"keydir",
"string",
",",
"userSuppliedPrivateKey",
"string",
")",
"error",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"pubkey",
",",
"err",
":=",
"json",
".",
"ExtractPublicKey",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"privkey",
",",
"err",
":=",
"findPrivateKey",
"(",
"pubkey",
",",
"keydir",
",",
"userSuppliedPrivateKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"myKP",
":=",
"crypto",
".",
"Keypair",
"{",
"Public",
":",
"pubkey",
",",
"Private",
":",
"privkey",
",",
"}",
"\n\n",
"decrypter",
":=",
"myKP",
".",
"Decrypter",
"(",
")",
"\n",
"walker",
":=",
"json",
".",
"Walker",
"{",
"Action",
":",
"decrypter",
".",
"Decrypt",
",",
"}",
"\n\n",
"newdata",
",",
"err",
":=",
"walker",
".",
"Walk",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"out",
".",
"Write",
"(",
"newdata",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Decrypt reads an ejson stream from 'in' and writes the decrypted data to 'out'.
// The private key is expected to be under 'keydir'.
// Returns error upon failure, or nil on success. | [
"Decrypt",
"reads",
"an",
"ejson",
"stream",
"from",
"in",
"and",
"writes",
"the",
"decrypted",
"data",
"to",
"out",
".",
"The",
"private",
"key",
"is",
"expected",
"to",
"be",
"under",
"keydir",
".",
"Returns",
"error",
"upon",
"failure",
"or",
"nil",
"on",
"success",
"."
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/ejson.go#L103-L137 |
149,154 | Shopify/ejson | ejson.go | DecryptFile | func DecryptFile(filePath, keydir string, userSuppliedPrivateKey string) ([]byte, error) {
if _, err := os.Stat(filePath); err != nil {
return nil, err
}
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer file.Close()
var outBuffer bytes.Buffer
err = Decrypt(file, &outBuffer, keydir, userSuppliedPrivateKey)
return outBuffer.Bytes(), err
} | go | func DecryptFile(filePath, keydir string, userSuppliedPrivateKey string) ([]byte, error) {
if _, err := os.Stat(filePath); err != nil {
return nil, err
}
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer file.Close()
var outBuffer bytes.Buffer
err = Decrypt(file, &outBuffer, keydir, userSuppliedPrivateKey)
return outBuffer.Bytes(), err
} | [
"func",
"DecryptFile",
"(",
"filePath",
",",
"keydir",
"string",
",",
"userSuppliedPrivateKey",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filePath",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"var",
"outBuffer",
"bytes",
".",
"Buffer",
"\n\n",
"err",
"=",
"Decrypt",
"(",
"file",
",",
"&",
"outBuffer",
",",
"keydir",
",",
"userSuppliedPrivateKey",
")",
"\n\n",
"return",
"outBuffer",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}"
] | // DecryptFile takes a path to an encrypted EJSON file and returns the data
// decrypted. The public key used to encrypt the values is embedded in the
// referenced document, and the matching private key is searched for in keydir.
// There must exist a file in keydir whose name is the public key from the
// EJSON document, and whose contents are the corresponding private key. See
// README.md for more details on this. | [
"DecryptFile",
"takes",
"a",
"path",
"to",
"an",
"encrypted",
"EJSON",
"file",
"and",
"returns",
"the",
"data",
"decrypted",
".",
"The",
"public",
"key",
"used",
"to",
"encrypt",
"the",
"values",
"is",
"embedded",
"in",
"the",
"referenced",
"document",
"and",
"the",
"matching",
"private",
"key",
"is",
"searched",
"for",
"in",
"keydir",
".",
"There",
"must",
"exist",
"a",
"file",
"in",
"keydir",
"whose",
"name",
"is",
"the",
"public",
"key",
"from",
"the",
"EJSON",
"document",
"and",
"whose",
"contents",
"are",
"the",
"corresponding",
"private",
"key",
".",
"See",
"README",
".",
"md",
"for",
"more",
"details",
"on",
"this",
"."
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/ejson.go#L145-L161 |
149,155 | Shopify/ejson | crypto/boxed_message.go | Dump | func (b *boxedMessage) Dump() []byte {
pub := base64.StdEncoding.EncodeToString(b.EncrypterPublic[:])
nonce := base64.StdEncoding.EncodeToString(b.Nonce[:])
box := base64.StdEncoding.EncodeToString(b.Box)
str := fmt.Sprintf("EJ[%d:%s:%s:%s]",
b.SchemaVersion, pub, nonce, box)
return []byte(str)
} | go | func (b *boxedMessage) Dump() []byte {
pub := base64.StdEncoding.EncodeToString(b.EncrypterPublic[:])
nonce := base64.StdEncoding.EncodeToString(b.Nonce[:])
box := base64.StdEncoding.EncodeToString(b.Box)
str := fmt.Sprintf("EJ[%d:%s:%s:%s]",
b.SchemaVersion, pub, nonce, box)
return []byte(str)
} | [
"func",
"(",
"b",
"*",
"boxedMessage",
")",
"Dump",
"(",
")",
"[",
"]",
"byte",
"{",
"pub",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"b",
".",
"EncrypterPublic",
"[",
":",
"]",
")",
"\n",
"nonce",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"b",
".",
"Nonce",
"[",
":",
"]",
")",
"\n",
"box",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"b",
".",
"Box",
")",
"\n\n",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"SchemaVersion",
",",
"pub",
",",
"nonce",
",",
"box",
")",
"\n",
"return",
"[",
"]",
"byte",
"(",
"str",
")",
"\n",
"}"
] | // Dump dumps to the wire format | [
"Dump",
"dumps",
"to",
"the",
"wire",
"format"
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/crypto/boxed_message.go#L39-L47 |
149,156 | Shopify/ejson | crypto/boxed_message.go | Load | func (b *boxedMessage) Load(from []byte) error {
var ssver, spub, snonce, sbox string
var err error
allMatches := messageParser.FindAllStringSubmatch(string(from), -1) // -> [][][]byte
if len(allMatches) != 1 {
return fmt.Errorf("invalid message format")
}
matches := allMatches[0]
if len(matches) != 5 {
return fmt.Errorf("invalid message format")
}
ssver = matches[1]
spub = matches[2]
snonce = matches[3]
sbox = matches[4]
b.SchemaVersion, err = strconv.Atoi(ssver)
if err != nil {
return err
}
pub, err := base64.StdEncoding.DecodeString(spub)
if err != nil {
return err
}
pubBytes := []byte(pub)
if len(pubBytes) != 32 {
return fmt.Errorf("public key invalid")
}
var public [32]byte
copy(public[:], pubBytes[0:32])
b.EncrypterPublic = public
nnc, err := base64.StdEncoding.DecodeString(snonce)
if err != nil {
return err
}
nonceBytes := []byte(nnc)
if len(nonceBytes) != 24 {
return fmt.Errorf("nonce invalid")
}
var nonce [24]byte
copy(nonce[:], nonceBytes[0:24])
b.Nonce = nonce
box, err := base64.StdEncoding.DecodeString(sbox)
if err != nil {
return err
}
b.Box = []byte(box)
return nil
} | go | func (b *boxedMessage) Load(from []byte) error {
var ssver, spub, snonce, sbox string
var err error
allMatches := messageParser.FindAllStringSubmatch(string(from), -1) // -> [][][]byte
if len(allMatches) != 1 {
return fmt.Errorf("invalid message format")
}
matches := allMatches[0]
if len(matches) != 5 {
return fmt.Errorf("invalid message format")
}
ssver = matches[1]
spub = matches[2]
snonce = matches[3]
sbox = matches[4]
b.SchemaVersion, err = strconv.Atoi(ssver)
if err != nil {
return err
}
pub, err := base64.StdEncoding.DecodeString(spub)
if err != nil {
return err
}
pubBytes := []byte(pub)
if len(pubBytes) != 32 {
return fmt.Errorf("public key invalid")
}
var public [32]byte
copy(public[:], pubBytes[0:32])
b.EncrypterPublic = public
nnc, err := base64.StdEncoding.DecodeString(snonce)
if err != nil {
return err
}
nonceBytes := []byte(nnc)
if len(nonceBytes) != 24 {
return fmt.Errorf("nonce invalid")
}
var nonce [24]byte
copy(nonce[:], nonceBytes[0:24])
b.Nonce = nonce
box, err := base64.StdEncoding.DecodeString(sbox)
if err != nil {
return err
}
b.Box = []byte(box)
return nil
} | [
"func",
"(",
"b",
"*",
"boxedMessage",
")",
"Load",
"(",
"from",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ssver",
",",
"spub",
",",
"snonce",
",",
"sbox",
"string",
"\n",
"var",
"err",
"error",
"\n\n",
"allMatches",
":=",
"messageParser",
".",
"FindAllStringSubmatch",
"(",
"string",
"(",
"from",
")",
",",
"-",
"1",
")",
"// -> [][][]byte",
"\n",
"if",
"len",
"(",
"allMatches",
")",
"!=",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"matches",
":=",
"allMatches",
"[",
"0",
"]",
"\n",
"if",
"len",
"(",
"matches",
")",
"!=",
"5",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ssver",
"=",
"matches",
"[",
"1",
"]",
"\n",
"spub",
"=",
"matches",
"[",
"2",
"]",
"\n",
"snonce",
"=",
"matches",
"[",
"3",
"]",
"\n",
"sbox",
"=",
"matches",
"[",
"4",
"]",
"\n\n",
"b",
".",
"SchemaVersion",
",",
"err",
"=",
"strconv",
".",
"Atoi",
"(",
"ssver",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"pub",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"spub",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"pubBytes",
":=",
"[",
"]",
"byte",
"(",
"pub",
")",
"\n",
"if",
"len",
"(",
"pubBytes",
")",
"!=",
"32",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"public",
"[",
"32",
"]",
"byte",
"\n",
"copy",
"(",
"public",
"[",
":",
"]",
",",
"pubBytes",
"[",
"0",
":",
"32",
"]",
")",
"\n",
"b",
".",
"EncrypterPublic",
"=",
"public",
"\n\n",
"nnc",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"snonce",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"nonceBytes",
":=",
"[",
"]",
"byte",
"(",
"nnc",
")",
"\n",
"if",
"len",
"(",
"nonceBytes",
")",
"!=",
"24",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"nonce",
"[",
"24",
"]",
"byte",
"\n",
"copy",
"(",
"nonce",
"[",
":",
"]",
",",
"nonceBytes",
"[",
"0",
":",
"24",
"]",
")",
"\n",
"b",
".",
"Nonce",
"=",
"nonce",
"\n\n",
"box",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"sbox",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"b",
".",
"Box",
"=",
"[",
"]",
"byte",
"(",
"box",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Load restores from the wire format. | [
"Load",
"restores",
"from",
"the",
"wire",
"format",
"."
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/crypto/boxed_message.go#L50-L104 |
149,157 | Shopify/ejson | json/walker.go | quoteBytes | func quoteBytes(in []byte) ([]byte, error) {
data := []string{string(in)}
out, err := json.Marshal(data)
if err != nil {
return nil, err
}
return out[1 : len(out)-1], nil
} | go | func quoteBytes(in []byte) ([]byte, error) {
data := []string{string(in)}
out, err := json.Marshal(data)
if err != nil {
return nil, err
}
return out[1 : len(out)-1], nil
} | [
"func",
"quoteBytes",
"(",
"in",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
":=",
"[",
"]",
"string",
"{",
"string",
"(",
"in",
")",
"}",
"\n",
"out",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"out",
"[",
"1",
":",
"len",
"(",
"out",
")",
"-",
"1",
"]",
",",
"nil",
"\n",
"}"
] | // probably a better way to do this, but... | [
"probably",
"a",
"better",
"way",
"to",
"do",
"this",
"but",
"..."
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/json/walker.go#L126-L133 |
149,158 | Shopify/ejson | json/key.go | ExtractPublicKey | func ExtractPublicKey(data []byte) (key [32]byte, err error) {
var (
obj map[string]interface{}
ks string
ok bool
bs []byte
)
err = json.Unmarshal(data, &obj)
if err != nil {
return
}
k, ok := obj[PublicKeyField]
if !ok {
goto missing
}
ks, ok = k.(string)
if !ok {
goto invalid
}
if len(ks) != 64 {
goto invalid
}
bs, err = hex.DecodeString(ks)
if err != nil {
goto invalid
}
if len(bs) != 32 {
goto invalid
}
copy(key[:], bs)
return
missing:
err = ErrPublicKeyMissing
return
invalid:
err = ErrPublicKeyInvalid
return
} | go | func ExtractPublicKey(data []byte) (key [32]byte, err error) {
var (
obj map[string]interface{}
ks string
ok bool
bs []byte
)
err = json.Unmarshal(data, &obj)
if err != nil {
return
}
k, ok := obj[PublicKeyField]
if !ok {
goto missing
}
ks, ok = k.(string)
if !ok {
goto invalid
}
if len(ks) != 64 {
goto invalid
}
bs, err = hex.DecodeString(ks)
if err != nil {
goto invalid
}
if len(bs) != 32 {
goto invalid
}
copy(key[:], bs)
return
missing:
err = ErrPublicKeyMissing
return
invalid:
err = ErrPublicKeyInvalid
return
} | [
"func",
"ExtractPublicKey",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"key",
"[",
"32",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"var",
"(",
"obj",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"ks",
"string",
"\n",
"ok",
"bool",
"\n",
"bs",
"[",
"]",
"byte",
"\n",
")",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"k",
",",
"ok",
":=",
"obj",
"[",
"PublicKeyField",
"]",
"\n",
"if",
"!",
"ok",
"{",
"goto",
"missing",
"\n",
"}",
"\n",
"ks",
",",
"ok",
"=",
"k",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"goto",
"invalid",
"\n",
"}",
"\n",
"if",
"len",
"(",
"ks",
")",
"!=",
"64",
"{",
"goto",
"invalid",
"\n",
"}",
"\n",
"bs",
",",
"err",
"=",
"hex",
".",
"DecodeString",
"(",
"ks",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"goto",
"invalid",
"\n",
"}",
"\n",
"if",
"len",
"(",
"bs",
")",
"!=",
"32",
"{",
"goto",
"invalid",
"\n",
"}",
"\n",
"copy",
"(",
"key",
"[",
":",
"]",
",",
"bs",
")",
"\n",
"return",
"\n",
"missing",
":",
"err",
"=",
"ErrPublicKeyMissing",
"\n",
"return",
"\n",
"invalid",
":",
"err",
"=",
"ErrPublicKeyInvalid",
"\n",
"return",
"\n",
"}"
] | // ExtractPublicKey finds the _public_key value in an EJSON document and
// parses it into a key usable with the crypto library. | [
"ExtractPublicKey",
"finds",
"the",
"_public_key",
"value",
"in",
"an",
"EJSON",
"document",
"and",
"parses",
"it",
"into",
"a",
"key",
"usable",
"with",
"the",
"crypto",
"library",
"."
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/json/key.go#L25-L62 |
149,159 | Shopify/ejson | crypto/crypto.go | NewEncrypter | func NewEncrypter(kp *Keypair, peerPublic [32]byte) *Encrypter {
var shared [32]byte
box.Precompute(&shared, &peerPublic, &kp.Private)
return &Encrypter{
Keypair: kp,
PeerPublic: peerPublic,
SharedKey: shared,
}
} | go | func NewEncrypter(kp *Keypair, peerPublic [32]byte) *Encrypter {
var shared [32]byte
box.Precompute(&shared, &peerPublic, &kp.Private)
return &Encrypter{
Keypair: kp,
PeerPublic: peerPublic,
SharedKey: shared,
}
} | [
"func",
"NewEncrypter",
"(",
"kp",
"*",
"Keypair",
",",
"peerPublic",
"[",
"32",
"]",
"byte",
")",
"*",
"Encrypter",
"{",
"var",
"shared",
"[",
"32",
"]",
"byte",
"\n",
"box",
".",
"Precompute",
"(",
"&",
"shared",
",",
"&",
"peerPublic",
",",
"&",
"kp",
".",
"Private",
")",
"\n",
"return",
"&",
"Encrypter",
"{",
"Keypair",
":",
"kp",
",",
"PeerPublic",
":",
"peerPublic",
",",
"SharedKey",
":",
"shared",
",",
"}",
"\n",
"}"
] | // NewEncrypter instantiates an Encrypter after pre-computing the shared key for
// the owned keypair and the given decrypter public key. | [
"NewEncrypter",
"instantiates",
"an",
"Encrypter",
"after",
"pre",
"-",
"computing",
"the",
"shared",
"key",
"for",
"the",
"owned",
"keypair",
"and",
"the",
"given",
"decrypter",
"public",
"key",
"."
] | 9d2ed221270221cf82616946316a0a62dca4a4a9 | https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/crypto/crypto.go#L88-L96 |
149,160 | soheilhy/cmux | cmux.go | New | func New(l net.Listener) CMux {
return &cMux{
root: l,
bufLen: 1024,
errh: func(_ error) bool { return true },
donec: make(chan struct{}),
readTimeout: noTimeout,
}
} | go | func New(l net.Listener) CMux {
return &cMux{
root: l,
bufLen: 1024,
errh: func(_ error) bool { return true },
donec: make(chan struct{}),
readTimeout: noTimeout,
}
} | [
"func",
"New",
"(",
"l",
"net",
".",
"Listener",
")",
"CMux",
"{",
"return",
"&",
"cMux",
"{",
"root",
":",
"l",
",",
"bufLen",
":",
"1024",
",",
"errh",
":",
"func",
"(",
"_",
"error",
")",
"bool",
"{",
"return",
"true",
"}",
",",
"donec",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"readTimeout",
":",
"noTimeout",
",",
"}",
"\n",
"}"
] | // New instantiates a new connection multiplexer. | [
"New",
"instantiates",
"a",
"new",
"connection",
"multiplexer",
"."
] | 8a8ea3c53959009183d7914522833c1ed8835020 | https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/cmux.go#L68-L76 |
149,161 | soheilhy/cmux | matchers.go | HTTP1 | func HTTP1() Matcher {
return func(r io.Reader) bool {
br := bufio.NewReader(&io.LimitedReader{R: r, N: maxHTTPRead})
l, part, err := br.ReadLine()
if err != nil || part {
return false
}
_, _, proto, ok := parseRequestLine(string(l))
if !ok {
return false
}
v, _, ok := http.ParseHTTPVersion(proto)
return ok && v == 1
}
} | go | func HTTP1() Matcher {
return func(r io.Reader) bool {
br := bufio.NewReader(&io.LimitedReader{R: r, N: maxHTTPRead})
l, part, err := br.ReadLine()
if err != nil || part {
return false
}
_, _, proto, ok := parseRequestLine(string(l))
if !ok {
return false
}
v, _, ok := http.ParseHTTPVersion(proto)
return ok && v == 1
}
} | [
"func",
"HTTP1",
"(",
")",
"Matcher",
"{",
"return",
"func",
"(",
"r",
"io",
".",
"Reader",
")",
"bool",
"{",
"br",
":=",
"bufio",
".",
"NewReader",
"(",
"&",
"io",
".",
"LimitedReader",
"{",
"R",
":",
"r",
",",
"N",
":",
"maxHTTPRead",
"}",
")",
"\n",
"l",
",",
"part",
",",
"err",
":=",
"br",
".",
"ReadLine",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"part",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"proto",
",",
"ok",
":=",
"parseRequestLine",
"(",
"string",
"(",
"l",
")",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"v",
",",
"_",
",",
"ok",
":=",
"http",
".",
"ParseHTTPVersion",
"(",
"proto",
")",
"\n",
"return",
"ok",
"&&",
"v",
"==",
"1",
"\n",
"}",
"\n",
"}"
] | // HTTP1 parses the first line or upto 4096 bytes of the request to see if
// the conection contains an HTTP request. | [
"HTTP1",
"parses",
"the",
"first",
"line",
"or",
"upto",
"4096",
"bytes",
"of",
"the",
"request",
"to",
"see",
"if",
"the",
"conection",
"contains",
"an",
"HTTP",
"request",
"."
] | 8a8ea3c53959009183d7914522833c1ed8835020 | https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L91-L107 |
149,162 | soheilhy/cmux | matchers.go | HTTP1HeaderField | func HTTP1HeaderField(name, value string) Matcher {
return func(r io.Reader) bool {
return matchHTTP1Field(r, name, func(gotValue string) bool {
return gotValue == value
})
}
} | go | func HTTP1HeaderField(name, value string) Matcher {
return func(r io.Reader) bool {
return matchHTTP1Field(r, name, func(gotValue string) bool {
return gotValue == value
})
}
} | [
"func",
"HTTP1HeaderField",
"(",
"name",
",",
"value",
"string",
")",
"Matcher",
"{",
"return",
"func",
"(",
"r",
"io",
".",
"Reader",
")",
"bool",
"{",
"return",
"matchHTTP1Field",
"(",
"r",
",",
"name",
",",
"func",
"(",
"gotValue",
"string",
")",
"bool",
"{",
"return",
"gotValue",
"==",
"value",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // HTTP1HeaderField returns a matcher matching the header fields of the first
// request of an HTTP 1 connection. | [
"HTTP1HeaderField",
"returns",
"a",
"matcher",
"matching",
"the",
"header",
"fields",
"of",
"the",
"first",
"request",
"of",
"an",
"HTTP",
"1",
"connection",
"."
] | 8a8ea3c53959009183d7914522833c1ed8835020 | https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L128-L134 |
149,163 | soheilhy/cmux | matchers.go | HTTP1HeaderFieldPrefix | func HTTP1HeaderFieldPrefix(name, valuePrefix string) Matcher {
return func(r io.Reader) bool {
return matchHTTP1Field(r, name, func(gotValue string) bool {
return strings.HasPrefix(gotValue, valuePrefix)
})
}
} | go | func HTTP1HeaderFieldPrefix(name, valuePrefix string) Matcher {
return func(r io.Reader) bool {
return matchHTTP1Field(r, name, func(gotValue string) bool {
return strings.HasPrefix(gotValue, valuePrefix)
})
}
} | [
"func",
"HTTP1HeaderFieldPrefix",
"(",
"name",
",",
"valuePrefix",
"string",
")",
"Matcher",
"{",
"return",
"func",
"(",
"r",
"io",
".",
"Reader",
")",
"bool",
"{",
"return",
"matchHTTP1Field",
"(",
"r",
",",
"name",
",",
"func",
"(",
"gotValue",
"string",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"gotValue",
",",
"valuePrefix",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // HTTP1HeaderFieldPrefix returns a matcher matching the header fields of the
// first request of an HTTP 1 connection. If the header with key name has a
// value prefixed with valuePrefix, this will match. | [
"HTTP1HeaderFieldPrefix",
"returns",
"a",
"matcher",
"matching",
"the",
"header",
"fields",
"of",
"the",
"first",
"request",
"of",
"an",
"HTTP",
"1",
"connection",
".",
"If",
"the",
"header",
"with",
"key",
"name",
"has",
"a",
"value",
"prefixed",
"with",
"valuePrefix",
"this",
"will",
"match",
"."
] | 8a8ea3c53959009183d7914522833c1ed8835020 | https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L139-L145 |
149,164 | soheilhy/cmux | matchers.go | HTTP2HeaderField | func HTTP2HeaderField(name, value string) Matcher {
return func(r io.Reader) bool {
return matchHTTP2Field(ioutil.Discard, r, name, func(gotValue string) bool {
return gotValue == value
})
}
} | go | func HTTP2HeaderField(name, value string) Matcher {
return func(r io.Reader) bool {
return matchHTTP2Field(ioutil.Discard, r, name, func(gotValue string) bool {
return gotValue == value
})
}
} | [
"func",
"HTTP2HeaderField",
"(",
"name",
",",
"value",
"string",
")",
"Matcher",
"{",
"return",
"func",
"(",
"r",
"io",
".",
"Reader",
")",
"bool",
"{",
"return",
"matchHTTP2Field",
"(",
"ioutil",
".",
"Discard",
",",
"r",
",",
"name",
",",
"func",
"(",
"gotValue",
"string",
")",
"bool",
"{",
"return",
"gotValue",
"==",
"value",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // HTTP2HeaderField returns a matcher matching the header fields of the first
// headers frame. | [
"HTTP2HeaderField",
"returns",
"a",
"matcher",
"matching",
"the",
"header",
"fields",
"of",
"the",
"first",
"headers",
"frame",
"."
] | 8a8ea3c53959009183d7914522833c1ed8835020 | https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L149-L155 |
149,165 | soheilhy/cmux | matchers.go | HTTP2HeaderFieldPrefix | func HTTP2HeaderFieldPrefix(name, valuePrefix string) Matcher {
return func(r io.Reader) bool {
return matchHTTP2Field(ioutil.Discard, r, name, func(gotValue string) bool {
return strings.HasPrefix(gotValue, valuePrefix)
})
}
} | go | func HTTP2HeaderFieldPrefix(name, valuePrefix string) Matcher {
return func(r io.Reader) bool {
return matchHTTP2Field(ioutil.Discard, r, name, func(gotValue string) bool {
return strings.HasPrefix(gotValue, valuePrefix)
})
}
} | [
"func",
"HTTP2HeaderFieldPrefix",
"(",
"name",
",",
"valuePrefix",
"string",
")",
"Matcher",
"{",
"return",
"func",
"(",
"r",
"io",
".",
"Reader",
")",
"bool",
"{",
"return",
"matchHTTP2Field",
"(",
"ioutil",
".",
"Discard",
",",
"r",
",",
"name",
",",
"func",
"(",
"gotValue",
"string",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"gotValue",
",",
"valuePrefix",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // HTTP2HeaderFieldPrefix returns a matcher matching the header fields of the
// first headers frame. If the header with key name has a value prefixed with
// valuePrefix, this will match. | [
"HTTP2HeaderFieldPrefix",
"returns",
"a",
"matcher",
"matching",
"the",
"header",
"fields",
"of",
"the",
"first",
"headers",
"frame",
".",
"If",
"the",
"header",
"with",
"key",
"name",
"has",
"a",
"value",
"prefixed",
"with",
"valuePrefix",
"this",
"will",
"match",
"."
] | 8a8ea3c53959009183d7914522833c1ed8835020 | https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L160-L166 |
149,166 | soheilhy/cmux | matchers.go | HTTP2MatchHeaderFieldSendSettings | func HTTP2MatchHeaderFieldSendSettings(name, value string) MatchWriter {
return func(w io.Writer, r io.Reader) bool {
return matchHTTP2Field(w, r, name, func(gotValue string) bool {
return gotValue == value
})
}
} | go | func HTTP2MatchHeaderFieldSendSettings(name, value string) MatchWriter {
return func(w io.Writer, r io.Reader) bool {
return matchHTTP2Field(w, r, name, func(gotValue string) bool {
return gotValue == value
})
}
} | [
"func",
"HTTP2MatchHeaderFieldSendSettings",
"(",
"name",
",",
"value",
"string",
")",
"MatchWriter",
"{",
"return",
"func",
"(",
"w",
"io",
".",
"Writer",
",",
"r",
"io",
".",
"Reader",
")",
"bool",
"{",
"return",
"matchHTTP2Field",
"(",
"w",
",",
"r",
",",
"name",
",",
"func",
"(",
"gotValue",
"string",
")",
"bool",
"{",
"return",
"gotValue",
"==",
"value",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // HTTP2MatchHeaderFieldSendSettings matches the header field and writes the
// settings to the server. Prefer HTTP2HeaderField over this one, if the client
// does not block on receiving a SETTING frame. | [
"HTTP2MatchHeaderFieldSendSettings",
"matches",
"the",
"header",
"field",
"and",
"writes",
"the",
"settings",
"to",
"the",
"server",
".",
"Prefer",
"HTTP2HeaderField",
"over",
"this",
"one",
"if",
"the",
"client",
"does",
"not",
"block",
"on",
"receiving",
"a",
"SETTING",
"frame",
"."
] | 8a8ea3c53959009183d7914522833c1ed8835020 | https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L171-L177 |
149,167 | soheilhy/cmux | matchers.go | HTTP2MatchHeaderFieldPrefixSendSettings | func HTTP2MatchHeaderFieldPrefixSendSettings(name, valuePrefix string) MatchWriter {
return func(w io.Writer, r io.Reader) bool {
return matchHTTP2Field(w, r, name, func(gotValue string) bool {
return strings.HasPrefix(gotValue, valuePrefix)
})
}
} | go | func HTTP2MatchHeaderFieldPrefixSendSettings(name, valuePrefix string) MatchWriter {
return func(w io.Writer, r io.Reader) bool {
return matchHTTP2Field(w, r, name, func(gotValue string) bool {
return strings.HasPrefix(gotValue, valuePrefix)
})
}
} | [
"func",
"HTTP2MatchHeaderFieldPrefixSendSettings",
"(",
"name",
",",
"valuePrefix",
"string",
")",
"MatchWriter",
"{",
"return",
"func",
"(",
"w",
"io",
".",
"Writer",
",",
"r",
"io",
".",
"Reader",
")",
"bool",
"{",
"return",
"matchHTTP2Field",
"(",
"w",
",",
"r",
",",
"name",
",",
"func",
"(",
"gotValue",
"string",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"gotValue",
",",
"valuePrefix",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // HTTP2MatchHeaderFieldPrefixSendSettings matches the header field prefix
// and writes the settings to the server. Prefer HTTP2HeaderFieldPrefix over
// this one, if the client does not block on receiving a SETTING frame. | [
"HTTP2MatchHeaderFieldPrefixSendSettings",
"matches",
"the",
"header",
"field",
"prefix",
"and",
"writes",
"the",
"settings",
"to",
"the",
"server",
".",
"Prefer",
"HTTP2HeaderFieldPrefix",
"over",
"this",
"one",
"if",
"the",
"client",
"does",
"not",
"block",
"on",
"receiving",
"a",
"SETTING",
"frame",
"."
] | 8a8ea3c53959009183d7914522833c1ed8835020 | https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L182-L188 |
149,168 | getlantern/systray | systray_windows.go | SetTooltip | func SetTooltip(tooltip string) {
if err := wt.setTooltip(tooltip); err != nil {
log.Errorf("Unable to set tooltip: %v", err)
return
}
} | go | func SetTooltip(tooltip string) {
if err := wt.setTooltip(tooltip); err != nil {
log.Errorf("Unable to set tooltip: %v", err)
return
}
} | [
"func",
"SetTooltip",
"(",
"tooltip",
"string",
")",
"{",
"if",
"err",
":=",
"wt",
".",
"setTooltip",
"(",
"tooltip",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
] | // SetTooltip sets the systray tooltip to display on mouse hover of the tray icon,
// only available on Mac and Windows. | [
"SetTooltip",
"sets",
"the",
"systray",
"tooltip",
"to",
"display",
"on",
"mouse",
"hover",
"of",
"the",
"tray",
"icon",
"only",
"available",
"on",
"Mac",
"and",
"Windows",
"."
] | 26d5b920200dbc1869c4bfde4571497082f83caa | https://github.com/getlantern/systray/blob/26d5b920200dbc1869c4bfde4571497082f83caa/systray_windows.go#L688-L693 |
149,169 | getlantern/systray | systray.go | AddMenuItem | func AddMenuItem(title string, tooltip string) *MenuItem {
id := atomic.AddInt32(¤tID, 1)
item := &MenuItem{nil, id, title, tooltip, false, false}
item.ClickedCh = make(chan struct{})
item.update()
return item
} | go | func AddMenuItem(title string, tooltip string) *MenuItem {
id := atomic.AddInt32(¤tID, 1)
item := &MenuItem{nil, id, title, tooltip, false, false}
item.ClickedCh = make(chan struct{})
item.update()
return item
} | [
"func",
"AddMenuItem",
"(",
"title",
"string",
",",
"tooltip",
"string",
")",
"*",
"MenuItem",
"{",
"id",
":=",
"atomic",
".",
"AddInt32",
"(",
"&",
"currentID",
",",
"1",
")",
"\n",
"item",
":=",
"&",
"MenuItem",
"{",
"nil",
",",
"id",
",",
"title",
",",
"tooltip",
",",
"false",
",",
"false",
"}",
"\n",
"item",
".",
"ClickedCh",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"item",
".",
"update",
"(",
")",
"\n",
"return",
"item",
"\n",
"}"
] | // AddMenuItem adds menu item with designated title and tooltip, returning a channel
// that notifies whenever that menu item is clicked.
//
// It can be safely invoked from different goroutines. | [
"AddMenuItem",
"adds",
"menu",
"item",
"with",
"designated",
"title",
"and",
"tooltip",
"returning",
"a",
"channel",
"that",
"notifies",
"whenever",
"that",
"menu",
"item",
"is",
"clicked",
".",
"It",
"can",
"be",
"safely",
"invoked",
"from",
"different",
"goroutines",
"."
] | 26d5b920200dbc1869c4bfde4571497082f83caa | https://github.com/getlantern/systray/blob/26d5b920200dbc1869c4bfde4571497082f83caa/systray.go#L95-L101 |
149,170 | getlantern/systray | systray.go | SetTitle | func (item *MenuItem) SetTitle(title string) {
item.title = title
item.update()
} | go | func (item *MenuItem) SetTitle(title string) {
item.title = title
item.update()
} | [
"func",
"(",
"item",
"*",
"MenuItem",
")",
"SetTitle",
"(",
"title",
"string",
")",
"{",
"item",
".",
"title",
"=",
"title",
"\n",
"item",
".",
"update",
"(",
")",
"\n",
"}"
] | // SetTitle set the text to display on a menu item | [
"SetTitle",
"set",
"the",
"text",
"to",
"display",
"on",
"a",
"menu",
"item"
] | 26d5b920200dbc1869c4bfde4571497082f83caa | https://github.com/getlantern/systray/blob/26d5b920200dbc1869c4bfde4571497082f83caa/systray.go#L109-L112 |
149,171 | getlantern/systray | systray.go | SetTooltip | func (item *MenuItem) SetTooltip(tooltip string) {
item.tooltip = tooltip
item.update()
} | go | func (item *MenuItem) SetTooltip(tooltip string) {
item.tooltip = tooltip
item.update()
} | [
"func",
"(",
"item",
"*",
"MenuItem",
")",
"SetTooltip",
"(",
"tooltip",
"string",
")",
"{",
"item",
".",
"tooltip",
"=",
"tooltip",
"\n",
"item",
".",
"update",
"(",
")",
"\n",
"}"
] | // SetTooltip set the tooltip to show when mouse hover | [
"SetTooltip",
"set",
"the",
"tooltip",
"to",
"show",
"when",
"mouse",
"hover"
] | 26d5b920200dbc1869c4bfde4571497082f83caa | https://github.com/getlantern/systray/blob/26d5b920200dbc1869c4bfde4571497082f83caa/systray.go#L115-L118 |
149,172 | getlantern/systray | systray.go | update | func (item *MenuItem) update() {
menuItemsLock.Lock()
defer menuItemsLock.Unlock()
menuItems[item.id] = item
addOrUpdateMenuItem(item)
} | go | func (item *MenuItem) update() {
menuItemsLock.Lock()
defer menuItemsLock.Unlock()
menuItems[item.id] = item
addOrUpdateMenuItem(item)
} | [
"func",
"(",
"item",
"*",
"MenuItem",
")",
"update",
"(",
")",
"{",
"menuItemsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"menuItemsLock",
".",
"Unlock",
"(",
")",
"\n",
"menuItems",
"[",
"item",
".",
"id",
"]",
"=",
"item",
"\n",
"addOrUpdateMenuItem",
"(",
"item",
")",
"\n",
"}"
] | // update propogates changes on a menu item to systray | [
"update",
"propogates",
"changes",
"on",
"a",
"menu",
"item",
"to",
"systray"
] | 26d5b920200dbc1869c4bfde4571497082f83caa | https://github.com/getlantern/systray/blob/26d5b920200dbc1869c4bfde4571497082f83caa/systray.go#L165-L170 |
149,173 | go-redsync/redsync | redsync.go | NewMutex | func (r *Redsync) NewMutex(name string, options ...Option) *Mutex {
m := &Mutex{
name: name,
expiry: 8 * time.Second,
tries: 32,
delayFunc: func(tries int) time.Duration { return 500 * time.Millisecond },
genValueFunc: genValue,
factor: 0.01,
quorum: len(r.pools)/2 + 1,
pools: r.pools,
}
for _, o := range options {
o.Apply(m)
}
return m
} | go | func (r *Redsync) NewMutex(name string, options ...Option) *Mutex {
m := &Mutex{
name: name,
expiry: 8 * time.Second,
tries: 32,
delayFunc: func(tries int) time.Duration { return 500 * time.Millisecond },
genValueFunc: genValue,
factor: 0.01,
quorum: len(r.pools)/2 + 1,
pools: r.pools,
}
for _, o := range options {
o.Apply(m)
}
return m
} | [
"func",
"(",
"r",
"*",
"Redsync",
")",
"NewMutex",
"(",
"name",
"string",
",",
"options",
"...",
"Option",
")",
"*",
"Mutex",
"{",
"m",
":=",
"&",
"Mutex",
"{",
"name",
":",
"name",
",",
"expiry",
":",
"8",
"*",
"time",
".",
"Second",
",",
"tries",
":",
"32",
",",
"delayFunc",
":",
"func",
"(",
"tries",
"int",
")",
"time",
".",
"Duration",
"{",
"return",
"500",
"*",
"time",
".",
"Millisecond",
"}",
",",
"genValueFunc",
":",
"genValue",
",",
"factor",
":",
"0.01",
",",
"quorum",
":",
"len",
"(",
"r",
".",
"pools",
")",
"/",
"2",
"+",
"1",
",",
"pools",
":",
"r",
".",
"pools",
",",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"options",
"{",
"o",
".",
"Apply",
"(",
"m",
")",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // NewMutex returns a new distributed mutex with given name. | [
"NewMutex",
"returns",
"a",
"new",
"distributed",
"mutex",
"with",
"given",
"name",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/redsync.go#L18-L33 |
149,174 | go-redsync/redsync | redsync.go | SetExpiry | func SetExpiry(expiry time.Duration) Option {
return OptionFunc(func(m *Mutex) {
m.expiry = expiry
})
} | go | func SetExpiry(expiry time.Duration) Option {
return OptionFunc(func(m *Mutex) {
m.expiry = expiry
})
} | [
"func",
"SetExpiry",
"(",
"expiry",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"OptionFunc",
"(",
"func",
"(",
"m",
"*",
"Mutex",
")",
"{",
"m",
".",
"expiry",
"=",
"expiry",
"\n",
"}",
")",
"\n",
"}"
] | // SetExpiry can be used to set the expiry of a mutex to the given value. | [
"SetExpiry",
"can",
"be",
"used",
"to",
"set",
"the",
"expiry",
"of",
"a",
"mutex",
"to",
"the",
"given",
"value",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/redsync.go#L49-L53 |
149,175 | go-redsync/redsync | redsync.go | SetTries | func SetTries(tries int) Option {
return OptionFunc(func(m *Mutex) {
m.tries = tries
})
} | go | func SetTries(tries int) Option {
return OptionFunc(func(m *Mutex) {
m.tries = tries
})
} | [
"func",
"SetTries",
"(",
"tries",
"int",
")",
"Option",
"{",
"return",
"OptionFunc",
"(",
"func",
"(",
"m",
"*",
"Mutex",
")",
"{",
"m",
".",
"tries",
"=",
"tries",
"\n",
"}",
")",
"\n",
"}"
] | // SetTries can be used to set the number of times lock acquire is attempted. | [
"SetTries",
"can",
"be",
"used",
"to",
"set",
"the",
"number",
"of",
"times",
"lock",
"acquire",
"is",
"attempted",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/redsync.go#L56-L60 |
149,176 | go-redsync/redsync | redsync.go | SetRetryDelay | func SetRetryDelay(delay time.Duration) Option {
return OptionFunc(func(m *Mutex) {
m.delayFunc = func(tries int) time.Duration {
return delay
}
})
} | go | func SetRetryDelay(delay time.Duration) Option {
return OptionFunc(func(m *Mutex) {
m.delayFunc = func(tries int) time.Duration {
return delay
}
})
} | [
"func",
"SetRetryDelay",
"(",
"delay",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"OptionFunc",
"(",
"func",
"(",
"m",
"*",
"Mutex",
")",
"{",
"m",
".",
"delayFunc",
"=",
"func",
"(",
"tries",
"int",
")",
"time",
".",
"Duration",
"{",
"return",
"delay",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // SetRetryDelay can be used to set the amount of time to wait between retries. | [
"SetRetryDelay",
"can",
"be",
"used",
"to",
"set",
"the",
"amount",
"of",
"time",
"to",
"wait",
"between",
"retries",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/redsync.go#L63-L69 |
149,177 | go-redsync/redsync | redsync.go | SetRetryDelayFunc | func SetRetryDelayFunc(delayFunc DelayFunc) Option {
return OptionFunc(func(m *Mutex) {
m.delayFunc = delayFunc
})
} | go | func SetRetryDelayFunc(delayFunc DelayFunc) Option {
return OptionFunc(func(m *Mutex) {
m.delayFunc = delayFunc
})
} | [
"func",
"SetRetryDelayFunc",
"(",
"delayFunc",
"DelayFunc",
")",
"Option",
"{",
"return",
"OptionFunc",
"(",
"func",
"(",
"m",
"*",
"Mutex",
")",
"{",
"m",
".",
"delayFunc",
"=",
"delayFunc",
"\n",
"}",
")",
"\n",
"}"
] | // SetRetryDelayFunc can be used to override default delay behavior. | [
"SetRetryDelayFunc",
"can",
"be",
"used",
"to",
"override",
"default",
"delay",
"behavior",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/redsync.go#L72-L76 |
149,178 | go-redsync/redsync | redsync.go | SetDriftFactor | func SetDriftFactor(factor float64) Option {
return OptionFunc(func(m *Mutex) {
m.factor = factor
})
} | go | func SetDriftFactor(factor float64) Option {
return OptionFunc(func(m *Mutex) {
m.factor = factor
})
} | [
"func",
"SetDriftFactor",
"(",
"factor",
"float64",
")",
"Option",
"{",
"return",
"OptionFunc",
"(",
"func",
"(",
"m",
"*",
"Mutex",
")",
"{",
"m",
".",
"factor",
"=",
"factor",
"\n",
"}",
")",
"\n",
"}"
] | // SetDriftFactor can be used to set the clock drift factor. | [
"SetDriftFactor",
"can",
"be",
"used",
"to",
"set",
"the",
"clock",
"drift",
"factor",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/redsync.go#L79-L83 |
149,179 | go-redsync/redsync | redsync.go | SetGenValueFunc | func SetGenValueFunc(genValueFunc func() (string, error)) Option {
return OptionFunc(func(m *Mutex) {
m.genValueFunc = genValueFunc
})
} | go | func SetGenValueFunc(genValueFunc func() (string, error)) Option {
return OptionFunc(func(m *Mutex) {
m.genValueFunc = genValueFunc
})
} | [
"func",
"SetGenValueFunc",
"(",
"genValueFunc",
"func",
"(",
")",
"(",
"string",
",",
"error",
")",
")",
"Option",
"{",
"return",
"OptionFunc",
"(",
"func",
"(",
"m",
"*",
"Mutex",
")",
"{",
"m",
".",
"genValueFunc",
"=",
"genValueFunc",
"\n",
"}",
")",
"\n",
"}"
] | // SetGenValueFunc can be used to set the custom value generator. | [
"SetGenValueFunc",
"can",
"be",
"used",
"to",
"set",
"the",
"custom",
"value",
"generator",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/redsync.go#L86-L90 |
149,180 | go-redsync/redsync | mutex.go | Unlock | func (m *Mutex) Unlock() bool {
n := m.actOnPoolsAsync(func(pool Pool) bool {
return m.release(pool, m.value)
})
return n >= m.quorum
} | go | func (m *Mutex) Unlock() bool {
n := m.actOnPoolsAsync(func(pool Pool) bool {
return m.release(pool, m.value)
})
return n >= m.quorum
} | [
"func",
"(",
"m",
"*",
"Mutex",
")",
"Unlock",
"(",
")",
"bool",
"{",
"n",
":=",
"m",
".",
"actOnPoolsAsync",
"(",
"func",
"(",
"pool",
"Pool",
")",
"bool",
"{",
"return",
"m",
".",
"release",
"(",
"pool",
",",
"m",
".",
"value",
")",
"\n",
"}",
")",
"\n",
"return",
"n",
">=",
"m",
".",
"quorum",
"\n",
"}"
] | // Unlock unlocks m and returns the status of unlock. | [
"Unlock",
"unlocks",
"m",
"and",
"returns",
"the",
"status",
"of",
"unlock",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/mutex.go#L66-L71 |
149,181 | go-redsync/redsync | mutex.go | Extend | func (m *Mutex) Extend() bool {
n := m.actOnPoolsAsync(func(pool Pool) bool {
return m.touch(pool, m.value, int(m.expiry/time.Millisecond))
})
return n >= m.quorum
} | go | func (m *Mutex) Extend() bool {
n := m.actOnPoolsAsync(func(pool Pool) bool {
return m.touch(pool, m.value, int(m.expiry/time.Millisecond))
})
return n >= m.quorum
} | [
"func",
"(",
"m",
"*",
"Mutex",
")",
"Extend",
"(",
")",
"bool",
"{",
"n",
":=",
"m",
".",
"actOnPoolsAsync",
"(",
"func",
"(",
"pool",
"Pool",
")",
"bool",
"{",
"return",
"m",
".",
"touch",
"(",
"pool",
",",
"m",
".",
"value",
",",
"int",
"(",
"m",
".",
"expiry",
"/",
"time",
".",
"Millisecond",
")",
")",
"\n",
"}",
")",
"\n",
"return",
"n",
">=",
"m",
".",
"quorum",
"\n",
"}"
] | // Extend resets the mutex's expiry and returns the status of expiry extension. | [
"Extend",
"resets",
"the",
"mutex",
"s",
"expiry",
"and",
"returns",
"the",
"status",
"of",
"expiry",
"extension",
"."
] | aba0a125bc554b826ae0f194e00af531c967bcd6 | https://github.com/go-redsync/redsync/blob/aba0a125bc554b826ae0f194e00af531c967bcd6/mutex.go#L74-L79 |
149,182 | cesanta/docker_auth | auth_server/authn/tokendb.go | NewTokenDB | func NewTokenDB(file string) (TokenDB, error) {
db, err := leveldb.OpenFile(file, nil)
return &TokenDBImpl{
DB: db,
}, err
} | go | func NewTokenDB(file string) (TokenDB, error) {
db, err := leveldb.OpenFile(file, nil)
return &TokenDBImpl{
DB: db,
}, err
} | [
"func",
"NewTokenDB",
"(",
"file",
"string",
")",
"(",
"TokenDB",
",",
"error",
")",
"{",
"db",
",",
"err",
":=",
"leveldb",
".",
"OpenFile",
"(",
"file",
",",
"nil",
")",
"\n",
"return",
"&",
"TokenDBImpl",
"{",
"DB",
":",
"db",
",",
"}",
",",
"err",
"\n",
"}"
] | // NewTokenDB returns a new TokenDB structure | [
"NewTokenDB",
"returns",
"a",
"new",
"TokenDB",
"structure"
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authn/tokendb.go#L77-L82 |
149,183 | cesanta/docker_auth | auth_server/authz/acl_mongo.go | NewACLMongoAuthorizer | func NewACLMongoAuthorizer(c *ACLMongoConfig) (Authorizer, error) {
// Attempt to create new MongoDB session.
session, err := mgo_session.New(c.MongoConfig)
if err != nil {
return nil, err
}
authorizer := &aclMongoAuthorizer{
config: c,
session: session,
updateTicker: time.NewTicker(c.CacheTTL),
}
// Initially fetch the ACL from MongoDB
if err := authorizer.updateACLCache(); err != nil {
return nil, err
}
go authorizer.continuouslyUpdateACLCache()
return authorizer, nil
} | go | func NewACLMongoAuthorizer(c *ACLMongoConfig) (Authorizer, error) {
// Attempt to create new MongoDB session.
session, err := mgo_session.New(c.MongoConfig)
if err != nil {
return nil, err
}
authorizer := &aclMongoAuthorizer{
config: c,
session: session,
updateTicker: time.NewTicker(c.CacheTTL),
}
// Initially fetch the ACL from MongoDB
if err := authorizer.updateACLCache(); err != nil {
return nil, err
}
go authorizer.continuouslyUpdateACLCache()
return authorizer, nil
} | [
"func",
"NewACLMongoAuthorizer",
"(",
"c",
"*",
"ACLMongoConfig",
")",
"(",
"Authorizer",
",",
"error",
")",
"{",
"// Attempt to create new MongoDB session.",
"session",
",",
"err",
":=",
"mgo_session",
".",
"New",
"(",
"c",
".",
"MongoConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"authorizer",
":=",
"&",
"aclMongoAuthorizer",
"{",
"config",
":",
"c",
",",
"session",
":",
"session",
",",
"updateTicker",
":",
"time",
".",
"NewTicker",
"(",
"c",
".",
"CacheTTL",
")",
",",
"}",
"\n\n",
"// Initially fetch the ACL from MongoDB",
"if",
"err",
":=",
"authorizer",
".",
"updateACLCache",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"go",
"authorizer",
".",
"continuouslyUpdateACLCache",
"(",
")",
"\n\n",
"return",
"authorizer",
",",
"nil",
"\n",
"}"
] | // NewACLMongoAuthorizer creates a new ACL MongoDB authorizer | [
"NewACLMongoAuthorizer",
"creates",
"a",
"new",
"ACL",
"MongoDB",
"authorizer"
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authz/acl_mongo.go#L40-L61 |
149,184 | cesanta/docker_auth | auth_server/authz/acl_mongo.go | continuouslyUpdateACLCache | func (ma *aclMongoAuthorizer) continuouslyUpdateACLCache() {
var tick time.Time
for ; true; tick = <-ma.updateTicker.C {
aclAge := time.Now().Sub(ma.lastCacheUpdate)
glog.V(2).Infof("Updating ACL at %s (ACL age: %s. CacheTTL: %s)", tick, aclAge, ma.config.CacheTTL)
for true {
err := ma.updateACLCache()
if err == nil {
break
} else if err == io.EOF {
glog.Warningf("EOF error received from Mongo. Retrying connection")
time.Sleep(time.Second)
continue
} else {
glog.Errorf("Failed to update ACL. ERROR: %s", err)
glog.Warningf("Using stale ACL (Age: %s, TTL: %s)", aclAge, ma.config.CacheTTL)
break
}
}
}
} | go | func (ma *aclMongoAuthorizer) continuouslyUpdateACLCache() {
var tick time.Time
for ; true; tick = <-ma.updateTicker.C {
aclAge := time.Now().Sub(ma.lastCacheUpdate)
glog.V(2).Infof("Updating ACL at %s (ACL age: %s. CacheTTL: %s)", tick, aclAge, ma.config.CacheTTL)
for true {
err := ma.updateACLCache()
if err == nil {
break
} else if err == io.EOF {
glog.Warningf("EOF error received from Mongo. Retrying connection")
time.Sleep(time.Second)
continue
} else {
glog.Errorf("Failed to update ACL. ERROR: %s", err)
glog.Warningf("Using stale ACL (Age: %s, TTL: %s)", aclAge, ma.config.CacheTTL)
break
}
}
}
} | [
"func",
"(",
"ma",
"*",
"aclMongoAuthorizer",
")",
"continuouslyUpdateACLCache",
"(",
")",
"{",
"var",
"tick",
"time",
".",
"Time",
"\n",
"for",
";",
"true",
";",
"tick",
"=",
"<-",
"ma",
".",
"updateTicker",
".",
"C",
"{",
"aclAge",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"ma",
".",
"lastCacheUpdate",
")",
"\n",
"glog",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"tick",
",",
"aclAge",
",",
"ma",
".",
"config",
".",
"CacheTTL",
")",
"\n\n",
"for",
"true",
"{",
"err",
":=",
"ma",
".",
"updateACLCache",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"else",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"glog",
".",
"Warningf",
"(",
"\"",
"\"",
")",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"continue",
"\n",
"}",
"else",
"{",
"glog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"glog",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"aclAge",
",",
"ma",
".",
"config",
".",
"CacheTTL",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // continuouslyUpdateACLCache checks if the ACL cache has expired and depending
// on the the result it updates the cache with the ACL from the MongoDB server.
// The ACL will be stored inside the static authorizer instance which we use
// to minimize duplication of code and maximize reuse of existing code. | [
"continuouslyUpdateACLCache",
"checks",
"if",
"the",
"ACL",
"cache",
"has",
"expired",
"and",
"depending",
"on",
"the",
"the",
"result",
"it",
"updates",
"the",
"cache",
"with",
"the",
"ACL",
"from",
"the",
"MongoDB",
"server",
".",
"The",
"ACL",
"will",
"be",
"stored",
"inside",
"the",
"static",
"authorizer",
"instance",
"which",
"we",
"use",
"to",
"minimize",
"duplication",
"of",
"code",
"and",
"maximize",
"reuse",
"of",
"existing",
"code",
"."
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authz/acl_mongo.go#L112-L133 |
149,185 | cesanta/docker_auth | auth_server/mgo_session/mgo_session.go | Validate | func (c *Config) Validate(configKey string) error {
if len(c.DialInfo.Addrs) == 0 {
return fmt.Errorf("At least one element in %s.dial_info.addrs is required", configKey)
}
if c.DialInfo.Timeout == 0 {
c.DialInfo.Timeout = 10 * time.Second
}
if c.DialInfo.Database == "" {
return fmt.Errorf("%s.dial_info.database is required", configKey)
}
return nil
} | go | func (c *Config) Validate(configKey string) error {
if len(c.DialInfo.Addrs) == 0 {
return fmt.Errorf("At least one element in %s.dial_info.addrs is required", configKey)
}
if c.DialInfo.Timeout == 0 {
c.DialInfo.Timeout = 10 * time.Second
}
if c.DialInfo.Database == "" {
return fmt.Errorf("%s.dial_info.database is required", configKey)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Validate",
"(",
"configKey",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"c",
".",
"DialInfo",
".",
"Addrs",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"configKey",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"DialInfo",
".",
"Timeout",
"==",
"0",
"{",
"c",
".",
"DialInfo",
".",
"Timeout",
"=",
"10",
"*",
"time",
".",
"Second",
"\n",
"}",
"\n",
"if",
"c",
".",
"DialInfo",
".",
"Database",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"configKey",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate ensures the most common fields inside the mgo.DialInfo portion of
// a Config are set correctly as well as other fields inside the
// Config itself. | [
"Validate",
"ensures",
"the",
"most",
"common",
"fields",
"inside",
"the",
"mgo",
".",
"DialInfo",
"portion",
"of",
"a",
"Config",
"are",
"set",
"correctly",
"as",
"well",
"as",
"other",
"fields",
"inside",
"the",
"Config",
"itself",
"."
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/mgo_session/mgo_session.go#L41-L52 |
149,186 | cesanta/docker_auth | auth_server/authz/acl.go | NewACLAuthorizer | func NewACLAuthorizer(acl ACL) (Authorizer, error) {
if err := ValidateACL(acl); err != nil {
return nil, err
}
glog.V(1).Infof("Created ACL Authorizer with %d entries", len(acl))
return &aclAuthorizer{acl: acl}, nil
} | go | func NewACLAuthorizer(acl ACL) (Authorizer, error) {
if err := ValidateACL(acl); err != nil {
return nil, err
}
glog.V(1).Infof("Created ACL Authorizer with %d entries", len(acl))
return &aclAuthorizer{acl: acl}, nil
} | [
"func",
"NewACLAuthorizer",
"(",
"acl",
"ACL",
")",
"(",
"Authorizer",
",",
"error",
")",
"{",
"if",
"err",
":=",
"ValidateACL",
"(",
"acl",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"glog",
".",
"V",
"(",
"1",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"len",
"(",
"acl",
")",
")",
"\n",
"return",
"&",
"aclAuthorizer",
"{",
"acl",
":",
"acl",
"}",
",",
"nil",
"\n",
"}"
] | // NewACLAuthorizer Creates a new static authorizer with ACL that have been read from the config file | [
"NewACLAuthorizer",
"Creates",
"a",
"new",
"static",
"authorizer",
"with",
"ACL",
"that",
"have",
"been",
"read",
"from",
"the",
"config",
"file"
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authz/acl.go#L104-L110 |
149,187 | cesanta/docker_auth | auth_server/authn/ldap_auth.go | ldapSearch | func (la *LDAPAuth) ldapSearch(l *ldap.Conn, baseDN *string, filter *string, attrs *[]string) (string, map[string][]string, error) {
if l == nil {
return "", nil, fmt.Errorf("No ldap connection!")
}
glog.V(2).Infof("Searching...basedDN:%s, filter:%s", *baseDN, *filter)
searchRequest := ldap.NewSearchRequest(
*baseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
*filter,
*attrs,
nil)
sr, err := l.Search(searchRequest)
if err != nil {
return "", nil, err
}
if len(sr.Entries) == 0 {
return "", nil, nil // User does not exist
} else if len(sr.Entries) > 1 {
return "", nil, fmt.Errorf("Too many entries returned.")
}
attributes := make(map[string][]string)
var entryDn string
for _, entry := range sr.Entries {
entryDn = entry.DN
if len(*attrs) == 0 {
glog.V(2).Infof("Entry DN = %s", entryDn)
} else {
for _, attr := range *attrs {
values := entry.GetAttributeValues(attr)
glog.V(2).Infof("Entry %s = %s", attr, strings.Join(values, "\n"))
attributes[attr] = values
}
}
}
return entryDn, attributes, nil
} | go | func (la *LDAPAuth) ldapSearch(l *ldap.Conn, baseDN *string, filter *string, attrs *[]string) (string, map[string][]string, error) {
if l == nil {
return "", nil, fmt.Errorf("No ldap connection!")
}
glog.V(2).Infof("Searching...basedDN:%s, filter:%s", *baseDN, *filter)
searchRequest := ldap.NewSearchRequest(
*baseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
*filter,
*attrs,
nil)
sr, err := l.Search(searchRequest)
if err != nil {
return "", nil, err
}
if len(sr.Entries) == 0 {
return "", nil, nil // User does not exist
} else if len(sr.Entries) > 1 {
return "", nil, fmt.Errorf("Too many entries returned.")
}
attributes := make(map[string][]string)
var entryDn string
for _, entry := range sr.Entries {
entryDn = entry.DN
if len(*attrs) == 0 {
glog.V(2).Infof("Entry DN = %s", entryDn)
} else {
for _, attr := range *attrs {
values := entry.GetAttributeValues(attr)
glog.V(2).Infof("Entry %s = %s", attr, strings.Join(values, "\n"))
attributes[attr] = values
}
}
}
return entryDn, attributes, nil
} | [
"func",
"(",
"la",
"*",
"LDAPAuth",
")",
"ldapSearch",
"(",
"l",
"*",
"ldap",
".",
"Conn",
",",
"baseDN",
"*",
"string",
",",
"filter",
"*",
"string",
",",
"attrs",
"*",
"[",
"]",
"string",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"l",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"glog",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"*",
"baseDN",
",",
"*",
"filter",
")",
"\n",
"searchRequest",
":=",
"ldap",
".",
"NewSearchRequest",
"(",
"*",
"baseDN",
",",
"ldap",
".",
"ScopeWholeSubtree",
",",
"ldap",
".",
"NeverDerefAliases",
",",
"0",
",",
"0",
",",
"false",
",",
"*",
"filter",
",",
"*",
"attrs",
",",
"nil",
")",
"\n",
"sr",
",",
"err",
":=",
"l",
".",
"Search",
"(",
"searchRequest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"sr",
".",
"Entries",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
"// User does not exist",
"\n",
"}",
"else",
"if",
"len",
"(",
"sr",
".",
"Entries",
")",
">",
"1",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"attributes",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"\n",
"var",
"entryDn",
"string",
"\n",
"for",
"_",
",",
"entry",
":=",
"range",
"sr",
".",
"Entries",
"{",
"entryDn",
"=",
"entry",
".",
"DN",
"\n",
"if",
"len",
"(",
"*",
"attrs",
")",
"==",
"0",
"{",
"glog",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"entryDn",
")",
"\n",
"}",
"else",
"{",
"for",
"_",
",",
"attr",
":=",
"range",
"*",
"attrs",
"{",
"values",
":=",
"entry",
".",
"GetAttributeValues",
"(",
"attr",
")",
"\n",
"glog",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"attr",
",",
"strings",
".",
"Join",
"(",
"values",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"attributes",
"[",
"attr",
"]",
"=",
"values",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"entryDn",
",",
"attributes",
",",
"nil",
"\n",
"}"
] | //ldap search and return required attributes' value from searched entries
//default return entry's DN value if you leave attrs array empty | [
"ldap",
"search",
"and",
"return",
"required",
"attributes",
"value",
"from",
"searched",
"entries",
"default",
"return",
"entry",
"s",
"DN",
"value",
"if",
"you",
"leave",
"attrs",
"array",
"empty"
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authn/ldap_auth.go#L204-L242 |
149,188 | cesanta/docker_auth | auth_server/authn/github_auth.go | removeSubstringsFromString | func removeSubstringsFromString(sourceStr string, stringsToStrip []string) string {
theNewString := sourceStr
for _, i := range stringsToStrip {
theNewString = strings.Replace(theNewString, i, "", -1)
}
return theNewString
} | go | func removeSubstringsFromString(sourceStr string, stringsToStrip []string) string {
theNewString := sourceStr
for _, i := range stringsToStrip {
theNewString = strings.Replace(theNewString, i, "", -1)
}
return theNewString
} | [
"func",
"removeSubstringsFromString",
"(",
"sourceStr",
"string",
",",
"stringsToStrip",
"[",
"]",
"string",
")",
"string",
"{",
"theNewString",
":=",
"sourceStr",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"stringsToStrip",
"{",
"theNewString",
"=",
"strings",
".",
"Replace",
"(",
"theNewString",
",",
"i",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"return",
"theNewString",
"\n",
"}"
] | // removeSubstringsFromString removes all occurences of stringsToStrip from sourceStr
// | [
"removeSubstringsFromString",
"removes",
"all",
"occurences",
"of",
"stringsToStrip",
"from",
"sourceStr"
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authn/github_auth.go#L123-L129 |
149,189 | cesanta/docker_auth | auth_server/authn/tokendb_gcs.go | GetValue | func (db *gcsTokenDB) GetValue(user string) (*TokenDBValue, error) {
rd, err := db.gcs.Bucket(db.bucket).Object(user).NewReader(context.Background())
if err == storage.ErrObjectNotExist {
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("could not retrieved token for user '%s' due: %v", user, err)
}
defer rd.Close()
var dbv TokenDBValue
if err := json.NewDecoder(rd).Decode(&dbv); err != nil {
glog.Errorf("bad DB value for %q: %v", user, err)
return nil, fmt.Errorf("could not read token for user '%s' due: %v", user, err)
}
return &dbv, nil
} | go | func (db *gcsTokenDB) GetValue(user string) (*TokenDBValue, error) {
rd, err := db.gcs.Bucket(db.bucket).Object(user).NewReader(context.Background())
if err == storage.ErrObjectNotExist {
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("could not retrieved token for user '%s' due: %v", user, err)
}
defer rd.Close()
var dbv TokenDBValue
if err := json.NewDecoder(rd).Decode(&dbv); err != nil {
glog.Errorf("bad DB value for %q: %v", user, err)
return nil, fmt.Errorf("could not read token for user '%s' due: %v", user, err)
}
return &dbv, nil
} | [
"func",
"(",
"db",
"*",
"gcsTokenDB",
")",
"GetValue",
"(",
"user",
"string",
")",
"(",
"*",
"TokenDBValue",
",",
"error",
")",
"{",
"rd",
",",
"err",
":=",
"db",
".",
"gcs",
".",
"Bucket",
"(",
"db",
".",
"bucket",
")",
".",
"Object",
"(",
"user",
")",
".",
"NewReader",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"if",
"err",
"==",
"storage",
".",
"ErrObjectNotExist",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"user",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"rd",
".",
"Close",
"(",
")",
"\n\n",
"var",
"dbv",
"TokenDBValue",
"\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"rd",
")",
".",
"Decode",
"(",
"&",
"dbv",
")",
";",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"user",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"user",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"dbv",
",",
"nil",
"\n",
"}"
] | // GetValue gets token value associated with the provided user. Each user
// in the bucket is having it's own file for tokens and it's recomanded bucket
// to not be shared with other apps | [
"GetValue",
"gets",
"token",
"value",
"associated",
"with",
"the",
"provided",
"user",
".",
"Each",
"user",
"in",
"the",
"bucket",
"is",
"having",
"it",
"s",
"own",
"file",
"for",
"tokens",
"and",
"it",
"s",
"recomanded",
"bucket",
"to",
"not",
"be",
"shared",
"with",
"other",
"apps"
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authn/tokendb_gcs.go#L48-L65 |
149,190 | cesanta/docker_auth | auth_server/authn/tokendb_gcs.go | StoreToken | func (db *gcsTokenDB) StoreToken(user string, v *TokenDBValue, updatePassword bool) (dp string, err error) {
if updatePassword {
dp = uniuri.New()
dph, _ := bcrypt.GenerateFromPassword([]byte(dp), bcrypt.DefaultCost)
v.DockerPassword = string(dph)
}
wr := db.gcs.Bucket(db.bucket).Object(user).NewWriter(context.Background())
if err := json.NewEncoder(wr).Encode(v); err != nil {
glog.Errorf("failed to set token data for %s: %s", user, err)
return "", fmt.Errorf("failed to set token data for %s due: %v", user, err)
}
err = wr.Close()
return
} | go | func (db *gcsTokenDB) StoreToken(user string, v *TokenDBValue, updatePassword bool) (dp string, err error) {
if updatePassword {
dp = uniuri.New()
dph, _ := bcrypt.GenerateFromPassword([]byte(dp), bcrypt.DefaultCost)
v.DockerPassword = string(dph)
}
wr := db.gcs.Bucket(db.bucket).Object(user).NewWriter(context.Background())
if err := json.NewEncoder(wr).Encode(v); err != nil {
glog.Errorf("failed to set token data for %s: %s", user, err)
return "", fmt.Errorf("failed to set token data for %s due: %v", user, err)
}
err = wr.Close()
return
} | [
"func",
"(",
"db",
"*",
"gcsTokenDB",
")",
"StoreToken",
"(",
"user",
"string",
",",
"v",
"*",
"TokenDBValue",
",",
"updatePassword",
"bool",
")",
"(",
"dp",
"string",
",",
"err",
"error",
")",
"{",
"if",
"updatePassword",
"{",
"dp",
"=",
"uniuri",
".",
"New",
"(",
")",
"\n",
"dph",
",",
"_",
":=",
"bcrypt",
".",
"GenerateFromPassword",
"(",
"[",
"]",
"byte",
"(",
"dp",
")",
",",
"bcrypt",
".",
"DefaultCost",
")",
"\n",
"v",
".",
"DockerPassword",
"=",
"string",
"(",
"dph",
")",
"\n",
"}",
"\n\n",
"wr",
":=",
"db",
".",
"gcs",
".",
"Bucket",
"(",
"db",
".",
"bucket",
")",
".",
"Object",
"(",
"user",
")",
".",
"NewWriter",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n\n",
"if",
"err",
":=",
"json",
".",
"NewEncoder",
"(",
"wr",
")",
".",
"Encode",
"(",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"user",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"user",
",",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"wr",
".",
"Close",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // StoreToken stores token in the GCS file in a JSON format. Note that separate file is
// used for each user | [
"StoreToken",
"stores",
"token",
"in",
"the",
"GCS",
"file",
"in",
"a",
"JSON",
"format",
".",
"Note",
"that",
"separate",
"file",
"is",
"used",
"for",
"each",
"user"
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authn/tokendb_gcs.go#L69-L85 |
149,191 | cesanta/docker_auth | auth_server/authn/tokendb_gcs.go | DeleteToken | func (db *gcsTokenDB) DeleteToken(user string) error {
ctx := context.Background()
err := db.gcs.Bucket(db.bucket).Object(user).Delete(ctx)
if err == storage.ErrObjectNotExist {
return nil
}
return err
} | go | func (db *gcsTokenDB) DeleteToken(user string) error {
ctx := context.Background()
err := db.gcs.Bucket(db.bucket).Object(user).Delete(ctx)
if err == storage.ErrObjectNotExist {
return nil
}
return err
} | [
"func",
"(",
"db",
"*",
"gcsTokenDB",
")",
"DeleteToken",
"(",
"user",
"string",
")",
"error",
"{",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"err",
":=",
"db",
".",
"gcs",
".",
"Bucket",
"(",
"db",
".",
"bucket",
")",
".",
"Object",
"(",
"user",
")",
".",
"Delete",
"(",
"ctx",
")",
"\n",
"if",
"err",
"==",
"storage",
".",
"ErrObjectNotExist",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // DeleteToken deletes the GCS file that is associated with the provided user. | [
"DeleteToken",
"deletes",
"the",
"GCS",
"file",
"that",
"is",
"associated",
"with",
"the",
"provided",
"user",
"."
] | b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf | https://github.com/cesanta/docker_auth/blob/b89dec9a4f0098fb0f71d9b94e44d1710c1fe5cf/auth_server/authn/tokendb_gcs.go#L109-L116 |
149,192 | square/certstrap | depot/depot.go | NewFileDepot | func NewFileDepot(dir string) (*FileDepot, error) {
dirpath, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
return &FileDepot{dirpath}, nil
} | go | func NewFileDepot(dir string) (*FileDepot, error) {
dirpath, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
return &FileDepot{dirpath}, nil
} | [
"func",
"NewFileDepot",
"(",
"dir",
"string",
")",
"(",
"*",
"FileDepot",
",",
"error",
")",
"{",
"dirpath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"FileDepot",
"{",
"dirpath",
"}",
",",
"nil",
"\n",
"}"
] | // NewFileDepot creates a new Depot at the specified path | [
"NewFileDepot",
"creates",
"a",
"new",
"Depot",
"at",
"the",
"specified",
"path"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/depot.go#L60-L67 |
149,193 | square/certstrap | depot/depot.go | Put | func (d *FileDepot) Put(tag *Tag, data []byte) error {
if data == nil {
return errors.New("data is nil")
}
if err := os.MkdirAll(d.dirPath, 0755); err != nil {
return err
}
name := d.path(tag.name)
perm := tag.perm
file, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
if err != nil {
return err
}
if _, err := file.Write(data); err != nil {
file.Close()
os.Remove(name)
return err
}
file.Close()
return nil
} | go | func (d *FileDepot) Put(tag *Tag, data []byte) error {
if data == nil {
return errors.New("data is nil")
}
if err := os.MkdirAll(d.dirPath, 0755); err != nil {
return err
}
name := d.path(tag.name)
perm := tag.perm
file, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
if err != nil {
return err
}
if _, err := file.Write(data); err != nil {
file.Close()
os.Remove(name)
return err
}
file.Close()
return nil
} | [
"func",
"(",
"d",
"*",
"FileDepot",
")",
"Put",
"(",
"tag",
"*",
"Tag",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"data",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"d",
".",
"dirPath",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"name",
":=",
"d",
".",
"path",
"(",
"tag",
".",
"name",
")",
"\n",
"perm",
":=",
"tag",
".",
"perm",
"\n\n",
"file",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"name",
",",
"os",
".",
"O_WRONLY",
"|",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_EXCL",
",",
"perm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"file",
".",
"Write",
"(",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"file",
".",
"Close",
"(",
")",
"\n",
"os",
".",
"Remove",
"(",
"name",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"file",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Put inserts the data into the file specified by the tag | [
"Put",
"inserts",
"the",
"data",
"into",
"the",
"file",
"specified",
"by",
"the",
"tag"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/depot.go#L74-L99 |
149,194 | square/certstrap | depot/depot.go | Check | func (d *FileDepot) Check(tag *Tag) bool {
name := d.path(tag.name)
if fi, err := os.Stat(name); err == nil && ^fi.Mode()&tag.perm == 0 {
return true
}
return false
} | go | func (d *FileDepot) Check(tag *Tag) bool {
name := d.path(tag.name)
if fi, err := os.Stat(name); err == nil && ^fi.Mode()&tag.perm == 0 {
return true
}
return false
} | [
"func",
"(",
"d",
"*",
"FileDepot",
")",
"Check",
"(",
"tag",
"*",
"Tag",
")",
"bool",
"{",
"name",
":=",
"d",
".",
"path",
"(",
"tag",
".",
"name",
")",
"\n",
"if",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"name",
")",
";",
"err",
"==",
"nil",
"&&",
"^",
"fi",
".",
"Mode",
"(",
")",
"&",
"tag",
".",
"perm",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Check returns whether the file at the tag location exists and has the correct permissions | [
"Check",
"returns",
"whether",
"the",
"file",
"at",
"the",
"tag",
"location",
"exists",
"and",
"has",
"the",
"correct",
"permissions"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/depot.go#L102-L108 |
149,195 | square/certstrap | depot/depot.go | Get | func (d *FileDepot) Get(tag *Tag) ([]byte, error) {
if err := d.check(tag); err != nil {
return nil, err
}
return ioutil.ReadFile(d.path(tag.name))
} | go | func (d *FileDepot) Get(tag *Tag) ([]byte, error) {
if err := d.check(tag); err != nil {
return nil, err
}
return ioutil.ReadFile(d.path(tag.name))
} | [
"func",
"(",
"d",
"*",
"FileDepot",
")",
"Get",
"(",
"tag",
"*",
"Tag",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"err",
":=",
"d",
".",
"check",
"(",
"tag",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"ReadFile",
"(",
"d",
".",
"path",
"(",
"tag",
".",
"name",
")",
")",
"\n",
"}"
] | // Get reads the file specified by the tag | [
"Get",
"reads",
"the",
"file",
"specified",
"by",
"the",
"tag"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/depot.go#L123-L128 |
149,196 | square/certstrap | depot/depot.go | Delete | func (d *FileDepot) Delete(tag *Tag) error {
return os.Remove(d.path(tag.name))
} | go | func (d *FileDepot) Delete(tag *Tag) error {
return os.Remove(d.path(tag.name))
} | [
"func",
"(",
"d",
"*",
"FileDepot",
")",
"Delete",
"(",
"tag",
"*",
"Tag",
")",
"error",
"{",
"return",
"os",
".",
"Remove",
"(",
"d",
".",
"path",
"(",
"tag",
".",
"name",
")",
")",
"\n",
"}"
] | // Delete removes the file specified by the tag | [
"Delete",
"removes",
"the",
"file",
"specified",
"by",
"the",
"tag"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/depot.go#L131-L133 |
149,197 | square/certstrap | depot/depot.go | List | func (d *FileDepot) List() []*Tag {
var tags = make([]*Tag, 0)
filepath.Walk(d.dirPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if info.IsDir() {
return nil
}
rel, err := filepath.Rel(d.dirPath, path)
if err != nil {
return nil
}
if rel != info.Name() {
return nil
}
tags = append(tags, &Tag{info.Name(), info.Mode()})
return nil
})
return tags
} | go | func (d *FileDepot) List() []*Tag {
var tags = make([]*Tag, 0)
filepath.Walk(d.dirPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if info.IsDir() {
return nil
}
rel, err := filepath.Rel(d.dirPath, path)
if err != nil {
return nil
}
if rel != info.Name() {
return nil
}
tags = append(tags, &Tag{info.Name(), info.Mode()})
return nil
})
return tags
} | [
"func",
"(",
"d",
"*",
"FileDepot",
")",
"List",
"(",
")",
"[",
"]",
"*",
"Tag",
"{",
"var",
"tags",
"=",
"make",
"(",
"[",
"]",
"*",
"Tag",
",",
"0",
")",
"\n\n",
"filepath",
".",
"Walk",
"(",
"d",
".",
"dirPath",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"info",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"rel",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"d",
".",
"dirPath",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"rel",
"!=",
"info",
".",
"Name",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"tags",
"=",
"append",
"(",
"tags",
",",
"&",
"Tag",
"{",
"info",
".",
"Name",
"(",
")",
",",
"info",
".",
"Mode",
"(",
")",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"tags",
"\n",
"}"
] | // List returns all tags in the specified depot | [
"List",
"returns",
"all",
"tags",
"in",
"the",
"specified",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/depot.go#L136-L158 |
149,198 | square/certstrap | depot/depot.go | GetFile | func (d *FileDepot) GetFile(tag *Tag) (*File, error) {
if err := d.check(tag); err != nil {
return nil, err
}
fi, err := os.Stat(d.path(tag.name))
if err != nil {
return nil, err
}
b, err := ioutil.ReadFile(d.path(tag.name))
return &File{fi, b}, err
} | go | func (d *FileDepot) GetFile(tag *Tag) (*File, error) {
if err := d.check(tag); err != nil {
return nil, err
}
fi, err := os.Stat(d.path(tag.name))
if err != nil {
return nil, err
}
b, err := ioutil.ReadFile(d.path(tag.name))
return &File{fi, b}, err
} | [
"func",
"(",
"d",
"*",
"FileDepot",
")",
"GetFile",
"(",
"tag",
"*",
"Tag",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"if",
"err",
":=",
"d",
".",
"check",
"(",
"tag",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"d",
".",
"path",
"(",
"tag",
".",
"name",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"d",
".",
"path",
"(",
"tag",
".",
"name",
")",
")",
"\n",
"return",
"&",
"File",
"{",
"fi",
",",
"b",
"}",
",",
"err",
"\n",
"}"
] | // GetFile returns the File at the specified tag in the given depot | [
"GetFile",
"returns",
"the",
"File",
"at",
"the",
"specified",
"tag",
"in",
"the",
"given",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/depot.go#L167-L177 |
149,199 | square/certstrap | cmd/revoke.go | NewRevokeCommand | func NewRevokeCommand() cli.Command {
return cli.Command{
Name: "revoke",
Usage: "Revoke certificate",
Description: "Add certificate to the CA's CRL.",
Flags: []cli.Flag{
cli.StringFlag{
Name: "CN",
Usage: "Common Name (CN) of certificate to revoke",
},
cli.StringFlag{
Name: "CA",
Usage: "Name of CA under which certificate was issued",
},
},
Action: new(revokeCommand).run,
}
} | go | func NewRevokeCommand() cli.Command {
return cli.Command{
Name: "revoke",
Usage: "Revoke certificate",
Description: "Add certificate to the CA's CRL.",
Flags: []cli.Flag{
cli.StringFlag{
Name: "CN",
Usage: "Common Name (CN) of certificate to revoke",
},
cli.StringFlag{
Name: "CA",
Usage: "Name of CA under which certificate was issued",
},
},
Action: new(revokeCommand).run,
}
} | [
"func",
"NewRevokeCommand",
"(",
")",
"cli",
".",
"Command",
"{",
"return",
"cli",
".",
"Command",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Description",
":",
"\"",
"\"",
",",
"Flags",
":",
"[",
"]",
"cli",
".",
"Flag",
"{",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"Action",
":",
"new",
"(",
"revokeCommand",
")",
".",
"run",
",",
"}",
"\n",
"}"
] | // NewRevokeCommand revokes the given certificate by adding it to the CA's CRL. | [
"NewRevokeCommand",
"revokes",
"the",
"given",
"certificate",
"by",
"adding",
"it",
"to",
"the",
"CA",
"s",
"CRL",
"."
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/cmd/revoke.go#L23-L40 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.