repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
pressly/sup
ssh.go
Wait
func (c *SSHClient) Wait() error { if !c.running { return fmt.Errorf("Trying to wait on stopped session") } err := c.sess.Wait() c.sess.Close() c.running = false c.sessOpened = false return err }
go
func (c *SSHClient) Wait() error { if !c.running { return fmt.Errorf("Trying to wait on stopped session") } err := c.sess.Wait() c.sess.Close() c.running = false c.sessOpened = false return err }
[ "func", "(", "c", "*", "SSHClient", ")", "Wait", "(", ")", "error", "{", "if", "!", "c", ".", "running", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "err", ":=", "c", ".", "sess", ".", "Wait", "(", ")", "\n",...
// Wait waits until the remote command finishes and exits. // It closes the SSH session.
[ "Wait", "waits", "until", "the", "remote", "command", "finishes", "and", "exits", ".", "It", "closes", "the", "SSH", "session", "." ]
be6dff41589b713547415b72660885dd7a045f8f
https://github.com/pressly/sup/blob/be6dff41589b713547415b72660885dd7a045f8f/ssh.go#L208-L219
train
pressly/sup
ssh.go
DialThrough
func (sc *SSHClient) DialThrough(net, addr string, config *ssh.ClientConfig) (*ssh.Client, error) { conn, err := sc.conn.Dial(net, addr) if err != nil { return nil, err } c, chans, reqs, err := ssh.NewClientConn(conn, addr, config) if err != nil { return nil, err } return ssh.NewClient(c, chans, reqs), nil }
go
func (sc *SSHClient) DialThrough(net, addr string, config *ssh.ClientConfig) (*ssh.Client, error) { conn, err := sc.conn.Dial(net, addr) if err != nil { return nil, err } c, chans, reqs, err := ssh.NewClientConn(conn, addr, config) if err != nil { return nil, err } return ssh.NewClient(c, chans, reqs), nil }
[ "func", "(", "sc", "*", "SSHClient", ")", "DialThrough", "(", "net", ",", "addr", "string", ",", "config", "*", "ssh", ".", "ClientConfig", ")", "(", "*", "ssh", ".", "Client", ",", "error", ")", "{", "conn", ",", "err", ":=", "sc", ".", "conn", ...
// DialThrough will create a new connection from the ssh server sc is connected to. DialThrough is an SSHDialer.
[ "DialThrough", "will", "create", "a", "new", "connection", "from", "the", "ssh", "server", "sc", "is", "connected", "to", ".", "DialThrough", "is", "an", "SSHDialer", "." ]
be6dff41589b713547415b72660885dd7a045f8f
https://github.com/pressly/sup/blob/be6dff41589b713547415b72660885dd7a045f8f/ssh.go#L222-L233
train
pressly/sup
ssh.go
Close
func (c *SSHClient) Close() error { if c.sessOpened { c.sess.Close() c.sessOpened = false } if !c.connOpened { return fmt.Errorf("Trying to close the already closed connection") } err := c.conn.Close() c.connOpened = false c.running = false return err }
go
func (c *SSHClient) Close() error { if c.sessOpened { c.sess.Close() c.sessOpened = false } if !c.connOpened { return fmt.Errorf("Trying to close the already closed connection") } err := c.conn.Close() c.connOpened = false c.running = false return err }
[ "func", "(", "c", "*", "SSHClient", ")", "Close", "(", ")", "error", "{", "if", "c", ".", "sessOpened", "{", "c", ".", "sess", ".", "Close", "(", ")", "\n", "c", ".", "sessOpened", "=", "false", "\n", "}", "\n", "if", "!", "c", ".", "connOpened...
// Close closes the underlying SSH connection and session.
[ "Close", "closes", "the", "underlying", "SSH", "connection", "and", "session", "." ]
be6dff41589b713547415b72660885dd7a045f8f
https://github.com/pressly/sup/blob/be6dff41589b713547415b72660885dd7a045f8f/ssh.go#L236-L250
train
pressly/sup
supfile.go
Set
func (e *EnvList) Set(key, value string) { for i, v := range *e { if v.Key == key { (*e)[i].Value = value return } } *e = append(*e, &EnvVar{ Key: key, Value: value, }) }
go
func (e *EnvList) Set(key, value string) { for i, v := range *e { if v.Key == key { (*e)[i].Value = value return } } *e = append(*e, &EnvVar{ Key: key, Value: value, }) }
[ "func", "(", "e", "*", "EnvList", ")", "Set", "(", "key", ",", "value", "string", ")", "{", "for", "i", ",", "v", ":=", "range", "*", "e", "{", "if", "v", ".", "Key", "==", "key", "{", "(", "*", "e", ")", "[", "i", "]", ".", "Value", "=",...
// Set key to be equal value in this list.
[ "Set", "key", "to", "be", "equal", "value", "in", "this", "list", "." ]
be6dff41589b713547415b72660885dd7a045f8f
https://github.com/pressly/sup/blob/be6dff41589b713547415b72660885dd7a045f8f/supfile.go#L199-L211
train
pressly/sup
supfile.go
NewSupfile
func NewSupfile(data []byte) (*Supfile, error) { var conf Supfile if err := yaml.Unmarshal(data, &conf); err != nil { return nil, err } // API backward compatibility. Will be deprecated in v1.0. switch conf.Version { case "": conf.Version = "0.1" fallthrough case "0.1": for _, cmd := range conf.Commands.cmds { if cmd.RunOnce { return nil, ErrMustUpdate{"command.run_once is not supported in Supfile v" + conf.Version} } } fallthrough case "0.2": for _, cmd := range conf.Commands.cmds { if cmd.Once { return nil, ErrMustUpdate{"command.once is not supported in Supfile v" + conf.Version} } if cmd.Local != "" { return nil, ErrMustUpdate{"command.local is not supported in Supfile v" + conf.Version} } if cmd.Serial != 0 { return nil, ErrMustUpdate{"command.serial is not supported in Supfile v" + conf.Version} } } for _, network := range conf.Networks.nets { if network.Inventory != "" { return nil, ErrMustUpdate{"network.inventory is not supported in Supfile v" + conf.Version} } } fallthrough case "0.3": var warning string for key, cmd := range conf.Commands.cmds { if cmd.RunOnce { warning = "Warning: command.run_once was deprecated by command.once in Supfile v" + conf.Version + "\n" cmd.Once = true conf.Commands.cmds[key] = cmd } } if warning != "" { fmt.Fprintf(os.Stderr, warning) } fallthrough case "0.4", "0.5": default: return nil, ErrUnsupportedSupfileVersion{"unsupported Supfile version " + conf.Version} } return &conf, nil }
go
func NewSupfile(data []byte) (*Supfile, error) { var conf Supfile if err := yaml.Unmarshal(data, &conf); err != nil { return nil, err } // API backward compatibility. Will be deprecated in v1.0. switch conf.Version { case "": conf.Version = "0.1" fallthrough case "0.1": for _, cmd := range conf.Commands.cmds { if cmd.RunOnce { return nil, ErrMustUpdate{"command.run_once is not supported in Supfile v" + conf.Version} } } fallthrough case "0.2": for _, cmd := range conf.Commands.cmds { if cmd.Once { return nil, ErrMustUpdate{"command.once is not supported in Supfile v" + conf.Version} } if cmd.Local != "" { return nil, ErrMustUpdate{"command.local is not supported in Supfile v" + conf.Version} } if cmd.Serial != 0 { return nil, ErrMustUpdate{"command.serial is not supported in Supfile v" + conf.Version} } } for _, network := range conf.Networks.nets { if network.Inventory != "" { return nil, ErrMustUpdate{"network.inventory is not supported in Supfile v" + conf.Version} } } fallthrough case "0.3": var warning string for key, cmd := range conf.Commands.cmds { if cmd.RunOnce { warning = "Warning: command.run_once was deprecated by command.once in Supfile v" + conf.Version + "\n" cmd.Once = true conf.Commands.cmds[key] = cmd } } if warning != "" { fmt.Fprintf(os.Stderr, warning) } fallthrough case "0.4", "0.5": default: return nil, ErrUnsupportedSupfileVersion{"unsupported Supfile version " + conf.Version} } return &conf, nil }
[ "func", "NewSupfile", "(", "data", "[", "]", "byte", ")", "(", "*", "Supfile", ",", "error", ")", "{", "var", "conf", "Supfile", "\n\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "conf", ")", ";", "err", "!=", "nil", "{"...
// NewSupfile parses configuration file and returns Supfile or error.
[ "NewSupfile", "parses", "configuration", "file", "and", "returns", "Supfile", "or", "error", "." ]
be6dff41589b713547415b72660885dd7a045f8f
https://github.com/pressly/sup/blob/be6dff41589b713547415b72660885dd7a045f8f/supfile.go#L266-L328
train
pressly/sup
supfile.go
ParseInventory
func (n Network) ParseInventory() ([]string, error) { if n.Inventory == "" { return nil, nil } cmd := exec.Command("/bin/sh", "-c", n.Inventory) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, n.Env.Slice()...) cmd.Stderr = os.Stderr output, err := cmd.Output() if err != nil { return nil, err } var hosts []string buf := bytes.NewBuffer(output) for { host, err := buf.ReadString('\n') if err != nil { if err == io.EOF { break } return nil, err } host = strings.TrimSpace(host) // skip empty lines and comments if host == "" || host[:1] == "#" { continue } hosts = append(hosts, host) } return hosts, nil }
go
func (n Network) ParseInventory() ([]string, error) { if n.Inventory == "" { return nil, nil } cmd := exec.Command("/bin/sh", "-c", n.Inventory) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, n.Env.Slice()...) cmd.Stderr = os.Stderr output, err := cmd.Output() if err != nil { return nil, err } var hosts []string buf := bytes.NewBuffer(output) for { host, err := buf.ReadString('\n') if err != nil { if err == io.EOF { break } return nil, err } host = strings.TrimSpace(host) // skip empty lines and comments if host == "" || host[:1] == "#" { continue } hosts = append(hosts, host) } return hosts, nil }
[ "func", "(", "n", "Network", ")", "ParseInventory", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "n", ".", "Inventory", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "cmd", ":=", "exec", ".", "Command"...
// ParseInventory runs the inventory command, if provided, and appends // the command's output lines to the manually defined list of hosts.
[ "ParseInventory", "runs", "the", "inventory", "command", "if", "provided", "and", "appends", "the", "command", "s", "output", "lines", "to", "the", "manually", "defined", "list", "of", "hosts", "." ]
be6dff41589b713547415b72660885dd7a045f8f
https://github.com/pressly/sup/blob/be6dff41589b713547415b72660885dd7a045f8f/supfile.go#L332-L366
train
bndr/gojenkins
jenkins.go
Info
func (j *Jenkins) Info() (*ExecutorResponse, error) { _, err := j.Requester.Get("/", j.Raw, nil) if err != nil { return nil, err } return j.Raw, nil }
go
func (j *Jenkins) Info() (*ExecutorResponse, error) { _, err := j.Requester.Get("/", j.Raw, nil) if err != nil { return nil, err } return j.Raw, nil }
[ "func", "(", "j", "*", "Jenkins", ")", "Info", "(", ")", "(", "*", "ExecutorResponse", ",", "error", ")", "{", "_", ",", "err", ":=", "j", ".", "Requester", ".", "Get", "(", "\"", "\"", ",", "j", ".", "Raw", ",", "nil", ")", "\n\n", "if", "er...
// Get Basic Information About Jenkins
[ "Get", "Basic", "Information", "About", "Jenkins" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L84-L91
train
bndr/gojenkins
jenkins.go
SafeRestart
func (j *Jenkins) SafeRestart() error { _, err := j.Requester.Post("/safeRestart", strings.NewReader(""), struct{}{}, map[string]string{}) return err }
go
func (j *Jenkins) SafeRestart() error { _, err := j.Requester.Post("/safeRestart", strings.NewReader(""), struct{}{}, map[string]string{}) return err }
[ "func", "(", "j", "*", "Jenkins", ")", "SafeRestart", "(", ")", "error", "{", "_", ",", "err", ":=", "j", ".", "Requester", ".", "Post", "(", "\"", "\"", ",", "strings", ".", "NewReader", "(", "\"", "\"", ")", ",", "struct", "{", "}", "{", "}",...
// SafeRestart jenkins, restart will be done when there are no jobs running
[ "SafeRestart", "jenkins", "restart", "will", "be", "done", "when", "there", "are", "no", "jobs", "running" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L94-L97
train
bndr/gojenkins
jenkins.go
DeleteNode
func (j *Jenkins) DeleteNode(name string) (bool, error) { node := Node{Jenkins: j, Raw: new(NodeResponse), Base: "/computer/" + name} return node.Delete() }
go
func (j *Jenkins) DeleteNode(name string) (bool, error) { node := Node{Jenkins: j, Raw: new(NodeResponse), Base: "/computer/" + name} return node.Delete() }
[ "func", "(", "j", "*", "Jenkins", ")", "DeleteNode", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "node", ":=", "Node", "{", "Jenkins", ":", "j", ",", "Raw", ":", "new", "(", "NodeResponse", ")", ",", "Base", ":", "\"", "\"", ...
// Delete a Jenkins slave node
[ "Delete", "a", "Jenkins", "slave", "node" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L179-L182
train
bndr/gojenkins
jenkins.go
RenameJob
func (j *Jenkins) RenameJob(job string, name string) *Job { jobObj := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + job} jobObj.Rename(name) return &jobObj }
go
func (j *Jenkins) RenameJob(job string, name string) *Job { jobObj := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + job} jobObj.Rename(name) return &jobObj }
[ "func", "(", "j", "*", "Jenkins", ")", "RenameJob", "(", "job", "string", ",", "name", "string", ")", "*", "Job", "{", "jobObj", ":=", "Job", "{", "Jenkins", ":", "j", ",", "Raw", ":", "new", "(", "JobResponse", ")", ",", "Base", ":", "\"", "\"",...
// Rename a job. // First parameter job old name, Second parameter job new name.
[ "Rename", "a", "job", ".", "First", "parameter", "job", "old", "name", "Second", "parameter", "job", "new", "name", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L231-L235
train
bndr/gojenkins
jenkins.go
CopyJob
func (j *Jenkins) CopyJob(copyFrom string, newName string) (*Job, error) { job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + copyFrom} _, err := job.Poll() if err != nil { return nil, err } return job.Copy(newName) }
go
func (j *Jenkins) CopyJob(copyFrom string, newName string) (*Job, error) { job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + copyFrom} _, err := job.Poll() if err != nil { return nil, err } return job.Copy(newName) }
[ "func", "(", "j", "*", "Jenkins", ")", "CopyJob", "(", "copyFrom", "string", ",", "newName", "string", ")", "(", "*", "Job", ",", "error", ")", "{", "job", ":=", "Job", "{", "Jenkins", ":", "j", ",", "Raw", ":", "new", "(", "JobResponse", ")", ",...
// Create a copy of a job. // First parameter Name of the job to copy from, Second parameter new job name.
[ "Create", "a", "copy", "of", "a", "job", ".", "First", "parameter", "Name", "of", "the", "job", "to", "copy", "from", "Second", "parameter", "new", "job", "name", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L239-L246
train
bndr/gojenkins
jenkins.go
DeleteJob
func (j *Jenkins) DeleteJob(name string) (bool, error) { job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name} return job.Delete() }
go
func (j *Jenkins) DeleteJob(name string) (bool, error) { job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name} return job.Delete() }
[ "func", "(", "j", "*", "Jenkins", ")", "DeleteJob", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "job", ":=", "Job", "{", "Jenkins", ":", "j", ",", "Raw", ":", "new", "(", "JobResponse", ")", ",", "Base", ":", "\"", "\"", "+...
// Delete a job.
[ "Delete", "a", "job", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L249-L252
train
bndr/gojenkins
jenkins.go
BuildJob
func (j *Jenkins) BuildJob(name string, options ...interface{}) (int64, error) { job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name} var params map[string]string if len(options) > 0 { params, _ = options[0].(map[string]string) } return job.InvokeSimple(params) }
go
func (j *Jenkins) BuildJob(name string, options ...interface{}) (int64, error) { job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name} var params map[string]string if len(options) > 0 { params, _ = options[0].(map[string]string) } return job.InvokeSimple(params) }
[ "func", "(", "j", "*", "Jenkins", ")", "BuildJob", "(", "name", "string", ",", "options", "...", "interface", "{", "}", ")", "(", "int64", ",", "error", ")", "{", "job", ":=", "Job", "{", "Jenkins", ":", "j", ",", "Raw", ":", "new", "(", "JobResp...
// Invoke a job. // First parameter job name, second parameter is optional Build parameters.
[ "Invoke", "a", "job", ".", "First", "parameter", "job", "name", "second", "parameter", "is", "optional", "Build", "parameters", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L256-L263
train
bndr/gojenkins
jenkins.go
GetAllJobNames
func (j *Jenkins) GetAllJobNames() ([]InnerJob, error) { exec := Executor{Raw: new(ExecutorResponse), Jenkins: j} _, err := j.Requester.GetJSON("/", exec.Raw, nil) if err != nil { return nil, err } return exec.Raw.Jobs, nil }
go
func (j *Jenkins) GetAllJobNames() ([]InnerJob, error) { exec := Executor{Raw: new(ExecutorResponse), Jenkins: j} _, err := j.Requester.GetJSON("/", exec.Raw, nil) if err != nil { return nil, err } return exec.Raw.Jobs, nil }
[ "func", "(", "j", "*", "Jenkins", ")", "GetAllJobNames", "(", ")", "(", "[", "]", "InnerJob", ",", "error", ")", "{", "exec", ":=", "Executor", "{", "Raw", ":", "new", "(", "ExecutorResponse", ")", ",", "Jenkins", ":", "j", "}", "\n", "_", ",", "...
// Get Only Array of Job Names, Color, URL // Does not query each single Job.
[ "Get", "Only", "Array", "of", "Job", "Names", "Color", "URL", "Does", "not", "query", "each", "single", "Job", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L372-L381
train
bndr/gojenkins
jenkins.go
GetAllJobs
func (j *Jenkins) GetAllJobs() ([]*Job, error) { exec := Executor{Raw: new(ExecutorResponse), Jenkins: j} _, err := j.Requester.GetJSON("/", exec.Raw, nil) if err != nil { return nil, err } jobs := make([]*Job, len(exec.Raw.Jobs)) for i, job := range exec.Raw.Jobs { ji, err := j.GetJob(job.Name) if err != nil { return nil, err } jobs[i] = ji } return jobs, nil }
go
func (j *Jenkins) GetAllJobs() ([]*Job, error) { exec := Executor{Raw: new(ExecutorResponse), Jenkins: j} _, err := j.Requester.GetJSON("/", exec.Raw, nil) if err != nil { return nil, err } jobs := make([]*Job, len(exec.Raw.Jobs)) for i, job := range exec.Raw.Jobs { ji, err := j.GetJob(job.Name) if err != nil { return nil, err } jobs[i] = ji } return jobs, nil }
[ "func", "(", "j", "*", "Jenkins", ")", "GetAllJobs", "(", ")", "(", "[", "]", "*", "Job", ",", "error", ")", "{", "exec", ":=", "Executor", "{", "Raw", ":", "new", "(", "ExecutorResponse", ")", ",", "Jenkins", ":", "j", "}", "\n", "_", ",", "er...
// Get All Possible Job Objects. // Each job will be queried.
[ "Get", "All", "Possible", "Job", "Objects", ".", "Each", "job", "will", "be", "queried", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L385-L402
train
bndr/gojenkins
jenkins.go
GetQueue
func (j *Jenkins) GetQueue() (*Queue, error) { q := &Queue{Jenkins: j, Raw: new(queueResponse), Base: j.GetQueueUrl()} _, err := q.Poll() if err != nil { return nil, err } return q, nil }
go
func (j *Jenkins) GetQueue() (*Queue, error) { q := &Queue{Jenkins: j, Raw: new(queueResponse), Base: j.GetQueueUrl()} _, err := q.Poll() if err != nil { return nil, err } return q, nil }
[ "func", "(", "j", "*", "Jenkins", ")", "GetQueue", "(", ")", "(", "*", "Queue", ",", "error", ")", "{", "q", ":=", "&", "Queue", "{", "Jenkins", ":", "j", ",", "Raw", ":", "new", "(", "queueResponse", ")", ",", "Base", ":", "j", ".", "GetQueueU...
// Returns a Queue
[ "Returns", "a", "Queue" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L405-L412
train
bndr/gojenkins
jenkins.go
GetQueueItem
func (j *Jenkins) GetQueueItem(id int64) (*Task, error) { t := &Task{Raw: new(taskResponse), Jenkins: j, Base: j.getQueueItemURL(id)} _, err := t.Poll() if err != nil { return nil, err } return t, nil }
go
func (j *Jenkins) GetQueueItem(id int64) (*Task, error) { t := &Task{Raw: new(taskResponse), Jenkins: j, Base: j.getQueueItemURL(id)} _, err := t.Poll() if err != nil { return nil, err } return t, nil }
[ "func", "(", "j", "*", "Jenkins", ")", "GetQueueItem", "(", "id", "int64", ")", "(", "*", "Task", ",", "error", ")", "{", "t", ":=", "&", "Task", "{", "Raw", ":", "new", "(", "taskResponse", ")", ",", "Jenkins", ":", "j", ",", "Base", ":", "j",...
// GetQueueItem returns a single queue Task
[ "GetQueueItem", "returns", "a", "single", "queue", "Task" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L419-L426
train
bndr/gojenkins
jenkins.go
GetArtifactData
func (j *Jenkins) GetArtifactData(id string) (*FingerPrintResponse, error) { fp := FingerPrint{Jenkins: j, Base: "/fingerprint/", Id: id, Raw: new(FingerPrintResponse)} return fp.GetInfo() }
go
func (j *Jenkins) GetArtifactData(id string) (*FingerPrintResponse, error) { fp := FingerPrint{Jenkins: j, Base: "/fingerprint/", Id: id, Raw: new(FingerPrintResponse)} return fp.GetInfo() }
[ "func", "(", "j", "*", "Jenkins", ")", "GetArtifactData", "(", "id", "string", ")", "(", "*", "FingerPrintResponse", ",", "error", ")", "{", "fp", ":=", "FingerPrint", "{", "Jenkins", ":", "j", ",", "Base", ":", "\"", "\"", ",", "Id", ":", "id", ",...
// Get Artifact data by Hash
[ "Get", "Artifact", "data", "by", "Hash" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L433-L436
train
bndr/gojenkins
jenkins.go
GetPlugins
func (j *Jenkins) GetPlugins(depth int) (*Plugins, error) { p := Plugins{Jenkins: j, Raw: new(PluginResponse), Base: "/pluginManager", Depth: depth} _, err := p.Poll() if err != nil { return nil, err } return &p, nil }
go
func (j *Jenkins) GetPlugins(depth int) (*Plugins, error) { p := Plugins{Jenkins: j, Raw: new(PluginResponse), Base: "/pluginManager", Depth: depth} _, err := p.Poll() if err != nil { return nil, err } return &p, nil }
[ "func", "(", "j", "*", "Jenkins", ")", "GetPlugins", "(", "depth", "int", ")", "(", "*", "Plugins", ",", "error", ")", "{", "p", ":=", "Plugins", "{", "Jenkins", ":", "j", ",", "Raw", ":", "new", "(", "PluginResponse", ")", ",", "Base", ":", "\""...
// Returns the list of all plugins installed on the Jenkins server. // You can supply depth parameter, to limit how much data is returned.
[ "Returns", "the", "list", "of", "all", "plugins", "installed", "on", "the", "Jenkins", "server", ".", "You", "can", "supply", "depth", "parameter", "to", "limit", "how", "much", "data", "is", "returned", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L440-L447
train
bndr/gojenkins
jenkins.go
UninstallPlugin
func (j *Jenkins) UninstallPlugin(name string) error { url := fmt.Sprintf("/pluginManager/plugin/%s/doUninstall", name) resp, err := j.Requester.Post(url, strings.NewReader(""), struct{}{}, map[string]string{}) if resp.StatusCode != 200 { return fmt.Errorf("Invalid status code returned: %d", resp.StatusCode) } return err }
go
func (j *Jenkins) UninstallPlugin(name string) error { url := fmt.Sprintf("/pluginManager/plugin/%s/doUninstall", name) resp, err := j.Requester.Post(url, strings.NewReader(""), struct{}{}, map[string]string{}) if resp.StatusCode != 200 { return fmt.Errorf("Invalid status code returned: %d", resp.StatusCode) } return err }
[ "func", "(", "j", "*", "Jenkins", ")", "UninstallPlugin", "(", "name", "string", ")", "error", "{", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", "\n", "resp", ",", "err", ":=", "j", ".", "Requester", ".", "Post", "(", "u...
// UninstallPlugin plugin otherwise returns error
[ "UninstallPlugin", "plugin", "otherwise", "returns", "error" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L450-L457
train
bndr/gojenkins
jenkins.go
HasPlugin
func (j *Jenkins) HasPlugin(name string) (*Plugin, error) { p, err := j.GetPlugins(1) if err != nil { return nil, err } return p.Contains(name), nil }
go
func (j *Jenkins) HasPlugin(name string) (*Plugin, error) { p, err := j.GetPlugins(1) if err != nil { return nil, err } return p.Contains(name), nil }
[ "func", "(", "j", "*", "Jenkins", ")", "HasPlugin", "(", "name", "string", ")", "(", "*", "Plugin", ",", "error", ")", "{", "p", ",", "err", ":=", "j", ".", "GetPlugins", "(", "1", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",...
// Check if the plugin is installed on the server. // Depth level 1 is used. If you need to go deeper, you can use GetPlugins, and iterate through them.
[ "Check", "if", "the", "plugin", "is", "installed", "on", "the", "server", ".", "Depth", "level", "1", "is", "used", ".", "If", "you", "need", "to", "go", "deeper", "you", "can", "use", "GetPlugins", "and", "iterate", "through", "them", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L461-L468
train
bndr/gojenkins
jenkins.go
InstallPlugin
func (j *Jenkins) InstallPlugin(name string, version string) error { xml := fmt.Sprintf(`<jenkins><install plugin="%s@%s" /></jenkins>`, name, version) resp, err := j.Requester.PostXML("/pluginManager/installNecessaryPlugins", xml, j.Raw, map[string]string{}) if resp.StatusCode != 200 { return fmt.Errorf("Invalid status code returned: %d", resp.StatusCode) } return err }
go
func (j *Jenkins) InstallPlugin(name string, version string) error { xml := fmt.Sprintf(`<jenkins><install plugin="%s@%s" /></jenkins>`, name, version) resp, err := j.Requester.PostXML("/pluginManager/installNecessaryPlugins", xml, j.Raw, map[string]string{}) if resp.StatusCode != 200 { return fmt.Errorf("Invalid status code returned: %d", resp.StatusCode) } return err }
[ "func", "(", "j", "*", "Jenkins", ")", "InstallPlugin", "(", "name", "string", ",", "version", "string", ")", "error", "{", "xml", ":=", "fmt", ".", "Sprintf", "(", "`<jenkins><install plugin=\"%s@%s\" /></jenkins>`", ",", "name", ",", "version", ")", "\n", ...
//InstallPlugin with given version and name
[ "InstallPlugin", "with", "given", "version", "and", "name" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/jenkins.go#L471-L479
train
bndr/gojenkins
credentials.go
List
func (cm CredentialsManager) List(domain string) ([]string, error) { idsResponse := credentialIDs{} ids := make([]string, 0) err := cm.handleResponse(cm.J.Requester.Get(cm.fillURL(credentialsListURL, domain), &idsResponse, listQuery)) if err != nil { return ids, err } for _, id := range idsResponse.Credentials { ids = append(ids, id.ID) } return ids, nil }
go
func (cm CredentialsManager) List(domain string) ([]string, error) { idsResponse := credentialIDs{} ids := make([]string, 0) err := cm.handleResponse(cm.J.Requester.Get(cm.fillURL(credentialsListURL, domain), &idsResponse, listQuery)) if err != nil { return ids, err } for _, id := range idsResponse.Credentials { ids = append(ids, id.ID) } return ids, nil }
[ "func", "(", "cm", "CredentialsManager", ")", "List", "(", "domain", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "idsResponse", ":=", "credentialIDs", "{", "}", "\n", "ids", ":=", "make", "(", "[", "]", "string", ",", "0", ")", ...
//List ids if credentials stored inside provided domain
[ "List", "ids", "if", "credentials", "stored", "inside", "provided", "domain" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/credentials.go#L110-L124
train
bndr/gojenkins
credentials.go
Add
func (cm CredentialsManager) Add(domain string, creds interface{}) error { return cm.postCredsXML(cm.fillURL(createCredentialsURL, domain), creds) }
go
func (cm CredentialsManager) Add(domain string, creds interface{}) error { return cm.postCredsXML(cm.fillURL(createCredentialsURL, domain), creds) }
[ "func", "(", "cm", "CredentialsManager", ")", "Add", "(", "domain", "string", ",", "creds", "interface", "{", "}", ")", "error", "{", "return", "cm", ".", "postCredsXML", "(", "cm", ".", "fillURL", "(", "createCredentialsURL", ",", "domain", ")", ",", "c...
//Add credential to given domain, creds must be struct which is parsable to xml
[ "Add", "credential", "to", "given", "domain", "creds", "must", "be", "struct", "which", "is", "parsable", "to", "xml" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/credentials.go#L139-L141
train
bndr/gojenkins
credentials.go
Delete
func (cm CredentialsManager) Delete(domain string, id string) error { return cm.handleResponse(cm.J.Requester.Post(cm.fillURL(deleteCredentialURL, domain, id), nil, cm.J.Raw, map[string]string{})) }
go
func (cm CredentialsManager) Delete(domain string, id string) error { return cm.handleResponse(cm.J.Requester.Post(cm.fillURL(deleteCredentialURL, domain, id), nil, cm.J.Raw, map[string]string{})) }
[ "func", "(", "cm", "CredentialsManager", ")", "Delete", "(", "domain", "string", ",", "id", "string", ")", "error", "{", "return", "cm", ".", "handleResponse", "(", "cm", ".", "J", ".", "Requester", ".", "Post", "(", "cm", ".", "fillURL", "(", "deleteC...
//Delete credential in given domain with given id
[ "Delete", "credential", "in", "given", "domain", "with", "given", "id" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/credentials.go#L144-L146
train
bndr/gojenkins
credentials.go
Update
func (cm CredentialsManager) Update(domain string, id string, creds interface{}) error { return cm.postCredsXML(cm.fillURL(configCredentialURL, domain, id), creds) }
go
func (cm CredentialsManager) Update(domain string, id string, creds interface{}) error { return cm.postCredsXML(cm.fillURL(configCredentialURL, domain, id), creds) }
[ "func", "(", "cm", "CredentialsManager", ")", "Update", "(", "domain", "string", ",", "id", "string", ",", "creds", "interface", "{", "}", ")", "error", "{", "return", "cm", ".", "postCredsXML", "(", "cm", ".", "fillURL", "(", "configCredentialURL", ",", ...
//Update credential in given domain with given id, creds must be pointer to struct which is parsable to xml
[ "Update", "credential", "in", "given", "domain", "with", "given", "id", "creds", "must", "be", "pointer", "to", "struct", "which", "is", "parsable", "to", "xml" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/credentials.go#L149-L151
train
bndr/gojenkins
request.go
redirectPolicyFunc
func (r *Requester) redirectPolicyFunc(req *http.Request, via []*http.Request) error { if r.BasicAuth != nil { req.SetBasicAuth(r.BasicAuth.Username, r.BasicAuth.Password) } return nil }
go
func (r *Requester) redirectPolicyFunc(req *http.Request, via []*http.Request) error { if r.BasicAuth != nil { req.SetBasicAuth(r.BasicAuth.Username, r.BasicAuth.Password) } return nil }
[ "func", "(", "r", "*", "Requester", ")", "redirectPolicyFunc", "(", "req", "*", "http", ".", "Request", ",", "via", "[", "]", "*", "http", ".", "Request", ")", "error", "{", "if", "r", ".", "BasicAuth", "!=", "nil", "{", "req", ".", "SetBasicAuth", ...
//Add auth on redirect if required.
[ "Add", "auth", "on", "redirect", "if", "required", "." ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/request.go#L138-L143
train
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", ",", "...
// Get raw byte data of Artifact
[ "Get", "raw", "byte", "data", "of", "Artifact" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/artifact.go#L36-L50
train
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", ".", "...
// 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
train
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", "(", "\"", ...
// 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
train
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", ".", "J...
// Compare Remote and local MD5
[ "Compare", "Remote", "and", "local", "MD5" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/artifact.go#L87-L101
train
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", "{", ...
// Get Local MD5
[ "Get", "Local", "MD5" ]
de43c03cf849dd63a9737df6e05791c7a176c93d
https://github.com/bndr/gojenkins/blob/de43c03cf849dd63a9737df6e05791c7a176c93d/artifact.go#L104-L118
train
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",...
// 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
train
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"...
// 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
train
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", ",...
// 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
train
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 &gt; Console Output" tooltip="Failed &gt; 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 &gt; Console Output" tooltip="Failed &gt; 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", ...
// 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
train
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...
// NextFields returns the next `count` fields
[ "NextFields", "returns", "the", "next", "count", "fields" ]
6a014d5e22e6a0b7c1fcb65f59872e4dd1227111
https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/scanner.go#L17-L27
train
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", ".", ...
// Next returns the next field
[ "Next", "returns", "the", "next", "field" ]
6a014d5e22e6a0b7c1fcb65f59872e4dd1227111
https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/scanner.go#L30-L53
train
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
train
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", ".", ...
// 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
train
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
train
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
train
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
train
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
train
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", "s...
6a014d5e22e6a0b7c1fcb65f59872e4dd1227111
https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L173-L177
train
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
train
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
train
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
train
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", ".", ...
// 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", ...
6a014d5e22e6a0b7c1fcb65f59872e4dd1227111
https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L208-L212
train
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",...
// 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
train
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", ...
// 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
train
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", "!=", ...
// 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
train
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...
// 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
train
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...
// 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
train
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...
// 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
train
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 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
train
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", ".", "ope...
// 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
train
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", ")...
// NameList issues an NLST FTP command.
[ "NameList", "issues", "an", "NLST", "FTP", "command", "." ]
6a014d5e22e6a0b7c1fcb65f59872e4dd1227111
https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L464-L481
train
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", ...
// List issues a LIST FTP command.
[ "List", "issues", "a", "LIST", "FTP", "command", "." ]
6a014d5e22e6a0b7c1fcb65f59872e4dd1227111
https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L484-L516
train
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
train
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", "{", "r...
// 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
train
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",...
// 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
train
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
train
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", ",", "\"", "\"", ",", "pa...
// 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"...
6a014d5e22e6a0b7c1fcb65f59872e4dd1227111
https://github.com/jlaffaye/ftp/blob/6a014d5e22e6a0b7c1fcb65f59872e4dd1227111/ftp.go#L573-L580
train
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", "!="...
// 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
train
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
train
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", ",", "e...
// 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
train
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
train
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
train
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
train
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
train
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
train
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", "....
// 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
train
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
train
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", ",", "\"", "\"...
// 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
train
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", "(...
// 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
train
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", ...
// 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
train
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",...
// 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
train
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"...
// 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"...
9d2ed221270221cf82616946316a0a62dca4a4a9
https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/ejson.go#L22-L28
train
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", "-",...
// 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", "...
9d2ed221270221cf82616946316a0a62dca4a4a9
https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/ejson.go#L35-L62
train
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", "...
// 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", "...
9d2ed221270221cf82616946316a0a62dca4a4a9
https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/ejson.go#L103-L137
train
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...
// 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"...
9d2ed221270221cf82616946316a0a62dca4a4a9
https://github.com/Shopify/ejson/blob/9d2ed221270221cf82616946316a0a62dca4a4a9/ejson.go#L145-L161
train
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", ".", "StdEncod...
// 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
train
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", ".", "F...
// 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
train
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", "...
// 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
train
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"...
// 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
train
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", ",", "&", ...
// 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
train
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", ":"...
// New instantiates a new connection multiplexer.
[ "New", "instantiates", "a", "new", "connection", "multiplexer", "." ]
8a8ea3c53959009183d7914522833c1ed8835020
https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/cmux.go#L68-L76
train
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", "}", ")",...
// 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
train
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", ")", "b...
// 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
train
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",...
// 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", "v...
8a8ea3c53959009183d7914522833c1ed8835020
https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L139-L145
train
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", "("...
// 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
train
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", ",", "...
// 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", "ma...
8a8ea3c53959009183d7914522833c1ed8835020
https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L160-L166
train
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", ...
// 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", ...
8a8ea3c53959009183d7914522833c1ed8835020
https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L171-L177
train
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", ",...
// 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", ...
8a8ea3c53959009183d7914522833c1ed8835020
https://github.com/soheilhy/cmux/blob/8a8ea3c53959009183d7914522833c1ed8835020/matchers.go#L182-L188
train
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
train
getlantern/systray
systray.go
AddMenuItem
func AddMenuItem(title string, tooltip string) *MenuItem { id := atomic.AddInt32(&currentID, 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(&currentID, 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",...
// 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", "gor...
26d5b920200dbc1869c4bfde4571497082f83caa
https://github.com/getlantern/systray/blob/26d5b920200dbc1869c4bfde4571497082f83caa/systray.go#L95-L101
train
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
train
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
train
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...
// 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
train