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
vmware/govmomi
simulator/simulator.go
RegisterSDK
func (s *Service) RegisterSDK(r *Registry) { if s.ServeMux == nil { s.ServeMux = http.NewServeMux() } s.sdk[r.Path] = r s.ServeMux.HandleFunc(r.Path, s.ServeSDK) }
go
func (s *Service) RegisterSDK(r *Registry) { if s.ServeMux == nil { s.ServeMux = http.NewServeMux() } s.sdk[r.Path] = r s.ServeMux.HandleFunc(r.Path, s.ServeSDK) }
[ "func", "(", "s", "*", "Service", ")", "RegisterSDK", "(", "r", "*", "Registry", ")", "{", "if", "s", ".", "ServeMux", "==", "nil", "{", "s", ".", "ServeMux", "=", "http", ".", "NewServeMux", "(", ")", "\n", "}", "\n\n", "s", ".", "sdk", "[", "...
// RegisterSDK adds an HTTP handler for the Registry's Path and Namespace.
[ "RegisterSDK", "adds", "an", "HTTP", "handler", "for", "the", "Registry", "s", "Path", "and", "Namespace", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L376-L383
train
vmware/govmomi
simulator/simulator.go
ServeSDK
func (s *Service) ServeSDK(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { w.WriteHeader(http.StatusMethodNotAllowed) return } body, err := s.readAll(r.Body) _ = r.Body.Close() if err != nil { log.Printf("error reading body: %s", err) w.WriteHeader(http.StatusBadRequest) retur...
go
func (s *Service) ServeSDK(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { w.WriteHeader(http.StatusMethodNotAllowed) return } body, err := s.readAll(r.Body) _ = r.Body.Close() if err != nil { log.Printf("error reading body: %s", err) w.WriteHeader(http.StatusBadRequest) retur...
[ "func", "(", "s", "*", "Service", ")", "ServeSDK", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "r", ".", "Method", "!=", "http", ".", "MethodPost", "{", "w", ".", "WriteHeader", "(", "http", ".", ...
// ServeSDK implements the http.Handler interface
[ "ServeSDK", "implements", "the", "http", ".", "Handler", "interface" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L386-L476
train
vmware/govmomi
simulator/simulator.go
defaultIP
func defaultIP(addr *net.TCPAddr) string { if !addr.IP.IsUnspecified() { return addr.IP.String() } nics, err := net.Interfaces() if err != nil { return addr.IP.String() } for _, nic := range nics { if nic.Name == "docker0" || strings.HasPrefix(nic.Name, "vmnet") { continue } addrs, aerr := nic.Addr...
go
func defaultIP(addr *net.TCPAddr) string { if !addr.IP.IsUnspecified() { return addr.IP.String() } nics, err := net.Interfaces() if err != nil { return addr.IP.String() } for _, nic := range nics { if nic.Name == "docker0" || strings.HasPrefix(nic.Name, "vmnet") { continue } addrs, aerr := nic.Addr...
[ "func", "defaultIP", "(", "addr", "*", "net", ".", "TCPAddr", ")", "string", "{", "if", "!", "addr", ".", "IP", ".", "IsUnspecified", "(", ")", "{", "return", "addr", ".", "IP", ".", "String", "(", ")", "\n", "}", "\n\n", "nics", ",", "err", ":="...
// defaultIP returns addr.IP if specified, otherwise attempts to find a non-loopback ipv4 IP
[ "defaultIP", "returns", "addr", ".", "IP", "if", "specified", "otherwise", "attempts", "to", "find", "a", "non", "-", "loopback", "ipv4", "IP" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L561-L589
train
vmware/govmomi
simulator/simulator.go
NewServer
func (s *Service) NewServer() *Server { s.RegisterSDK(Map) mux := s.ServeMux vim := Map.Path + "/vimService" s.sdk[vim] = s.sdk[vim25.Path] mux.HandleFunc(vim, s.ServeSDK) mux.HandleFunc(Map.Path+"/vimServiceVersions.xml", s.ServiceVersions) mux.HandleFunc(folderPrefix, s.ServeDatastore) mux.HandleFunc(nfcPref...
go
func (s *Service) NewServer() *Server { s.RegisterSDK(Map) mux := s.ServeMux vim := Map.Path + "/vimService" s.sdk[vim] = s.sdk[vim25.Path] mux.HandleFunc(vim, s.ServeSDK) mux.HandleFunc(Map.Path+"/vimServiceVersions.xml", s.ServiceVersions) mux.HandleFunc(folderPrefix, s.ServeDatastore) mux.HandleFunc(nfcPref...
[ "func", "(", "s", "*", "Service", ")", "NewServer", "(", ")", "*", "Server", "{", "s", ".", "RegisterSDK", "(", "Map", ")", "\n\n", "mux", ":=", "s", ".", "ServeMux", "\n", "vim", ":=", "Map", ".", "Path", "+", "\"", "\"", "\n", "s", ".", "sdk"...
// NewServer returns an http Server instance for the given service
[ "NewServer", "returns", "an", "http", "Server", "instance", "for", "the", "given", "service" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L592-L645
train
vmware/govmomi
simulator/simulator.go
Certificate
func (s *Server) Certificate() *x509.Certificate { // By default httptest.StartTLS uses http/internal.LocalhostCert, which we can access here: cert, _ := x509.ParseCertificate(s.TLS.Certificates[0].Certificate[0]) return cert }
go
func (s *Server) Certificate() *x509.Certificate { // By default httptest.StartTLS uses http/internal.LocalhostCert, which we can access here: cert, _ := x509.ParseCertificate(s.TLS.Certificates[0].Certificate[0]) return cert }
[ "func", "(", "s", "*", "Server", ")", "Certificate", "(", ")", "*", "x509", ".", "Certificate", "{", "// By default httptest.StartTLS uses http/internal.LocalhostCert, which we can access here:", "cert", ",", "_", ":=", "x509", ".", "ParseCertificate", "(", "s", ".", ...
// Certificate returns the TLS certificate for the Server if started with TLS enabled. // This method will panic if TLS is not enabled for the server.
[ "Certificate", "returns", "the", "TLS", "certificate", "for", "the", "Server", "if", "started", "with", "TLS", "enabled", ".", "This", "method", "will", "panic", "if", "TLS", "is", "not", "enabled", "for", "the", "server", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L649-L653
train
vmware/govmomi
simulator/simulator.go
proxy
func (s *Server) proxy(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodConnect { http.Error(w, "", http.StatusMethodNotAllowed) return } dst, err := net.Dial("tcp", s.URL.Host) if err != nil { http.Error(w, err.Error(), http.StatusBadGateway) return } w.WriteHeader(http.StatusOK) sr...
go
func (s *Server) proxy(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodConnect { http.Error(w, "", http.StatusMethodNotAllowed) return } dst, err := net.Dial("tcp", s.URL.Host) if err != nil { http.Error(w, err.Error(), http.StatusBadGateway) return } w.WriteHeader(http.StatusOK) sr...
[ "func", "(", "s", "*", "Server", ")", "proxy", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "r", ".", "Method", "!=", "http", ".", "MethodConnect", "{", "http", ".", "Error", "(", "w", ",", "\"",...
// proxy tunnels SDK requests
[ "proxy", "tunnels", "SDK", "requests" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L681-L706
train
vmware/govmomi
simulator/simulator.go
StartTunnel
func (s *Server) StartTunnel() error { tunnel := &http.Server{ Addr: fmt.Sprintf("%s:%d", s.URL.Hostname(), s.Tunnel), Handler: http.HandlerFunc(s.proxy), } l, err := net.Listen("tcp", tunnel.Addr) if err != nil { return err } if s.Tunnel == 0 { s.Tunnel = l.Addr().(*net.TCPAddr).Port } // Set cli...
go
func (s *Server) StartTunnel() error { tunnel := &http.Server{ Addr: fmt.Sprintf("%s:%d", s.URL.Hostname(), s.Tunnel), Handler: http.HandlerFunc(s.proxy), } l, err := net.Listen("tcp", tunnel.Addr) if err != nil { return err } if s.Tunnel == 0 { s.Tunnel = l.Addr().(*net.TCPAddr).Port } // Set cli...
[ "func", "(", "s", "*", "Server", ")", "StartTunnel", "(", ")", "error", "{", "tunnel", ":=", "&", "http", ".", "Server", "{", "Addr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "URL", ".", "Hostname", "(", ")", ",", "s", ".", ...
// StartTunnel runs an HTTP proxy for tunneling SDK requests that require TLS client certificate authentication.
[ "StartTunnel", "runs", "an", "HTTP", "proxy", "for", "tunneling", "SDK", "requests", "that", "require", "TLS", "client", "certificate", "authentication", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L709-L732
train
vmware/govmomi
simulator/simulator.go
UnmarshalBody
func UnmarshalBody(typeFunc func(string) (reflect.Type, bool), data []byte) (*Method, error) { body := &Element{typeFunc: typeFunc} req := soap.Envelope{ Header: &soap.Header{ Security: new(Element), }, Body: body, } err := xml.Unmarshal(data, &req) if err != nil { return nil, fmt.Errorf("xml.Unmarshal...
go
func UnmarshalBody(typeFunc func(string) (reflect.Type, bool), data []byte) (*Method, error) { body := &Element{typeFunc: typeFunc} req := soap.Envelope{ Header: &soap.Header{ Security: new(Element), }, Body: body, } err := xml.Unmarshal(data, &req) if err != nil { return nil, fmt.Errorf("xml.Unmarshal...
[ "func", "UnmarshalBody", "(", "typeFunc", "func", "(", "string", ")", "(", "reflect", ".", "Type", ",", "bool", ")", ",", "data", "[", "]", "byte", ")", "(", "*", "Method", ",", "error", ")", "{", "body", ":=", "&", "Element", "{", "typeFunc", ":",...
// UnmarshalBody extracts the Body from a soap.Envelope and unmarshals to the corresponding govmomi type
[ "UnmarshalBody", "extracts", "the", "Body", "from", "a", "soap", ".", "Envelope", "and", "unmarshals", "to", "the", "corresponding", "govmomi", "type" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L786-L838
train
vmware/govmomi
govc/host/autostart/info.go
vmPaths
func (r *infoResult) vmPaths() (map[string]string, error) { ctx := context.TODO() paths := make(map[string]string) for _, info := range r.mhas.Config.PowerInfo { mes, err := mo.Ancestors(ctx, r.client, r.client.ServiceContent.PropertyCollector, info.Key) if err != nil { return nil, err } path := "" for...
go
func (r *infoResult) vmPaths() (map[string]string, error) { ctx := context.TODO() paths := make(map[string]string) for _, info := range r.mhas.Config.PowerInfo { mes, err := mo.Ancestors(ctx, r.client, r.client.ServiceContent.PropertyCollector, info.Key) if err != nil { return nil, err } path := "" for...
[ "func", "(", "r", "*", "infoResult", ")", "vmPaths", "(", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "ctx", ":=", "context", ".", "TODO", "(", ")", "\n", "paths", ":=", "make", "(", "map", "[", "string", "]", "string",...
// vmPaths resolves the paths for the VMs in the result.
[ "vmPaths", "resolves", "the", "paths", "for", "the", "VMs", "in", "the", "result", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/host/autostart/info.go#L86-L108
train
vmware/govmomi
simulator/custom_fields_manager.go
entitiesFieldRemove
func entitiesFieldRemove(field types.CustomFieldDef) { entities := Map.All(field.ManagedObjectType) for _, e := range entities { entity := e.Entity() Map.WithLock(entity, func() { aFields := entity.AvailableField for i, aField := range aFields { if aField.Key == field.Key { entity.AvailableField = ...
go
func entitiesFieldRemove(field types.CustomFieldDef) { entities := Map.All(field.ManagedObjectType) for _, e := range entities { entity := e.Entity() Map.WithLock(entity, func() { aFields := entity.AvailableField for i, aField := range aFields { if aField.Key == field.Key { entity.AvailableField = ...
[ "func", "entitiesFieldRemove", "(", "field", "types", ".", "CustomFieldDef", ")", "{", "entities", ":=", "Map", ".", "All", "(", "field", ".", "ManagedObjectType", ")", "\n", "for", "_", ",", "e", ":=", "range", "entities", "{", "entity", ":=", "e", ".",...
// Iterates through all entities of passed field type; // Removes found field from their custom field properties.
[ "Iterates", "through", "all", "entities", "of", "passed", "field", "type", ";", "Removes", "found", "field", "from", "their", "custom", "field", "properties", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/custom_fields_manager.go#L41-L71
train
vmware/govmomi
simulator/custom_fields_manager.go
entitiesFieldRename
func entitiesFieldRename(field types.CustomFieldDef) { entities := Map.All(field.ManagedObjectType) for _, e := range entities { entity := e.Entity() Map.WithLock(entity, func() { aFields := entity.AvailableField for i, aField := range aFields { if aField.Key == field.Key { aFields[i].Name = field....
go
func entitiesFieldRename(field types.CustomFieldDef) { entities := Map.All(field.ManagedObjectType) for _, e := range entities { entity := e.Entity() Map.WithLock(entity, func() { aFields := entity.AvailableField for i, aField := range aFields { if aField.Key == field.Key { aFields[i].Name = field....
[ "func", "entitiesFieldRename", "(", "field", "types", ".", "CustomFieldDef", ")", "{", "entities", ":=", "Map", ".", "All", "(", "field", ".", "ManagedObjectType", ")", "\n", "for", "_", ",", "e", ":=", "range", "entities", "{", "entity", ":=", "e", ".",...
// Iterates through all entities of passed field type; // Renames found field in entity's AvailableField property.
[ "Iterates", "through", "all", "entities", "of", "passed", "field", "type", ";", "Renames", "found", "field", "in", "entity", "s", "AvailableField", "property", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/custom_fields_manager.go#L75-L89
train
vmware/govmomi
toolbox/hgfs/archive.go
Stat
func (*ArchiveHandler) Stat(u *url.URL) (os.FileInfo, error) { switch u.Query().Get("format") { case "", "tar", "tgz": // ok default: log.Printf("unknown archive format: %q", u) return nil, vix.Error(vix.InvalidArg) } return &archive{ name: u.Path, size: math.MaxInt64, }, nil }
go
func (*ArchiveHandler) Stat(u *url.URL) (os.FileInfo, error) { switch u.Query().Get("format") { case "", "tar", "tgz": // ok default: log.Printf("unknown archive format: %q", u) return nil, vix.Error(vix.InvalidArg) } return &archive{ name: u.Path, size: math.MaxInt64, }, nil }
[ "func", "(", "*", "ArchiveHandler", ")", "Stat", "(", "u", "*", "url", ".", "URL", ")", "(", "os", ".", "FileInfo", ",", "error", ")", "{", "switch", "u", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", "{", "case", "\"", "\"", ",",...
// Stat implements FileHandler.Stat
[ "Stat", "implements", "FileHandler", ".", "Stat" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/archive.go#L56-L69
train
vmware/govmomi
toolbox/hgfs/archive.go
Open
func (h *ArchiveHandler) Open(u *url.URL, mode int32) (File, error) { switch mode { case OpenModeReadOnly: return h.newArchiveFromGuest(u) case OpenModeWriteOnly: return h.newArchiveToGuest(u) default: return nil, os.ErrNotExist } }
go
func (h *ArchiveHandler) Open(u *url.URL, mode int32) (File, error) { switch mode { case OpenModeReadOnly: return h.newArchiveFromGuest(u) case OpenModeWriteOnly: return h.newArchiveToGuest(u) default: return nil, os.ErrNotExist } }
[ "func", "(", "h", "*", "ArchiveHandler", ")", "Open", "(", "u", "*", "url", ".", "URL", ",", "mode", "int32", ")", "(", "File", ",", "error", ")", "{", "switch", "mode", "{", "case", "OpenModeReadOnly", ":", "return", "h", ".", "newArchiveFromGuest", ...
// Open implements FileHandler.Open
[ "Open", "implements", "FileHandler", ".", "Open" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/archive.go#L72-L81
train
vmware/govmomi
toolbox/hgfs/archive.go
newArchiveFromGuest
func (h *ArchiveHandler) newArchiveFromGuest(u *url.URL) (File, error) { r, w := io.Pipe() a := &archive{ name: u.Path, done: r.Close, Reader: r, Writer: w, } var z io.Writer = w var c io.Closer = ioutil.NopCloser(nil) switch u.Query().Get("format") { case "tgz": gz := gzip.NewWriter(w) z = gz...
go
func (h *ArchiveHandler) newArchiveFromGuest(u *url.URL) (File, error) { r, w := io.Pipe() a := &archive{ name: u.Path, done: r.Close, Reader: r, Writer: w, } var z io.Writer = w var c io.Closer = ioutil.NopCloser(nil) switch u.Query().Get("format") { case "tgz": gz := gzip.NewWriter(w) z = gz...
[ "func", "(", "h", "*", "ArchiveHandler", ")", "newArchiveFromGuest", "(", "u", "*", "url", ".", "URL", ")", "(", "File", ",", "error", ")", "{", "r", ",", "w", ":=", "io", ".", "Pipe", "(", ")", "\n\n", "a", ":=", "&", "archive", "{", "name", "...
// newArchiveFromGuest returns an hgfs.File implementation to read a directory as a gzip'd tar.
[ "newArchiveFromGuest", "returns", "an", "hgfs", ".", "File", "implementation", "to", "read", "a", "directory", "as", "a", "gzip", "d", "tar", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/archive.go#L131-L165
train
vmware/govmomi
toolbox/hgfs/archive.go
newArchiveToGuest
func (h *ArchiveHandler) newArchiveToGuest(u *url.URL) (File, error) { r, w := io.Pipe() buf := bufio.NewReader(r) a := &archive{ name: u.Path, Reader: buf, Writer: w, } var cerr error var wg sync.WaitGroup a.done = func() error { _ = w.Close() // We need to wait for unpack to finish to complete ...
go
func (h *ArchiveHandler) newArchiveToGuest(u *url.URL) (File, error) { r, w := io.Pipe() buf := bufio.NewReader(r) a := &archive{ name: u.Path, Reader: buf, Writer: w, } var cerr error var wg sync.WaitGroup a.done = func() error { _ = w.Close() // We need to wait for unpack to finish to complete ...
[ "func", "(", "h", "*", "ArchiveHandler", ")", "newArchiveToGuest", "(", "u", "*", "url", ".", "URL", ")", "(", "File", ",", "error", ")", "{", "r", ",", "w", ":=", "io", ".", "Pipe", "(", ")", "\n\n", "buf", ":=", "bufio", ".", "NewReader", "(", ...
// newArchiveToGuest returns an hgfs.File implementation to expand a gzip'd tar into a directory.
[ "newArchiveToGuest", "returns", "an", "hgfs", ".", "File", "implementation", "to", "expand", "a", "gzip", "d", "tar", "into", "a", "directory", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/archive.go#L168-L225
train
vmware/govmomi
toolbox/hgfs/archive.go
archiveRead
func archiveRead(u *url.URL, tr *tar.Reader) error { for { header, err := tr.Next() if err != nil { if err == io.EOF { return nil } return err } name := filepath.Join(u.Path, header.Name) mode := os.FileMode(header.Mode) switch header.Typeflag { case tar.TypeDir: err = os.MkdirAll(name,...
go
func archiveRead(u *url.URL, tr *tar.Reader) error { for { header, err := tr.Next() if err != nil { if err == io.EOF { return nil } return err } name := filepath.Join(u.Path, header.Name) mode := os.FileMode(header.Mode) switch header.Typeflag { case tar.TypeDir: err = os.MkdirAll(name,...
[ "func", "archiveRead", "(", "u", "*", "url", ".", "URL", ",", "tr", "*", "tar", ".", "Reader", ")", "error", "{", "for", "{", "header", ",", "err", ":=", "tr", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io...
// archiveRead writes the contents of the given tar.Reader to the given directory.
[ "archiveRead", "writes", "the", "contents", "of", "the", "given", "tar", ".", "Reader", "to", "the", "given", "directory", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/archive.go#L232-L273
train
vmware/govmomi
toolbox/hgfs/archive.go
archiveWrite
func archiveWrite(u *url.URL, tw *tar.Writer) error { info, err := os.Stat(u.Path) if err != nil { return err } // Note that the VMX will trim any trailing slash. For example: // "/foo/bar/?prefix=bar/" will end up here as "/foo/bar/?prefix=bar" // Escape to avoid this: "/for/bar/?prefix=bar%2F" prefix := u....
go
func archiveWrite(u *url.URL, tw *tar.Writer) error { info, err := os.Stat(u.Path) if err != nil { return err } // Note that the VMX will trim any trailing slash. For example: // "/foo/bar/?prefix=bar/" will end up here as "/foo/bar/?prefix=bar" // Escape to avoid this: "/for/bar/?prefix=bar%2F" prefix := u....
[ "func", "archiveWrite", "(", "u", "*", "url", ".", "URL", ",", "tw", "*", "tar", ".", "Writer", ")", "error", "{", "info", ",", "err", ":=", "os", ".", "Stat", "(", "u", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", ...
// archiveWrite writes the contents of the given source directory to the given tar.Writer.
[ "archiveWrite", "writes", "the", "contents", "of", "the", "given", "source", "directory", "to", "the", "given", "tar", ".", "Writer", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/archive.go#L276-L342
train
vmware/govmomi
property/filter.go
MatchProperty
func (f Filter) MatchProperty(prop types.DynamicProperty) bool { match, ok := f[prop.Name] if !ok { return false } if match == prop.Val { return true } ptype := reflect.TypeOf(prop.Val) if strings.HasPrefix(ptype.Name(), "ArrayOf") { pval := reflect.ValueOf(prop.Val).Field(0) for i := 0; i < pval.Len...
go
func (f Filter) MatchProperty(prop types.DynamicProperty) bool { match, ok := f[prop.Name] if !ok { return false } if match == prop.Val { return true } ptype := reflect.TypeOf(prop.Val) if strings.HasPrefix(ptype.Name(), "ArrayOf") { pval := reflect.ValueOf(prop.Val).Field(0) for i := 0; i < pval.Len...
[ "func", "(", "f", "Filter", ")", "MatchProperty", "(", "prop", "types", ".", "DynamicProperty", ")", "bool", "{", "match", ",", "ok", ":=", "f", "[", "prop", ".", "Name", "]", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n\n", "if", ...
// MatchProperty returns true if a Filter entry matches the given prop.
[ "MatchProperty", "returns", "true", "if", "a", "Filter", "entry", "matches", "the", "given", "prop", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/property/filter.go#L44-L115
train
vmware/govmomi
property/filter.go
MatchPropertyList
func (f Filter) MatchPropertyList(props []types.DynamicProperty) bool { for _, p := range props { if !f.MatchProperty(p) { return false } } return len(f) == len(props) // false if a property such as VM "guest" is unset }
go
func (f Filter) MatchPropertyList(props []types.DynamicProperty) bool { for _, p := range props { if !f.MatchProperty(p) { return false } } return len(f) == len(props) // false if a property such as VM "guest" is unset }
[ "func", "(", "f", "Filter", ")", "MatchPropertyList", "(", "props", "[", "]", "types", ".", "DynamicProperty", ")", "bool", "{", "for", "_", ",", "p", ":=", "range", "props", "{", "if", "!", "f", ".", "MatchProperty", "(", "p", ")", "{", "return", ...
// MatchPropertyList returns true if all given props match the Filter.
[ "MatchPropertyList", "returns", "true", "if", "all", "given", "props", "match", "the", "Filter", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/property/filter.go#L118-L126
train
vmware/govmomi
property/filter.go
MatchObjectContent
func (f Filter) MatchObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference { var refs []types.ManagedObjectReference for _, o := range objects { if f.MatchPropertyList(o.PropSet) { refs = append(refs, o.Obj) } } return refs }
go
func (f Filter) MatchObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference { var refs []types.ManagedObjectReference for _, o := range objects { if f.MatchPropertyList(o.PropSet) { refs = append(refs, o.Obj) } } return refs }
[ "func", "(", "f", "Filter", ")", "MatchObjectContent", "(", "objects", "[", "]", "types", ".", "ObjectContent", ")", "[", "]", "types", ".", "ManagedObjectReference", "{", "var", "refs", "[", "]", "types", ".", "ManagedObjectReference", "\n\n", "for", "_", ...
// MatchObjectContent returns a list of ObjectContent.Obj where the ObjectContent.PropSet matches the Filter.
[ "MatchObjectContent", "returns", "a", "list", "of", "ObjectContent", ".", "Obj", "where", "the", "ObjectContent", ".", "PropSet", "matches", "the", "Filter", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/property/filter.go#L129-L139
train
golang/lint
lint.go
Lint
func (l *Linter) Lint(filename string, src []byte) ([]Problem, error) { return l.LintFiles(map[string][]byte{filename: src}) }
go
func (l *Linter) Lint(filename string, src []byte) ([]Problem, error) { return l.LintFiles(map[string][]byte{filename: src}) }
[ "func", "(", "l", "*", "Linter", ")", "Lint", "(", "filename", "string", ",", "src", "[", "]", "byte", ")", "(", "[", "]", "Problem", ",", "error", ")", "{", "return", "l", ".", "LintFiles", "(", "map", "[", "string", "]", "[", "]", "byte", "{"...
// Lint lints src.
[ "Lint", "lints", "src", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L79-L81
train
golang/lint
lint.go
LintFiles
func (l *Linter) LintFiles(files map[string][]byte) ([]Problem, error) { pkg := &pkg{ fset: token.NewFileSet(), files: make(map[string]*file), } var pkgName string for filename, src := range files { if isGenerated(src) { continue // See issue #239 } f, err := parser.ParseFile(pkg.fset, filename, src, ...
go
func (l *Linter) LintFiles(files map[string][]byte) ([]Problem, error) { pkg := &pkg{ fset: token.NewFileSet(), files: make(map[string]*file), } var pkgName string for filename, src := range files { if isGenerated(src) { continue // See issue #239 } f, err := parser.ParseFile(pkg.fset, filename, src, ...
[ "func", "(", "l", "*", "Linter", ")", "LintFiles", "(", "files", "map", "[", "string", "]", "[", "]", "byte", ")", "(", "[", "]", "Problem", ",", "error", ")", "{", "pkg", ":=", "&", "pkg", "{", "fset", ":", "token", ".", "NewFileSet", "(", ")"...
// LintFiles lints a set of files of a single package. // The argument is a map of filename to source.
[ "LintFiles", "lints", "a", "set", "of", "files", "of", "a", "single", "package", ".", "The", "argument", "is", "a", "map", "of", "filename", "to", "source", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L85-L116
train
golang/lint
lint.go
errorf
func (f *file) errorf(n ast.Node, confidence float64, args ...interface{}) *Problem { pos := f.fset.Position(n.Pos()) if pos.Filename == "" { pos.Filename = f.filename } return f.pkg.errorfAt(pos, confidence, args...) }
go
func (f *file) errorf(n ast.Node, confidence float64, args ...interface{}) *Problem { pos := f.fset.Position(n.Pos()) if pos.Filename == "" { pos.Filename = f.filename } return f.pkg.errorfAt(pos, confidence, args...) }
[ "func", "(", "f", "*", "file", ")", "errorf", "(", "n", "ast", ".", "Node", ",", "confidence", "float64", ",", "args", "...", "interface", "{", "}", ")", "*", "Problem", "{", "pos", ":=", "f", ".", "fset", ".", "Position", "(", "n", ".", "Pos", ...
// The variadic arguments may start with link and category types, // and must end with a format string and any arguments. // It returns the new Problem.
[ "The", "variadic", "arguments", "may", "start", "with", "link", "and", "category", "types", "and", "must", "end", "with", "a", "format", "string", "and", "any", "arguments", ".", "It", "returns", "the", "new", "Problem", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L222-L228
train
golang/lint
lint.go
scopeOf
func (p *pkg) scopeOf(id *ast.Ident) *types.Scope { var scope *types.Scope if obj := p.typesInfo.ObjectOf(id); obj != nil { scope = obj.Parent() } if scope == p.typesPkg.Scope() { // We were given a top-level identifier. // Use the file-level scope instead of the package-level scope. pos := id.Pos() for _...
go
func (p *pkg) scopeOf(id *ast.Ident) *types.Scope { var scope *types.Scope if obj := p.typesInfo.ObjectOf(id); obj != nil { scope = obj.Parent() } if scope == p.typesPkg.Scope() { // We were given a top-level identifier. // Use the file-level scope instead of the package-level scope. pos := id.Pos() for _...
[ "func", "(", "p", "*", "pkg", ")", "scopeOf", "(", "id", "*", "ast", ".", "Ident", ")", "*", "types", ".", "Scope", "{", "var", "scope", "*", "types", ".", "Scope", "\n", "if", "obj", ":=", "p", ".", "typesInfo", ".", "ObjectOf", "(", "id", ")"...
// scopeOf returns the tightest scope encompassing id.
[ "scopeOf", "returns", "the", "tightest", "scope", "encompassing", "id", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L308-L325
train
golang/lint
lint.go
lintPackageComment
func (f *file) lintPackageComment() { if f.isTest() { return } const ref = styleGuideBase + "#package-comments" prefix := "Package " + f.f.Name.Name + " " // Look for a detached package comment. // First, scan for the last comment that occurs before the "package" keyword. var lastCG *ast.CommentGroup for _,...
go
func (f *file) lintPackageComment() { if f.isTest() { return } const ref = styleGuideBase + "#package-comments" prefix := "Package " + f.f.Name.Name + " " // Look for a detached package comment. // First, scan for the last comment that occurs before the "package" keyword. var lastCG *ast.CommentGroup for _,...
[ "func", "(", "f", "*", "file", ")", "lintPackageComment", "(", ")", "{", "if", "f", ".", "isTest", "(", ")", "{", "return", "\n", "}", "\n\n", "const", "ref", "=", "styleGuideBase", "+", "\"", "\"", "\n", "prefix", ":=", "\"", "\"", "+", "f", "."...
// lintPackageComment checks package comments. It complains if // there is no package comment, or if it is not of the right form. // This has a notable false positive in that a package comment // could rightfully appear in a different file of the same package, // but that's not easy to fix since this linter is file-ori...
[ "lintPackageComment", "checks", "package", "comments", ".", "It", "complains", "if", "there", "is", "no", "package", "comment", "or", "if", "it", "is", "not", "of", "the", "right", "form", ".", "This", "has", "a", "notable", "false", "positive", "in", "tha...
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L380-L429
train
golang/lint
lint.go
lintBlankImports
func (f *file) lintBlankImports() { // In package main and in tests, we don't complain about blank imports. if f.pkg.main || f.isTest() { return } // The first element of each contiguous group of blank imports should have // an explanatory comment of some kind. for i, imp := range f.f.Imports { pos := f.fset...
go
func (f *file) lintBlankImports() { // In package main and in tests, we don't complain about blank imports. if f.pkg.main || f.isTest() { return } // The first element of each contiguous group of blank imports should have // an explanatory comment of some kind. for i, imp := range f.f.Imports { pos := f.fset...
[ "func", "(", "f", "*", "file", ")", "lintBlankImports", "(", ")", "{", "// In package main and in tests, we don't complain about blank imports.", "if", "f", ".", "pkg", ".", "main", "||", "f", ".", "isTest", "(", ")", "{", "return", "\n", "}", "\n\n", "// The ...
// lintBlankImports complains if a non-main package has blank imports that are // not documented.
[ "lintBlankImports", "complains", "if", "a", "non", "-", "main", "package", "has", "blank", "imports", "that", "are", "not", "documented", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L433-L461
train
golang/lint
lint.go
lintImports
func (f *file) lintImports() { for i, is := range f.f.Imports { _ = i if is.Name != nil && is.Name.Name == "." && !f.isTest() { f.errorf(is, 1, link(styleGuideBase+"#import-dot"), category("imports"), "should not use dot imports") } } }
go
func (f *file) lintImports() { for i, is := range f.f.Imports { _ = i if is.Name != nil && is.Name.Name == "." && !f.isTest() { f.errorf(is, 1, link(styleGuideBase+"#import-dot"), category("imports"), "should not use dot imports") } } }
[ "func", "(", "f", "*", "file", ")", "lintImports", "(", ")", "{", "for", "i", ",", "is", ":=", "range", "f", ".", "f", ".", "Imports", "{", "_", "=", "i", "\n", "if", "is", ".", "Name", "!=", "nil", "&&", "is", ".", "Name", ".", "Name", "==...
// lintImports examines import blocks.
[ "lintImports", "examines", "import", "blocks", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L464-L472
train
golang/lint
lint.go
lintExported
func (f *file) lintExported() { if f.isTest() { return } var lastGen *ast.GenDecl // last GenDecl entered. // Set of GenDecls that have already had missing comments flagged. genDeclMissingComments := make(map[*ast.GenDecl]bool) f.walk(func(node ast.Node) bool { switch v := node.(type) { case *ast.GenDecl...
go
func (f *file) lintExported() { if f.isTest() { return } var lastGen *ast.GenDecl // last GenDecl entered. // Set of GenDecls that have already had missing comments flagged. genDeclMissingComments := make(map[*ast.GenDecl]bool) f.walk(func(node ast.Node) bool { switch v := node.(type) { case *ast.GenDecl...
[ "func", "(", "f", "*", "file", ")", "lintExported", "(", ")", "{", "if", "f", ".", "isTest", "(", ")", "{", "return", "\n", "}", "\n\n", "var", "lastGen", "*", "ast", ".", "GenDecl", "// last GenDecl entered.", "\n\n", "// Set of GenDecls that have already h...
// lintExported examines the exported names. // It complains if any required doc comments are missing, // or if they are not of the right form. The exact rules are in // lintFuncDoc, lintTypeDoc and lintValueSpecDoc; this function // also tracks the GenDecl structure being traversed to permit // doc comments for consta...
[ "lintExported", "examines", "the", "exported", "names", ".", "It", "complains", "if", "any", "required", "doc", "comments", "are", "missing", "or", "if", "they", "are", "not", "of", "the", "right", "form", ".", "The", "exact", "rules", "are", "in", "lintFu...
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L484-L528
train
golang/lint
lint.go
lintTypeDoc
func (f *file) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) { if !ast.IsExported(t.Name.Name) { return } if doc == nil { f.errorf(t, 1, link(docCommentsLink), category("comments"), "exported type %v should have comment or be unexported", t.Name) return } s := doc.Text() articles := [...]string{"A", ...
go
func (f *file) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) { if !ast.IsExported(t.Name.Name) { return } if doc == nil { f.errorf(t, 1, link(docCommentsLink), category("comments"), "exported type %v should have comment or be unexported", t.Name) return } s := doc.Text() articles := [...]string{"A", ...
[ "func", "(", "f", "*", "file", ")", "lintTypeDoc", "(", "t", "*", "ast", ".", "TypeSpec", ",", "doc", "*", "ast", ".", "CommentGroup", ")", "{", "if", "!", "ast", ".", "IsExported", "(", "t", ".", "Name", ".", "Name", ")", "{", "return", "\n", ...
// lintTypeDoc examines the doc comment on a type. // It complains if they are missing from an exported type, // or if they are not of the standard form.
[ "lintTypeDoc", "examines", "the", "doc", "comment", "on", "a", "type", ".", "It", "complains", "if", "they", "are", "missing", "from", "an", "exported", "type", "or", "if", "they", "are", "not", "of", "the", "standard", "form", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L815-L835
train
golang/lint
lint.go
lintVarDecls
func (f *file) lintVarDecls() { var lastGen *ast.GenDecl // last GenDecl entered. f.walk(func(node ast.Node) bool { switch v := node.(type) { case *ast.GenDecl: if v.Tok != token.CONST && v.Tok != token.VAR { return false } lastGen = v return true case *ast.ValueSpec: if lastGen.Tok == token...
go
func (f *file) lintVarDecls() { var lastGen *ast.GenDecl // last GenDecl entered. f.walk(func(node ast.Node) bool { switch v := node.(type) { case *ast.GenDecl: if v.Tok != token.CONST && v.Tok != token.VAR { return false } lastGen = v return true case *ast.ValueSpec: if lastGen.Tok == token...
[ "func", "(", "f", "*", "file", ")", "lintVarDecls", "(", ")", "{", "var", "lastGen", "*", "ast", ".", "GenDecl", "// last GenDecl entered.", "\n\n", "f", ".", "walk", "(", "func", "(", "node", "ast", ".", "Node", ")", "bool", "{", "switch", "v", ":="...
// lintVarDecls examines variable declarations. It complains about declarations with // redundant LHS types that can be inferred from the RHS.
[ "lintVarDecls", "examines", "variable", "declarations", ".", "It", "complains", "about", "declarations", "with", "redundant", "LHS", "types", "that", "can", "be", "inferred", "from", "the", "RHS", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L982-L1050
train
golang/lint
lint.go
lintElses
func (f *file) lintElses() { // We don't want to flag if { } else if { } else { } constructions. // They will appear as an IfStmt whose Else field is also an IfStmt. // Record such a node so we ignore it when we visit it. ignore := make(map[*ast.IfStmt]bool) f.walk(func(node ast.Node) bool { ifStmt, ok := node....
go
func (f *file) lintElses() { // We don't want to flag if { } else if { } else { } constructions. // They will appear as an IfStmt whose Else field is also an IfStmt. // Record such a node so we ignore it when we visit it. ignore := make(map[*ast.IfStmt]bool) f.walk(func(node ast.Node) bool { ifStmt, ok := node....
[ "func", "(", "f", "*", "file", ")", "lintElses", "(", ")", "{", "// We don't want to flag if { } else if { } else { } constructions.", "// They will appear as an IfStmt whose Else field is also an IfStmt.", "// Record such a node so we ignore it when we visit it.", "ignore", ":=", "mak...
// lintElses examines else blocks. It complains about any else block whose if block ends in a return.
[ "lintElses", "examines", "else", "blocks", ".", "It", "complains", "about", "any", "else", "block", "whose", "if", "block", "ends", "in", "a", "return", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1059-L1100
train
golang/lint
lint.go
lintRanges
func (f *file) lintRanges() { f.walk(func(node ast.Node) bool { rs, ok := node.(*ast.RangeStmt) if !ok { return true } if isIdent(rs.Key, "_") && (rs.Value == nil || isIdent(rs.Value, "_")) { p := f.errorf(rs.Key, 1, category("range-loop"), "should omit values from range; this loop is equivalent to `for...
go
func (f *file) lintRanges() { f.walk(func(node ast.Node) bool { rs, ok := node.(*ast.RangeStmt) if !ok { return true } if isIdent(rs.Key, "_") && (rs.Value == nil || isIdent(rs.Value, "_")) { p := f.errorf(rs.Key, 1, category("range-loop"), "should omit values from range; this loop is equivalent to `for...
[ "func", "(", "f", "*", "file", ")", "lintRanges", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "node", "ast", ".", "Node", ")", "bool", "{", "rs", ",", "ok", ":=", "node", ".", "(", "*", "ast", ".", "RangeStmt", ")", "\n", "if", "!", ...
// lintRanges examines range clauses. It complains about redundant constructions.
[ "lintRanges", "examines", "range", "clauses", ".", "It", "complains", "about", "redundant", "constructions", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1103-L1131
train
golang/lint
lint.go
lintErrorf
func (f *file) lintErrorf() { f.walk(func(node ast.Node) bool { ce, ok := node.(*ast.CallExpr) if !ok || len(ce.Args) != 1 { return true } isErrorsNew := isPkgDot(ce.Fun, "errors", "New") var isTestingError bool se, ok := ce.Fun.(*ast.SelectorExpr) if ok && se.Sel.Name == "Error" { if typ := f.pkg....
go
func (f *file) lintErrorf() { f.walk(func(node ast.Node) bool { ce, ok := node.(*ast.CallExpr) if !ok || len(ce.Args) != 1 { return true } isErrorsNew := isPkgDot(ce.Fun, "errors", "New") var isTestingError bool se, ok := ce.Fun.(*ast.SelectorExpr) if ok && se.Sel.Name == "Error" { if typ := f.pkg....
[ "func", "(", "f", "*", "file", ")", "lintErrorf", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "node", "ast", ".", "Node", ")", "bool", "{", "ce", ",", "ok", ":=", "node", ".", "(", "*", "ast", ".", "CallExpr", ")", "\n", "if", "!", "...
// lintErrorf examines errors.New and testing.Error calls. It complains if its only argument is an fmt.Sprintf invocation.
[ "lintErrorf", "examines", "errors", ".", "New", "and", "testing", ".", "Error", "calls", ".", "It", "complains", "if", "its", "only", "argument", "is", "an", "fmt", ".", "Sprintf", "invocation", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1134-L1172
train
golang/lint
lint.go
lintErrors
func (f *file) lintErrors() { for _, decl := range f.f.Decls { gd, ok := decl.(*ast.GenDecl) if !ok || gd.Tok != token.VAR { continue } for _, spec := range gd.Specs { spec := spec.(*ast.ValueSpec) if len(spec.Names) != 1 || len(spec.Values) != 1 { continue } ce, ok := spec.Values[0].(*ast.C...
go
func (f *file) lintErrors() { for _, decl := range f.f.Decls { gd, ok := decl.(*ast.GenDecl) if !ok || gd.Tok != token.VAR { continue } for _, spec := range gd.Specs { spec := spec.(*ast.ValueSpec) if len(spec.Names) != 1 || len(spec.Values) != 1 { continue } ce, ok := spec.Values[0].(*ast.C...
[ "func", "(", "f", "*", "file", ")", "lintErrors", "(", ")", "{", "for", "_", ",", "decl", ":=", "range", "f", ".", "f", ".", "Decls", "{", "gd", ",", "ok", ":=", "decl", ".", "(", "*", "ast", ".", "GenDecl", ")", "\n", "if", "!", "ok", "||"...
// lintErrors examines global error vars. It complains if they aren't named in the standard way.
[ "lintErrors", "examines", "global", "error", "vars", ".", "It", "complains", "if", "they", "aren", "t", "named", "in", "the", "standard", "way", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1175-L1204
train
golang/lint
lint.go
lintErrorStrings
func (f *file) lintErrorStrings() { f.walk(func(node ast.Node) bool { ce, ok := node.(*ast.CallExpr) if !ok { return true } if !isPkgDot(ce.Fun, "errors", "New") && !isPkgDot(ce.Fun, "fmt", "Errorf") { return true } if len(ce.Args) < 1 { return true } str, ok := ce.Args[0].(*ast.BasicLit) if...
go
func (f *file) lintErrorStrings() { f.walk(func(node ast.Node) bool { ce, ok := node.(*ast.CallExpr) if !ok { return true } if !isPkgDot(ce.Fun, "errors", "New") && !isPkgDot(ce.Fun, "fmt", "Errorf") { return true } if len(ce.Args) < 1 { return true } str, ok := ce.Args[0].(*ast.BasicLit) if...
[ "func", "(", "f", "*", "file", ")", "lintErrorStrings", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "node", "ast", ".", "Node", ")", "bool", "{", "ce", ",", "ok", ":=", "node", ".", "(", "*", "ast", ".", "CallExpr", ")", "\n", "if", "!...
// lintErrorStrings examines error strings. // It complains if they are capitalized or end in punctuation or a newline.
[ "lintErrorStrings", "examines", "error", "strings", ".", "It", "complains", "if", "they", "are", "capitalized", "or", "end", "in", "punctuation", "or", "a", "newline", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1230-L1259
train
golang/lint
lint.go
lintReceiverNames
func (f *file) lintReceiverNames() { typeReceiver := map[string]string{} f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || fn.Recv == nil || len(fn.Recv.List) == 0 { return true } names := fn.Recv.List[0].Names if len(names) < 1 { return true } name := names[0].Name const ref ...
go
func (f *file) lintReceiverNames() { typeReceiver := map[string]string{} f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || fn.Recv == nil || len(fn.Recv.List) == 0 { return true } names := fn.Recv.List[0].Names if len(names) < 1 { return true } name := names[0].Name const ref ...
[ "func", "(", "f", "*", "file", ")", "lintReceiverNames", "(", ")", "{", "typeReceiver", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "f", ".", "walk", "(", "func", "(", "n", "ast", ".", "Node", ")", "bool", "{", "fn", ",", "ok", "...
// lintReceiverNames examines receiver names. It complains about inconsistent // names used for the same type and names such as "this".
[ "lintReceiverNames", "examines", "receiver", "names", ".", "It", "complains", "about", "inconsistent", "names", "used", "for", "the", "same", "type", "and", "names", "such", "as", "this", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1263-L1292
train
golang/lint
lint.go
lintErrorReturn
func (f *file) lintErrorReturn() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || fn.Type.Results == nil { return true } ret := fn.Type.Results.List if len(ret) <= 1 { return true } if isIdent(ret[len(ret)-1].Type, "error") { return true } // An error return parameter s...
go
func (f *file) lintErrorReturn() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || fn.Type.Results == nil { return true } ret := fn.Type.Results.List if len(ret) <= 1 { return true } if isIdent(ret[len(ret)-1].Type, "error") { return true } // An error return parameter s...
[ "func", "(", "f", "*", "file", ")", "lintErrorReturn", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "n", "ast", ".", "Node", ")", "bool", "{", "fn", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "FuncDecl", ")", "\n", "if", "!", "o...
// lintErrorReturn examines function declarations that return an error. // It complains if the error isn't the last parameter.
[ "lintErrorReturn", "examines", "function", "declarations", "that", "return", "an", "error", ".", "It", "complains", "if", "the", "error", "isn", "t", "the", "last", "parameter", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1324-L1347
train
golang/lint
lint.go
lintUnexportedReturn
func (f *file) lintUnexportedReturn() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok { return true } if fn.Type.Results == nil { return false } if !fn.Name.IsExported() { return false } thing := "func" if fn.Recv != nil && len(fn.Recv.List) > 0 { thing = "method" i...
go
func (f *file) lintUnexportedReturn() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok { return true } if fn.Type.Results == nil { return false } if !fn.Name.IsExported() { return false } thing := "func" if fn.Recv != nil && len(fn.Recv.List) > 0 { thing = "method" i...
[ "func", "(", "f", "*", "file", ")", "lintUnexportedReturn", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "n", "ast", ".", "Node", ")", "bool", "{", "fn", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "FuncDecl", ")", "\n", "if", "!",...
// lintUnexportedReturn examines exported function declarations. // It complains if any return an unexported type.
[ "lintUnexportedReturn", "examines", "exported", "function", "declarations", ".", "It", "complains", "if", "any", "return", "an", "unexported", "type", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1351-L1384
train
golang/lint
lint.go
exportedType
func exportedType(typ types.Type) bool { switch T := typ.(type) { case *types.Named: // Builtin types have no package. return T.Obj().Pkg() == nil || T.Obj().Exported() case *types.Map: return exportedType(T.Key()) && exportedType(T.Elem()) case interface { Elem() types.Type }: // array, slice, pointer, ch...
go
func exportedType(typ types.Type) bool { switch T := typ.(type) { case *types.Named: // Builtin types have no package. return T.Obj().Pkg() == nil || T.Obj().Exported() case *types.Map: return exportedType(T.Key()) && exportedType(T.Elem()) case interface { Elem() types.Type }: // array, slice, pointer, ch...
[ "func", "exportedType", "(", "typ", "types", ".", "Type", ")", "bool", "{", "switch", "T", ":=", "typ", ".", "(", "type", ")", "{", "case", "*", "types", ".", "Named", ":", "// Builtin types have no package.", "return", "T", ".", "Obj", "(", ")", ".", ...
// exportedType reports whether typ is an exported type. // It is imprecise, and will err on the side of returning true, // such as for composite types.
[ "exportedType", "reports", "whether", "typ", "is", "an", "exported", "type", ".", "It", "is", "imprecise", "and", "will", "err", "on", "the", "side", "of", "returning", "true", "such", "as", "for", "composite", "types", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1389-L1403
train
golang/lint
lint.go
checkContextKeyType
func (f *file) checkContextKeyType(x *ast.CallExpr) { sel, ok := x.Fun.(*ast.SelectorExpr) if !ok { return } pkg, ok := sel.X.(*ast.Ident) if !ok || pkg.Name != "context" { return } if sel.Sel.Name != "WithValue" { return } // key is second argument to context.WithValue if len(x.Args) != 3 { return ...
go
func (f *file) checkContextKeyType(x *ast.CallExpr) { sel, ok := x.Fun.(*ast.SelectorExpr) if !ok { return } pkg, ok := sel.X.(*ast.Ident) if !ok || pkg.Name != "context" { return } if sel.Sel.Name != "WithValue" { return } // key is second argument to context.WithValue if len(x.Args) != 3 { return ...
[ "func", "(", "f", "*", "file", ")", "checkContextKeyType", "(", "x", "*", "ast", ".", "CallExpr", ")", "{", "sel", ",", "ok", ":=", "x", ".", "Fun", ".", "(", "*", "ast", ".", "SelectorExpr", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}"...
// checkContextKeyType reports an error if the call expression calls // context.WithValue with a key argument of basic type.
[ "checkContextKeyType", "reports", "an", "error", "if", "the", "call", "expression", "calls", "context", ".", "WithValue", "with", "a", "key", "argument", "of", "basic", "type", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1464-L1486
train
golang/lint
lint.go
lintContextArgs
func (f *file) lintContextArgs() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || len(fn.Type.Params.List) <= 1 { return true } // A context.Context should be the first parameter of a function. // Flag any that show up after the first. for _, arg := range fn.Type.Params.List[1:] { ...
go
func (f *file) lintContextArgs() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || len(fn.Type.Params.List) <= 1 { return true } // A context.Context should be the first parameter of a function. // Flag any that show up after the first. for _, arg := range fn.Type.Params.List[1:] { ...
[ "func", "(", "f", "*", "file", ")", "lintContextArgs", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "n", "ast", ".", "Node", ")", "bool", "{", "fn", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "FuncDecl", ")", "\n", "if", "!", "o...
// lintContextArgs examines function declarations that contain an // argument with a type of context.Context // It complains if that argument isn't the first parameter.
[ "lintContextArgs", "examines", "function", "declarations", "that", "contain", "an", "argument", "with", "a", "type", "of", "context", ".", "Context", "It", "complains", "if", "that", "argument", "isn", "t", "the", "first", "parameter", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1491-L1507
train
golang/lint
lint.go
isUntypedConst
func (f *file) isUntypedConst(expr ast.Expr) (defType string, ok bool) { // Re-evaluate expr outside of its context to see if it's untyped. // (An expr evaluated within, for example, an assignment context will get the type of the LHS.) exprStr := f.render(expr) tv, err := types.Eval(f.fset, f.pkg.typesPkg, expr.Pos...
go
func (f *file) isUntypedConst(expr ast.Expr) (defType string, ok bool) { // Re-evaluate expr outside of its context to see if it's untyped. // (An expr evaluated within, for example, an assignment context will get the type of the LHS.) exprStr := f.render(expr) tv, err := types.Eval(f.fset, f.pkg.typesPkg, expr.Pos...
[ "func", "(", "f", "*", "file", ")", "isUntypedConst", "(", "expr", "ast", ".", "Expr", ")", "(", "defType", "string", ",", "ok", "bool", ")", "{", "// Re-evaluate expr outside of its context to see if it's untyped.", "// (An expr evaluated within, for example, an assignme...
// isUntypedConst reports whether expr is an untyped constant, // and indicates what its default type is. // scope may be nil.
[ "isUntypedConst", "reports", "whether", "expr", "is", "an", "untyped", "constant", "and", "indicates", "what", "its", "default", "type", "is", ".", "scope", "may", "be", "nil", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1622-L1637
train
golang/lint
lint.go
firstLineOf
func (f *file) firstLineOf(node, match ast.Node) string { line := f.render(node) if i := strings.Index(line, "\n"); i >= 0 { line = line[:i] } return f.indentOf(match) + line }
go
func (f *file) firstLineOf(node, match ast.Node) string { line := f.render(node) if i := strings.Index(line, "\n"); i >= 0 { line = line[:i] } return f.indentOf(match) + line }
[ "func", "(", "f", "*", "file", ")", "firstLineOf", "(", "node", ",", "match", "ast", ".", "Node", ")", "string", "{", "line", ":=", "f", ".", "render", "(", "node", ")", "\n", "if", "i", ":=", "strings", ".", "Index", "(", "line", ",", "\"", "\...
// firstLineOf renders the given node and returns its first line. // It will also match the indentation of another node.
[ "firstLineOf", "renders", "the", "given", "node", "and", "returns", "its", "first", "line", ".", "It", "will", "also", "match", "the", "indentation", "of", "another", "node", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1641-L1647
train
golang/lint
lint.go
imports
func (f *file) imports(importPath string) bool { all := astutil.Imports(f.fset, f.f) for _, p := range all { for _, i := range p { uq, err := strconv.Unquote(i.Path.Value) if err == nil && importPath == uq { return true } } } return false }
go
func (f *file) imports(importPath string) bool { all := astutil.Imports(f.fset, f.f) for _, p := range all { for _, i := range p { uq, err := strconv.Unquote(i.Path.Value) if err == nil && importPath == uq { return true } } } return false }
[ "func", "(", "f", "*", "file", ")", "imports", "(", "importPath", "string", ")", "bool", "{", "all", ":=", "astutil", ".", "Imports", "(", "f", ".", "fset", ",", "f", ".", "f", ")", "\n", "for", "_", ",", "p", ":=", "range", "all", "{", "for", ...
// imports returns true if the current file imports the specified package path.
[ "imports", "returns", "true", "if", "the", "current", "file", "imports", "the", "specified", "package", "path", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1669-L1680
train
golang/lint
lint.go
srcLine
func srcLine(src []byte, p token.Position) string { // Run to end of line in both directions if not at line start/end. lo, hi := p.Offset, p.Offset+1 for lo > 0 && src[lo-1] != '\n' { lo-- } for hi < len(src) && src[hi-1] != '\n' { hi++ } return string(src[lo:hi]) }
go
func srcLine(src []byte, p token.Position) string { // Run to end of line in both directions if not at line start/end. lo, hi := p.Offset, p.Offset+1 for lo > 0 && src[lo-1] != '\n' { lo-- } for hi < len(src) && src[hi-1] != '\n' { hi++ } return string(src[lo:hi]) }
[ "func", "srcLine", "(", "src", "[", "]", "byte", ",", "p", "token", ".", "Position", ")", "string", "{", "// Run to end of line in both directions if not at line start/end.", "lo", ",", "hi", ":=", "p", ".", "Offset", ",", "p", ".", "Offset", "+", "1", "\n",...
// srcLine returns the complete line at p, including the terminating newline.
[ "srcLine", "returns", "the", "complete", "line", "at", "p", "including", "the", "terminating", "newline", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1683-L1693
train
golang/lint
golint/import.go
importPaths
func importPaths(args []string) []string { args = importPathsNoDotExpansion(args) var out []string for _, a := range args { if strings.Contains(a, "...") { if build.IsLocalImport(a) { out = append(out, allPackagesInFS(a)...) } else { out = append(out, allPackages(a)...) } continue } out = a...
go
func importPaths(args []string) []string { args = importPathsNoDotExpansion(args) var out []string for _, a := range args { if strings.Contains(a, "...") { if build.IsLocalImport(a) { out = append(out, allPackagesInFS(a)...) } else { out = append(out, allPackages(a)...) } continue } out = a...
[ "func", "importPaths", "(", "args", "[", "]", "string", ")", "[", "]", "string", "{", "args", "=", "importPathsNoDotExpansion", "(", "args", ")", "\n", "var", "out", "[", "]", "string", "\n", "for", "_", ",", "a", ":=", "range", "args", "{", "if", ...
// importPaths returns the import paths to use for the given command line.
[ "importPaths", "returns", "the", "import", "paths", "to", "use", "for", "the", "given", "command", "line", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/golint/import.go#L65-L80
train
golang/lint
golint/import.go
hasPathPrefix
func hasPathPrefix(s, prefix string) bool { switch { default: return false case len(s) == len(prefix): return s == prefix case len(s) > len(prefix): if prefix != "" && prefix[len(prefix)-1] == '/' { return strings.HasPrefix(s, prefix) } return s[len(prefix)] == '/' && s[:len(prefix)] == prefix } }
go
func hasPathPrefix(s, prefix string) bool { switch { default: return false case len(s) == len(prefix): return s == prefix case len(s) > len(prefix): if prefix != "" && prefix[len(prefix)-1] == '/' { return strings.HasPrefix(s, prefix) } return s[len(prefix)] == '/' && s[:len(prefix)] == prefix } }
[ "func", "hasPathPrefix", "(", "s", ",", "prefix", "string", ")", "bool", "{", "switch", "{", "default", ":", "return", "false", "\n", "case", "len", "(", "s", ")", "==", "len", "(", "prefix", ")", ":", "return", "s", "==", "prefix", "\n", "case", "...
// hasPathPrefix reports whether the path s begins with the // elements in prefix.
[ "hasPathPrefix", "reports", "whether", "the", "path", "s", "begins", "with", "the", "elements", "in", "prefix", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/golint/import.go#L101-L113
train
hashicorp/go-plugin
grpc_client.go
newGRPCClient
func newGRPCClient(doneCtx context.Context, c *Client) (*GRPCClient, error) { conn, err := dialGRPCConn(c.config.TLSConfig, c.dialer) if err != nil { return nil, err } // Start the broker. brokerGRPCClient := newGRPCBrokerClient(conn) broker := newGRPCBroker(brokerGRPCClient, c.config.TLSConfig) go broker.Run...
go
func newGRPCClient(doneCtx context.Context, c *Client) (*GRPCClient, error) { conn, err := dialGRPCConn(c.config.TLSConfig, c.dialer) if err != nil { return nil, err } // Start the broker. brokerGRPCClient := newGRPCBrokerClient(conn) broker := newGRPCBroker(brokerGRPCClient, c.config.TLSConfig) go broker.Run...
[ "func", "newGRPCClient", "(", "doneCtx", "context", ".", "Context", ",", "c", "*", "Client", ")", "(", "*", "GRPCClient", ",", "error", ")", "{", "conn", ",", "err", ":=", "dialGRPCConn", "(", "c", ".", "config", ".", "TLSConfig", ",", "c", ".", "dia...
// newGRPCClient creates a new GRPCClient. The Client argument is expected // to be successfully started already with a lock held.
[ "newGRPCClient", "creates", "a", "new", "GRPCClient", ".", "The", "Client", "argument", "is", "expected", "to", "be", "successfully", "started", "already", "with", "a", "lock", "held", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_client.go#L47-L68
train
hashicorp/go-plugin
server_mux.go
ServeMux
func ServeMux(m ServeMuxMap) { if len(os.Args) != 2 { fmt.Fprintf(os.Stderr, "Invoked improperly. This is an internal command that shouldn't\n"+ "be manually invoked.\n") os.Exit(1) } opts, ok := m[os.Args[1]] if !ok { fmt.Fprintf(os.Stderr, "Unknown plugin: %s\n", os.Args[1]) os.Exit(1) } Serve(...
go
func ServeMux(m ServeMuxMap) { if len(os.Args) != 2 { fmt.Fprintf(os.Stderr, "Invoked improperly. This is an internal command that shouldn't\n"+ "be manually invoked.\n") os.Exit(1) } opts, ok := m[os.Args[1]] if !ok { fmt.Fprintf(os.Stderr, "Unknown plugin: %s\n", os.Args[1]) os.Exit(1) } Serve(...
[ "func", "ServeMux", "(", "m", "ServeMuxMap", ")", "{", "if", "len", "(", "os", ".", "Args", ")", "!=", "2", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", "+", "\"", "\\n", "\"", ")", "\n", "os", ".", "Exit", "(...
// ServeMux is like Serve, but serves multiple types of plugins determined // by the argument given on the command-line. // // This command doesn't return until the plugin is done being executed. Any // errors are logged or output to stderr.
[ "ServeMux", "is", "like", "Serve", "but", "serves", "multiple", "types", "of", "plugins", "determined", "by", "the", "argument", "given", "on", "the", "command", "-", "line", ".", "This", "command", "doesn", "t", "return", "until", "the", "plugin", "is", "...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/server_mux.go#L16-L31
train
hashicorp/go-plugin
grpc_broker.go
Recv
func (s *gRPCBrokerServer) Recv() (*plugin.ConnInfo, error) { select { case <-s.quit: return nil, errors.New("broker closed") case i := <-s.recv: return i, nil } }
go
func (s *gRPCBrokerServer) Recv() (*plugin.ConnInfo, error) { select { case <-s.quit: return nil, errors.New("broker closed") case i := <-s.recv: return i, nil } }
[ "func", "(", "s", "*", "gRPCBrokerServer", ")", "Recv", "(", ")", "(", "*", "plugin", ".", "ConnInfo", ",", "error", ")", "{", "select", "{", "case", "<-", "s", ".", "quit", ":", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", ...
// Recv is used by the GRPCBroker to pass connection information that has been // sent from the client from the stream to the broker.
[ "Recv", "is", "used", "by", "the", "GRPCBroker", "to", "pass", "connection", "information", "that", "has", "been", "sent", "from", "the", "client", "from", "the", "stream", "to", "the", "broker", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_broker.go#L120-L127
train
hashicorp/go-plugin
grpc_broker.go
Send
func (s *gRPCBrokerClientImpl) Send(i *plugin.ConnInfo) error { ch := make(chan error) defer close(ch) select { case <-s.quit: return errors.New("broker closed") case s.send <- &sendErr{ i: i, ch: ch, }: } return <-ch }
go
func (s *gRPCBrokerClientImpl) Send(i *plugin.ConnInfo) error { ch := make(chan error) defer close(ch) select { case <-s.quit: return errors.New("broker closed") case s.send <- &sendErr{ i: i, ch: ch, }: } return <-ch }
[ "func", "(", "s", "*", "gRPCBrokerClientImpl", ")", "Send", "(", "i", "*", "plugin", ".", "ConnInfo", ")", "error", "{", "ch", ":=", "make", "(", "chan", "error", ")", "\n", "defer", "close", "(", "ch", ")", "\n\n", "select", "{", "case", "<-", "s"...
// Send is used by the GRPCBroker to pass connection information into the stream // to the plugin.
[ "Send", "is", "used", "by", "the", "GRPCBroker", "to", "pass", "connection", "information", "into", "the", "stream", "to", "the", "plugin", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_broker.go#L212-L226
train
hashicorp/go-plugin
grpc_broker.go
AcceptAndServe
func (b *GRPCBroker) AcceptAndServe(id uint32, s func([]grpc.ServerOption) *grpc.Server) { listener, err := b.Accept(id) if err != nil { log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err) return } defer listener.Close() var opts []grpc.ServerOption if b.tls != nil { opts = []grpc.ServerOption...
go
func (b *GRPCBroker) AcceptAndServe(id uint32, s func([]grpc.ServerOption) *grpc.Server) { listener, err := b.Accept(id) if err != nil { log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err) return } defer listener.Close() var opts []grpc.ServerOption if b.tls != nil { opts = []grpc.ServerOption...
[ "func", "(", "b", "*", "GRPCBroker", ")", "AcceptAndServe", "(", "id", "uint32", ",", "s", "func", "(", "[", "]", "grpc", ".", "ServerOption", ")", "*", "grpc", ".", "Server", ")", "{", "listener", ",", "err", ":=", "b", ".", "Accept", "(", "id", ...
// AcceptAndServe is used to accept a specific stream ID and immediately // serve a gRPC server on that stream ID. This is used to easily serve // complex arguments. Each AcceptAndServe call opens a new listener socket and // sends the connection info down the stream to the dialer. Since a new // connection is opened e...
[ "AcceptAndServe", "is", "used", "to", "accept", "a", "specific", "stream", "ID", "and", "immediately", "serve", "a", "gRPC", "server", "on", "that", "stream", "ID", ".", "This", "is", "used", "to", "easily", "serve", "complex", "arguments", ".", "Each", "A...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_broker.go#L312-L355
train
hashicorp/go-plugin
grpc_broker.go
Close
func (b *GRPCBroker) Close() error { b.streamer.Close() b.o.Do(func() { close(b.doneCh) }) return nil }
go
func (b *GRPCBroker) Close() error { b.streamer.Close() b.o.Do(func() { close(b.doneCh) }) return nil }
[ "func", "(", "b", "*", "GRPCBroker", ")", "Close", "(", ")", "error", "{", "b", ".", "streamer", ".", "Close", "(", ")", "\n", "b", ".", "o", ".", "Do", "(", "func", "(", ")", "{", "close", "(", "b", ".", "doneCh", ")", "\n", "}", ")", "\n"...
// Close closes the stream and all servers.
[ "Close", "closes", "the", "stream", "and", "all", "servers", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_broker.go#L358-L364
train
hashicorp/go-plugin
log_entry.go
parseJSON
func parseJSON(input []byte) (*logEntry, error) { var raw map[string]interface{} entry := &logEntry{} err := json.Unmarshal(input, &raw) if err != nil { return nil, err } // Parse hclog-specific objects if v, ok := raw["@message"]; ok { entry.Message = v.(string) delete(raw, "@message") } if v, ok := ...
go
func parseJSON(input []byte) (*logEntry, error) { var raw map[string]interface{} entry := &logEntry{} err := json.Unmarshal(input, &raw) if err != nil { return nil, err } // Parse hclog-specific objects if v, ok := raw["@message"]; ok { entry.Message = v.(string) delete(raw, "@message") } if v, ok := ...
[ "func", "parseJSON", "(", "input", "[", "]", "byte", ")", "(", "*", "logEntry", ",", "error", ")", "{", "var", "raw", "map", "[", "string", "]", "interface", "{", "}", "\n", "entry", ":=", "&", "logEntry", "{", "}", "\n\n", "err", ":=", "json", "...
// parseJSON handles parsing JSON output
[ "parseJSON", "handles", "parsing", "JSON", "output" ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/log_entry.go#L35-L73
train
hashicorp/go-plugin
client.go
Check
func (s *SecureConfig) Check(filePath string) (bool, error) { if len(s.Checksum) == 0 { return false, ErrSecureConfigNoChecksum } if s.Hash == nil { return false, ErrSecureConfigNoHash } file, err := os.Open(filePath) if err != nil { return false, err } defer file.Close() _, err = io.Copy(s.Hash, file...
go
func (s *SecureConfig) Check(filePath string) (bool, error) { if len(s.Checksum) == 0 { return false, ErrSecureConfigNoChecksum } if s.Hash == nil { return false, ErrSecureConfigNoHash } file, err := os.Open(filePath) if err != nil { return false, err } defer file.Close() _, err = io.Copy(s.Hash, file...
[ "func", "(", "s", "*", "SecureConfig", ")", "Check", "(", "filePath", "string", ")", "(", "bool", ",", "error", ")", "{", "if", "len", "(", "s", ".", "Checksum", ")", "==", "0", "{", "return", "false", ",", "ErrSecureConfigNoChecksum", "\n", "}", "\n...
// Check takes the filepath to an executable and returns true if the checksum of // the file matches the checksum provided in the SecureConfig.
[ "Check", "takes", "the", "filepath", "to", "an", "executable", "and", "returns", "true", "if", "the", "checksum", "of", "the", "file", "matches", "the", "checksum", "provided", "in", "the", "SecureConfig", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L233-L256
train
hashicorp/go-plugin
client.go
Client
func (c *Client) Client() (ClientProtocol, error) { _, err := c.Start() if err != nil { return nil, err } c.l.Lock() defer c.l.Unlock() if c.client != nil { return c.client, nil } switch c.protocol { case ProtocolNetRPC: c.client, err = newRPCClient(c) case ProtocolGRPC: c.client, err = newGRPCCli...
go
func (c *Client) Client() (ClientProtocol, error) { _, err := c.Start() if err != nil { return nil, err } c.l.Lock() defer c.l.Unlock() if c.client != nil { return c.client, nil } switch c.protocol { case ProtocolNetRPC: c.client, err = newRPCClient(c) case ProtocolGRPC: c.client, err = newGRPCCli...
[ "func", "(", "c", "*", "Client", ")", "Client", "(", ")", "(", "ClientProtocol", ",", "error", ")", "{", "_", ",", "err", ":=", "c", ".", "Start", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", ...
// Client returns the protocol client for this connection. // // Subsequent calls to this will return the same client.
[ "Client", "returns", "the", "protocol", "client", "for", "this", "connection", ".", "Subsequent", "calls", "to", "this", "will", "return", "the", "same", "client", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L340-L370
train
hashicorp/go-plugin
client.go
killed
func (c *Client) killed() bool { c.l.Lock() defer c.l.Unlock() return c.processKilled }
go
func (c *Client) killed() bool { c.l.Lock() defer c.l.Unlock() return c.processKilled }
[ "func", "(", "c", "*", "Client", ")", "killed", "(", ")", "bool", "{", "c", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "l", ".", "Unlock", "(", ")", "\n", "return", "c", ".", "processKilled", "\n", "}" ]
// killed is used in tests to check if a process failed to exit gracefully, and // needed to be killed.
[ "killed", "is", "used", "in", "tests", "to", "check", "if", "a", "process", "failed", "to", "exit", "gracefully", "and", "needed", "to", "be", "killed", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L381-L385
train
hashicorp/go-plugin
client.go
loadServerCert
func (c *Client) loadServerCert(cert string) error { certPool := x509.NewCertPool() asn1, err := base64.RawStdEncoding.DecodeString(cert) if err != nil { return err } x509Cert, err := x509.ParseCertificate([]byte(asn1)) if err != nil { return err } certPool.AddCert(x509Cert) c.config.TLSConfig.RootCAs ...
go
func (c *Client) loadServerCert(cert string) error { certPool := x509.NewCertPool() asn1, err := base64.RawStdEncoding.DecodeString(cert) if err != nil { return err } x509Cert, err := x509.ParseCertificate([]byte(asn1)) if err != nil { return err } certPool.AddCert(x509Cert) c.config.TLSConfig.RootCAs ...
[ "func", "(", "c", "*", "Client", ")", "loadServerCert", "(", "cert", "string", ")", "error", "{", "certPool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n\n", "asn1", ",", "err", ":=", "base64", ".", "RawStdEncoding", ".", "DecodeString", "(", "cert",...
// loadServerCert is used by AutoMTLS to read an x.509 cert returned by the // server, and load it as the RootCA for the client TLSConfig.
[ "loadServerCert", "is", "used", "by", "AutoMTLS", "to", "read", "an", "x", ".", "509", "cert", "returned", "by", "the", "server", "and", "load", "it", "as", "the", "RootCA", "for", "the", "client", "TLSConfig", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L759-L776
train
hashicorp/go-plugin
client.go
checkProtoVersion
func (c *Client) checkProtoVersion(protoVersion string) (int, PluginSet, error) { serverVersion, err := strconv.Atoi(protoVersion) if err != nil { return 0, nil, fmt.Errorf("Error parsing protocol version %q: %s", protoVersion, err) } // record these for the error message var clientVersions []int // all versi...
go
func (c *Client) checkProtoVersion(protoVersion string) (int, PluginSet, error) { serverVersion, err := strconv.Atoi(protoVersion) if err != nil { return 0, nil, fmt.Errorf("Error parsing protocol version %q: %s", protoVersion, err) } // record these for the error message var clientVersions []int // all versi...
[ "func", "(", "c", "*", "Client", ")", "checkProtoVersion", "(", "protoVersion", "string", ")", "(", "int", ",", "PluginSet", ",", "error", ")", "{", "serverVersion", ",", "err", ":=", "strconv", ".", "Atoi", "(", "protoVersion", ")", "\n", "if", "err", ...
// checkProtoVersion returns the negotiated version and PluginSet. // This returns an error if the server returned an incompatible protocol // version, or an invalid handshake response.
[ "checkProtoVersion", "returns", "the", "negotiated", "version", "and", "PluginSet", ".", "This", "returns", "an", "error", "if", "the", "server", "returned", "an", "incompatible", "protocol", "version", "or", "an", "invalid", "handshake", "response", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L834-L856
train
hashicorp/go-plugin
client.go
ReattachConfig
func (c *Client) ReattachConfig() *ReattachConfig { c.l.Lock() defer c.l.Unlock() if c.address == nil { return nil } if c.config.Cmd != nil && c.config.Cmd.Process == nil { return nil } // If we connected via reattach, just return the information as-is if c.config.Reattach != nil { return c.config.Reat...
go
func (c *Client) ReattachConfig() *ReattachConfig { c.l.Lock() defer c.l.Unlock() if c.address == nil { return nil } if c.config.Cmd != nil && c.config.Cmd.Process == nil { return nil } // If we connected via reattach, just return the information as-is if c.config.Reattach != nil { return c.config.Reat...
[ "func", "(", "c", "*", "Client", ")", "ReattachConfig", "(", ")", "*", "ReattachConfig", "{", "c", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "l", ".", "Unlock", "(", ")", "\n\n", "if", "c", ".", "address", "==", "nil", "{", "ret...
// ReattachConfig returns the information that must be provided to NewClient // to reattach to the plugin process that this client started. This is // useful for plugins that detach from their parent process. // // If this returns nil then the process hasn't been started yet. Please // call Start or Client before calli...
[ "ReattachConfig", "returns", "the", "information", "that", "must", "be", "provided", "to", "NewClient", "to", "reattach", "to", "the", "plugin", "process", "that", "this", "client", "started", ".", "This", "is", "useful", "for", "plugins", "that", "detach", "f...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L864-L886
train
hashicorp/go-plugin
client.go
Protocol
func (c *Client) Protocol() Protocol { _, err := c.Start() if err != nil { return ProtocolInvalid } return c.protocol }
go
func (c *Client) Protocol() Protocol { _, err := c.Start() if err != nil { return ProtocolInvalid } return c.protocol }
[ "func", "(", "c", "*", "Client", ")", "Protocol", "(", ")", "Protocol", "{", "_", ",", "err", ":=", "c", ".", "Start", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ProtocolInvalid", "\n", "}", "\n\n", "return", "c", ".", "protocol", ...
// Protocol returns the protocol of server on the remote end. This will // start the plugin process if it isn't already started. Errors from // starting the plugin are surpressed and ProtocolInvalid is returned. It // is recommended you call Start explicitly before calling Protocol to ensure // no errors occur.
[ "Protocol", "returns", "the", "protocol", "of", "server", "on", "the", "remote", "end", ".", "This", "will", "start", "the", "plugin", "process", "if", "it", "isn", "t", "already", "started", ".", "Errors", "from", "starting", "the", "plugin", "are", "surp...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L893-L900
train
hashicorp/go-plugin
client.go
dialer
func (c *Client) dialer(_ string, timeout time.Duration) (net.Conn, error) { conn, err := netAddrDialer(c.address)("", timeout) if err != nil { return nil, err } // If we have a TLS config we wrap our connection. We only do this // for net/rpc since gRPC uses its own mechanism for TLS. if c.protocol == Protoco...
go
func (c *Client) dialer(_ string, timeout time.Duration) (net.Conn, error) { conn, err := netAddrDialer(c.address)("", timeout) if err != nil { return nil, err } // If we have a TLS config we wrap our connection. We only do this // for net/rpc since gRPC uses its own mechanism for TLS. if c.protocol == Protoco...
[ "func", "(", "c", "*", "Client", ")", "dialer", "(", "_", "string", ",", "timeout", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "conn", ",", "err", ":=", "netAddrDialer", "(", "c", ".", "address", ")", "(", "\""...
// dialer is compatible with grpc.WithDialer and creates the connection // to the plugin.
[ "dialer", "is", "compatible", "with", "grpc", ".", "WithDialer", "and", "creates", "the", "connection", "to", "the", "plugin", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L920-L933
train
hashicorp/go-plugin
mtls.go
generateCert
func generateCert() (cert []byte, privateKey []byte, err error) { key, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) if err != nil { return nil, nil, err } serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) sn, err := rand.Int(rand.Reader, serialNumberLimit) if err != nil { return nil, nil, e...
go
func generateCert() (cert []byte, privateKey []byte, err error) { key, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) if err != nil { return nil, nil, err } serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) sn, err := rand.Int(rand.Reader, serialNumberLimit) if err != nil { return nil, nil, e...
[ "func", "generateCert", "(", ")", "(", "cert", "[", "]", "byte", ",", "privateKey", "[", "]", "byte", ",", "err", "error", ")", "{", "key", ",", "err", ":=", "ecdsa", ".", "GenerateKey", "(", "elliptic", ".", "P521", "(", ")", ",", "rand", ".", "...
// generateCert generates a temporary certificate for plugin authentication. The // certificate and private key are returns in PEM format.
[ "generateCert", "generates", "a", "temporary", "certificate", "for", "plugin", "authentication", ".", "The", "certificate", "and", "private", "key", "are", "returns", "in", "PEM", "format", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/mtls.go#L17-L73
train
hashicorp/go-plugin
process_windows.go
_pidAlive
func _pidAlive(pid int) bool { h, err := syscall.OpenProcess(processDesiredAccess, false, uint32(pid)) if err != nil { return false } var ec uint32 if e := syscall.GetExitCodeProcess(h, &ec); e != nil { return false } return ec == exit_STILL_ACTIVE }
go
func _pidAlive(pid int) bool { h, err := syscall.OpenProcess(processDesiredAccess, false, uint32(pid)) if err != nil { return false } var ec uint32 if e := syscall.GetExitCodeProcess(h, &ec); e != nil { return false } return ec == exit_STILL_ACTIVE }
[ "func", "_pidAlive", "(", "pid", "int", ")", "bool", "{", "h", ",", "err", ":=", "syscall", ".", "OpenProcess", "(", "processDesiredAccess", ",", "false", ",", "uint32", "(", "pid", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\...
// _pidAlive tests whether a process is alive or not
[ "_pidAlive", "tests", "whether", "a", "process", "is", "alive", "or", "not" ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/process_windows.go#L17-L29
train
hashicorp/go-plugin
grpc_server.go
Config
func (s *GRPCServer) Config() string { // Create a buffer that will contain our final contents var buf bytes.Buffer // Wrap the base64 encoding with JSON encoding. if err := json.NewEncoder(&buf).Encode(s.config); err != nil { // We panic since ths shouldn't happen under any scenario. We // carefully control t...
go
func (s *GRPCServer) Config() string { // Create a buffer that will contain our final contents var buf bytes.Buffer // Wrap the base64 encoding with JSON encoding. if err := json.NewEncoder(&buf).Encode(s.config); err != nil { // We panic since ths shouldn't happen under any scenario. We // carefully control t...
[ "func", "(", "s", "*", "GRPCServer", ")", "Config", "(", ")", "string", "{", "// Create a buffer that will contain our final contents", "var", "buf", "bytes", ".", "Buffer", "\n\n", "// Wrap the base64 encoding with JSON encoding.", "if", "err", ":=", "json", ".", "Ne...
// Config is the GRPCServerConfig encoded as JSON then base64.
[ "Config", "is", "the", "GRPCServerConfig", "encoded", "as", "JSON", "then", "base64", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_server.go#L114-L127
train
hashicorp/go-plugin
rpc_client.go
newRPCClient
func newRPCClient(c *Client) (*RPCClient, error) { // Connect to the client conn, err := net.Dial(c.address.Network(), c.address.String()) if err != nil { return nil, err } if tcpConn, ok := conn.(*net.TCPConn); ok { // Make sure to set keep alive so that the connection doesn't die tcpConn.SetKeepAlive(true)...
go
func newRPCClient(c *Client) (*RPCClient, error) { // Connect to the client conn, err := net.Dial(c.address.Network(), c.address.String()) if err != nil { return nil, err } if tcpConn, ok := conn.(*net.TCPConn); ok { // Make sure to set keep alive so that the connection doesn't die tcpConn.SetKeepAlive(true)...
[ "func", "newRPCClient", "(", "c", "*", "Client", ")", "(", "*", "RPCClient", ",", "error", ")", "{", "// Connect to the client", "conn", ",", "err", ":=", "net", ".", "Dial", "(", "c", ".", "address", ".", "Network", "(", ")", ",", "c", ".", "address...
// newRPCClient creates a new RPCClient. The Client argument is expected // to be successfully started already with a lock held.
[ "newRPCClient", "creates", "a", "new", "RPCClient", ".", "The", "Client", "argument", "is", "expected", "to", "be", "successfully", "started", "already", "with", "a", "lock", "held", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L25-L57
train
hashicorp/go-plugin
rpc_client.go
NewRPCClient
func NewRPCClient(conn io.ReadWriteCloser, plugins map[string]Plugin) (*RPCClient, error) { // Create the yamux client so we can multiplex mux, err := yamux.Client(conn, nil) if err != nil { conn.Close() return nil, err } // Connect to the control stream. control, err := mux.Open() if err != nil { mux.Clo...
go
func NewRPCClient(conn io.ReadWriteCloser, plugins map[string]Plugin) (*RPCClient, error) { // Create the yamux client so we can multiplex mux, err := yamux.Client(conn, nil) if err != nil { conn.Close() return nil, err } // Connect to the control stream. control, err := mux.Open() if err != nil { mux.Clo...
[ "func", "NewRPCClient", "(", "conn", "io", ".", "ReadWriteCloser", ",", "plugins", "map", "[", "string", "]", "Plugin", ")", "(", "*", "RPCClient", ",", "error", ")", "{", "// Create the yamux client so we can multiplex", "mux", ",", "err", ":=", "yamux", ".",...
// NewRPCClient creates a client from an already-open connection-like value. // Dial is typically used instead.
[ "NewRPCClient", "creates", "a", "client", "from", "an", "already", "-", "open", "connection", "-", "like", "value", ".", "Dial", "is", "typically", "used", "instead", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L61-L98
train
hashicorp/go-plugin
rpc_client.go
SyncStreams
func (c *RPCClient) SyncStreams(stdout io.Writer, stderr io.Writer) error { go copyStream("stdout", stdout, c.stdout) go copyStream("stderr", stderr, c.stderr) return nil }
go
func (c *RPCClient) SyncStreams(stdout io.Writer, stderr io.Writer) error { go copyStream("stdout", stdout, c.stdout) go copyStream("stderr", stderr, c.stderr) return nil }
[ "func", "(", "c", "*", "RPCClient", ")", "SyncStreams", "(", "stdout", "io", ".", "Writer", ",", "stderr", "io", ".", "Writer", ")", "error", "{", "go", "copyStream", "(", "\"", "\"", ",", "stdout", ",", "c", ".", "stdout", ")", "\n", "go", "copySt...
// SyncStreams should be called to enable syncing of stdout, // stderr with the plugin. // // This will return immediately and the syncing will continue to happen // in the background. You do not need to launch this in a goroutine itself. // // This should never be called multiple times.
[ "SyncStreams", "should", "be", "called", "to", "enable", "syncing", "of", "stdout", "stderr", "with", "the", "plugin", ".", "This", "will", "return", "immediately", "and", "the", "syncing", "will", "continue", "to", "happen", "in", "the", "background", ".", ...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L107-L111
train
hashicorp/go-plugin
rpc_client.go
Close
func (c *RPCClient) Close() error { // Call the control channel and ask it to gracefully exit. If this // errors, then we save it so that we always return an error but we // want to try to close the other channels anyways. var empty struct{} returnErr := c.control.Call("Control.Quit", true, &empty) // Close the ...
go
func (c *RPCClient) Close() error { // Call the control channel and ask it to gracefully exit. If this // errors, then we save it so that we always return an error but we // want to try to close the other channels anyways. var empty struct{} returnErr := c.control.Call("Control.Quit", true, &empty) // Close the ...
[ "func", "(", "c", "*", "RPCClient", ")", "Close", "(", ")", "error", "{", "// Call the control channel and ask it to gracefully exit. If this", "// errors, then we save it so that we always return an error but we", "// want to try to close the other channels anyways.", "var", "empty", ...
// Close closes the connection. The client is no longer usable after this // is called.
[ "Close", "closes", "the", "connection", ".", "The", "client", "is", "no", "longer", "usable", "after", "this", "is", "called", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L115-L140
train
hashicorp/go-plugin
rpc_client.go
Ping
func (c *RPCClient) Ping() error { var empty struct{} return c.control.Call("Control.Ping", true, &empty) }
go
func (c *RPCClient) Ping() error { var empty struct{} return c.control.Call("Control.Ping", true, &empty) }
[ "func", "(", "c", "*", "RPCClient", ")", "Ping", "(", ")", "error", "{", "var", "empty", "struct", "{", "}", "\n", "return", "c", ".", "control", ".", "Call", "(", "\"", "\"", ",", "true", ",", "&", "empty", ")", "\n", "}" ]
// Ping pings the connection to ensure it is still alive. // // The error from the RPC call is returned exactly if you want to inspect // it for further error analysis. Any error returned from here would indicate // that the connection to the plugin is not healthy.
[ "Ping", "pings", "the", "connection", "to", "ensure", "it", "is", "still", "alive", ".", "The", "error", "from", "the", "RPC", "call", "is", "returned", "exactly", "if", "you", "want", "to", "inspect", "it", "for", "further", "error", "analysis", ".", "A...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L167-L170
train
hashicorp/go-plugin
rpc_server.go
ServeConn
func (s *RPCServer) ServeConn(conn io.ReadWriteCloser) { // First create the yamux server to wrap this connection mux, err := yamux.Server(conn, nil) if err != nil { conn.Close() log.Printf("[ERR] plugin: error creating yamux server: %s", err) return } // Accept the control connection control, err := mux.A...
go
func (s *RPCServer) ServeConn(conn io.ReadWriteCloser) { // First create the yamux server to wrap this connection mux, err := yamux.Server(conn, nil) if err != nil { conn.Close() log.Printf("[ERR] plugin: error creating yamux server: %s", err) return } // Accept the control connection control, err := mux.A...
[ "func", "(", "s", "*", "RPCServer", ")", "ServeConn", "(", "conn", "io", ".", "ReadWriteCloser", ")", "{", "// First create the yamux server to wrap this connection", "mux", ",", "err", ":=", "yamux", ".", "Server", "(", "conn", ",", "nil", ")", "\n", "if", ...
// ServeConn runs a single connection. // // ServeConn blocks, serving the connection until the client hangs up.
[ "ServeConn", "runs", "a", "single", "connection", ".", "ServeConn", "blocks", "serving", "the", "connection", "until", "the", "client", "hangs", "up", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_server.go#L59-L109
train
hashicorp/go-plugin
rpc_server.go
done
func (s *RPCServer) done() { s.lock.Lock() defer s.lock.Unlock() if s.DoneCh != nil { close(s.DoneCh) s.DoneCh = nil } }
go
func (s *RPCServer) done() { s.lock.Lock() defer s.lock.Unlock() if s.DoneCh != nil { close(s.DoneCh) s.DoneCh = nil } }
[ "func", "(", "s", "*", "RPCServer", ")", "done", "(", ")", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "DoneCh", "!=", "nil", "{", "close", "(", "s", ".", "...
// done is called internally by the control server to trigger the // doneCh to close which is listened to by the main process to cleanly // exit.
[ "done", "is", "called", "internally", "by", "the", "control", "server", "to", "trigger", "the", "doneCh", "to", "close", "which", "is", "listened", "to", "by", "the", "main", "process", "to", "cleanly", "exit", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_server.go#L114-L122
train
hashicorp/go-plugin
server.go
protocolVersion
func protocolVersion(opts *ServeConfig) (int, Protocol, PluginSet) { protoVersion := int(opts.ProtocolVersion) pluginSet := opts.Plugins protoType := ProtocolNetRPC // Check if the client sent a list of acceptable versions var clientVersions []int if vs := os.Getenv("PLUGIN_PROTOCOL_VERSIONS"); vs != "" { for _...
go
func protocolVersion(opts *ServeConfig) (int, Protocol, PluginSet) { protoVersion := int(opts.ProtocolVersion) pluginSet := opts.Plugins protoType := ProtocolNetRPC // Check if the client sent a list of acceptable versions var clientVersions []int if vs := os.Getenv("PLUGIN_PROTOCOL_VERSIONS"); vs != "" { for _...
[ "func", "protocolVersion", "(", "opts", "*", "ServeConfig", ")", "(", "int", ",", "Protocol", ",", "PluginSet", ")", "{", "protoVersion", ":=", "int", "(", "opts", ".", "ProtocolVersion", ")", "\n", "pluginSet", ":=", "opts", ".", "Plugins", "\n", "protoTy...
// protocolVersion determines the protocol version and plugin set to be used by // the server. In the event that there is no suitable version, the last version // in the config is returned leaving the client to report the incompatibility.
[ "protocolVersion", "determines", "the", "protocol", "version", "and", "plugin", "set", "to", "be", "used", "by", "the", "server", ".", "In", "the", "event", "that", "there", "is", "no", "suitable", "version", "the", "last", "version", "in", "the", "config", ...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/server.go#L93-L167
train
hashicorp/go-plugin
process_posix.go
_pidAlive
func _pidAlive(pid int) bool { proc, err := os.FindProcess(pid) if err == nil { err = proc.Signal(syscall.Signal(0)) } return err == nil }
go
func _pidAlive(pid int) bool { proc, err := os.FindProcess(pid) if err == nil { err = proc.Signal(syscall.Signal(0)) } return err == nil }
[ "func", "_pidAlive", "(", "pid", "int", ")", "bool", "{", "proc", ",", "err", ":=", "os", ".", "FindProcess", "(", "pid", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "proc", ".", "Signal", "(", "syscall", ".", "Signal", "(", "0", ")", ...
// _pidAlive tests whether a process is alive or not by sending it Signal 0, // since Go otherwise has no way to test this.
[ "_pidAlive", "tests", "whether", "a", "process", "is", "alive", "or", "not", "by", "sending", "it", "Signal", "0", "since", "Go", "otherwise", "has", "no", "way", "to", "test", "this", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/process_posix.go#L12-L19
train
hashicorp/go-plugin
mux_broker.go
AcceptAndServe
func (m *MuxBroker) AcceptAndServe(id uint32, v interface{}) { conn, err := m.Accept(id) if err != nil { log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err) return } serve(conn, "Plugin", v) }
go
func (m *MuxBroker) AcceptAndServe(id uint32, v interface{}) { conn, err := m.Accept(id) if err != nil { log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err) return } serve(conn, "Plugin", v) }
[ "func", "(", "m", "*", "MuxBroker", ")", "AcceptAndServe", "(", "id", "uint32", ",", "v", "interface", "{", "}", ")", "{", "conn", ",", "err", ":=", "m", ".", "Accept", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", ...
// AcceptAndServe is used to accept a specific stream ID and immediately // serve an RPC server on that stream ID. This is used to easily serve // complex arguments. // // The served interface is always registered to the "Plugin" name.
[ "AcceptAndServe", "is", "used", "to", "accept", "a", "specific", "stream", "ID", "and", "immediately", "serve", "an", "RPC", "server", "on", "that", "stream", "ID", ".", "This", "is", "used", "to", "easily", "serve", "complex", "arguments", ".", "The", "se...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/mux_broker.go#L80-L88
train
hashicorp/go-plugin
process.go
pidWait
func pidWait(pid int) error { ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() for range ticker.C { if !pidAlive(pid) { break } } return nil }
go
func pidWait(pid int) error { ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() for range ticker.C { if !pidAlive(pid) { break } } return nil }
[ "func", "pidWait", "(", "pid", "int", ")", "error", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "1", "*", "time", ".", "Second", ")", "\n", "defer", "ticker", ".", "Stop", "(", ")", "\n\n", "for", "range", "ticker", ".", "C", "{", "if", "...
// pidWait blocks for a process to exit.
[ "pidWait", "blocks", "for", "a", "process", "to", "exit", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/process.go#L13-L24
train
hashicorp/go-plugin
grpc_controller.go
Shutdown
func (s *grpcControllerServer) Shutdown(ctx context.Context, _ *plugin.Empty) (*plugin.Empty, error) { resp := &plugin.Empty{} // TODO: figure out why GracefullStop doesn't work. s.server.Stop() return resp, nil }
go
func (s *grpcControllerServer) Shutdown(ctx context.Context, _ *plugin.Empty) (*plugin.Empty, error) { resp := &plugin.Empty{} // TODO: figure out why GracefullStop doesn't work. s.server.Stop() return resp, nil }
[ "func", "(", "s", "*", "grpcControllerServer", ")", "Shutdown", "(", "ctx", "context", ".", "Context", ",", "_", "*", "plugin", ".", "Empty", ")", "(", "*", "plugin", ".", "Empty", ",", "error", ")", "{", "resp", ":=", "&", "plugin", ".", "Empty", ...
// Shutdown stops the grpc server. It first will attempt a graceful stop, then a // full stop on the server.
[ "Shutdown", "stops", "the", "grpc", "server", ".", "It", "first", "will", "attempt", "a", "graceful", "stop", "then", "a", "full", "stop", "on", "the", "server", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_controller.go#L17-L23
train
nareix/joy4
av/av.go
IsPlanar
func (self SampleFormat) IsPlanar() bool { switch self { case S16P, S32P, FLTP, DBLP: return true default: return false } }
go
func (self SampleFormat) IsPlanar() bool { switch self { case S16P, S32P, FLTP, DBLP: return true default: return false } }
[ "func", "(", "self", "SampleFormat", ")", "IsPlanar", "(", ")", "bool", "{", "switch", "self", "{", "case", "S16P", ",", "S32P", ",", "FLTP", ",", "DBLP", ":", "return", "true", "\n", "default", ":", "return", "false", "\n", "}", "\n", "}" ]
// Check if this sample format is in planar.
[ "Check", "if", "this", "sample", "format", "is", "in", "planar", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L70-L77
train
nareix/joy4
av/av.go
MakeAudioCodecType
func MakeAudioCodecType(base uint32) (c CodecType) { c = CodecType(base)<<codecTypeOtherBits | CodecType(codecTypeAudioBit) return }
go
func MakeAudioCodecType(base uint32) (c CodecType) { c = CodecType(base)<<codecTypeOtherBits | CodecType(codecTypeAudioBit) return }
[ "func", "MakeAudioCodecType", "(", "base", "uint32", ")", "(", "c", "CodecType", ")", "{", "c", "=", "CodecType", "(", "base", ")", "<<", "codecTypeOtherBits", "|", "CodecType", "(", "codecTypeAudioBit", ")", "\n", "return", "\n", "}" ]
// Make a new audio codec type.
[ "Make", "a", "new", "audio", "codec", "type", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L157-L160
train
nareix/joy4
av/av.go
HasSameFormat
func (self AudioFrame) HasSameFormat(other AudioFrame) bool { if self.SampleRate != other.SampleRate { return false } if self.ChannelLayout != other.ChannelLayout { return false } if self.SampleFormat != other.SampleFormat { return false } return true }
go
func (self AudioFrame) HasSameFormat(other AudioFrame) bool { if self.SampleRate != other.SampleRate { return false } if self.ChannelLayout != other.ChannelLayout { return false } if self.SampleFormat != other.SampleFormat { return false } return true }
[ "func", "(", "self", "AudioFrame", ")", "HasSameFormat", "(", "other", "AudioFrame", ")", "bool", "{", "if", "self", ".", "SampleRate", "!=", "other", ".", "SampleRate", "{", "return", "false", "\n", "}", "\n", "if", "self", ".", "ChannelLayout", "!=", "...
// Check this audio frame has same format as other audio frame.
[ "Check", "this", "audio", "frame", "has", "same", "format", "as", "other", "audio", "frame", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L252-L263
train
nareix/joy4
av/av.go
Slice
func (self AudioFrame) Slice(start int, end int) (out AudioFrame) { if start > end { panic(fmt.Sprintf("av: AudioFrame split failed start=%d end=%d invalid", start, end)) } out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount = end - start size := self.SampleFormat.BytesPerSample() for i :=...
go
func (self AudioFrame) Slice(start int, end int) (out AudioFrame) { if start > end { panic(fmt.Sprintf("av: AudioFrame split failed start=%d end=%d invalid", start, end)) } out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount = end - start size := self.SampleFormat.BytesPerSample() for i :=...
[ "func", "(", "self", "AudioFrame", ")", "Slice", "(", "start", "int", ",", "end", "int", ")", "(", "out", "AudioFrame", ")", "{", "if", "start", ">", "end", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "start", ",", "end", ")",...
// Split sample audio sample from this frame.
[ "Split", "sample", "audio", "sample", "from", "this", "frame", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L266-L278
train
nareix/joy4
av/av.go
Concat
func (self AudioFrame) Concat(in AudioFrame) (out AudioFrame) { out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount += in.SampleCount for i := range out.Data { out.Data[i] = append(out.Data[i], in.Data[i]...) } return }
go
func (self AudioFrame) Concat(in AudioFrame) (out AudioFrame) { out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount += in.SampleCount for i := range out.Data { out.Data[i] = append(out.Data[i], in.Data[i]...) } return }
[ "func", "(", "self", "AudioFrame", ")", "Concat", "(", "in", "AudioFrame", ")", "(", "out", "AudioFrame", ")", "{", "out", "=", "self", "\n", "out", ".", "Data", "=", "append", "(", "[", "]", "[", "]", "byte", "(", "nil", ")", ",", "out", ".", ...
// Concat two audio frames.
[ "Concat", "two", "audio", "frames", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L281-L289
train
nareix/joy4
av/transcode/transcode.go
Do
func (self *Transcoder) Do(pkt av.Packet) (out []av.Packet, err error) { stream := self.streams[pkt.Idx] if stream.aenc != nil && stream.adec != nil { if out, err = stream.audioDecodeAndEncode(pkt); err != nil { return } } else { out = append(out, pkt) } return }
go
func (self *Transcoder) Do(pkt av.Packet) (out []av.Packet, err error) { stream := self.streams[pkt.Idx] if stream.aenc != nil && stream.adec != nil { if out, err = stream.audioDecodeAndEncode(pkt); err != nil { return } } else { out = append(out, pkt) } return }
[ "func", "(", "self", "*", "Transcoder", ")", "Do", "(", "pkt", "av", ".", "Packet", ")", "(", "out", "[", "]", "av", ".", "Packet", ",", "err", "error", ")", "{", "stream", ":=", "self", ".", "streams", "[", "pkt", ".", "Idx", "]", "\n", "if", ...
// Do the transcode. // // In audio transcoding one Packet may transcode into many Packets // packet time will be adjusted automatically.
[ "Do", "the", "transcode", ".", "In", "audio", "transcoding", "one", "Packet", "may", "transcode", "into", "many", "Packets", "packet", "time", "will", "be", "adjusted", "automatically", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L114-L124
train
nareix/joy4
av/transcode/transcode.go
Streams
func (self *Transcoder) Streams() (streams []av.CodecData, err error) { for _, stream := range self.streams { streams = append(streams, stream.codec) } return }
go
func (self *Transcoder) Streams() (streams []av.CodecData, err error) { for _, stream := range self.streams { streams = append(streams, stream.codec) } return }
[ "func", "(", "self", "*", "Transcoder", ")", "Streams", "(", ")", "(", "streams", "[", "]", "av", ".", "CodecData", ",", "err", "error", ")", "{", "for", "_", ",", "stream", ":=", "range", "self", ".", "streams", "{", "streams", "=", "append", "(",...
// Get CodecDatas after transcoding.
[ "Get", "CodecDatas", "after", "transcoding", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L127-L132
train
nareix/joy4
av/transcode/transcode.go
Close
func (self *Transcoder) Close() (err error) { for _, stream := range self.streams { if stream.aenc != nil { stream.aenc.Close() stream.aenc = nil } if stream.adec != nil { stream.adec.Close() stream.adec = nil } } self.streams = nil return }
go
func (self *Transcoder) Close() (err error) { for _, stream := range self.streams { if stream.aenc != nil { stream.aenc.Close() stream.aenc = nil } if stream.adec != nil { stream.adec.Close() stream.adec = nil } } self.streams = nil return }
[ "func", "(", "self", "*", "Transcoder", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "for", "_", ",", "stream", ":=", "range", "self", ".", "streams", "{", "if", "stream", ".", "aenc", "!=", "nil", "{", "stream", ".", "aenc", ".", "Clos...
// Close transcoder, close related encoder and decoders.
[ "Close", "transcoder", "close", "related", "encoder", "and", "decoders", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L135-L148
train
nareix/joy4
av/pubsub/queue.go
WritePacket
func (self *Queue) WritePacket(pkt av.Packet) (err error) { self.lock.Lock() self.buf.Push(pkt) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { self.curgopcount++ } for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 { pkt := self.buf.Pop() if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFra...
go
func (self *Queue) WritePacket(pkt av.Packet) (err error) { self.lock.Lock() self.buf.Push(pkt) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { self.curgopcount++ } for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 { pkt := self.buf.Pop() if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFra...
[ "func", "(", "self", "*", "Queue", ")", "WritePacket", "(", "pkt", "av", ".", "Packet", ")", "(", "err", "error", ")", "{", "self", ".", "lock", ".", "Lock", "(", ")", "\n\n", "self", ".", "buf", ".", "Push", "(", "pkt", ")", "\n", "if", "pkt",...
// Put packet into buffer, old packets will be discared.
[ "Put", "packet", "into", "buffer", "old", "packets", "will", "be", "discared", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L83-L106
train
nareix/joy4
av/pubsub/queue.go
Oldest
func (self *Queue) Oldest() *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { return buf.Head } return cursor }
go
func (self *Queue) Oldest() *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { return buf.Head } return cursor }
[ "func", "(", "self", "*", "Queue", ")", "Oldest", "(", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", "Buf", ",", "videoidx", "int", ")", ...
// Create cursor position at oldest buffered packet.
[ "Create", "cursor", "position", "at", "oldest", "buffered", "packet", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L131-L137
train
nareix/joy4
av/pubsub/queue.go
DelayedTime
func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if buf.IsValidPos(i) { end := buf.Get(i) for buf.IsValidPos(i) { if end.Time-buf.Get(i).Time > dur { break } i-- ...
go
func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if buf.IsValidPos(i) { end := buf.Get(i) for buf.IsValidPos(i) { if end.Time-buf.Get(i).Time > dur { break } i-- ...
[ "func", "(", "self", "*", "Queue", ")", "DelayedTime", "(", "dur", "time", ".", "Duration", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", ...
// Create cursor position at specific time in buffered packets.
[ "Create", "cursor", "position", "at", "specific", "time", "in", "buffered", "packets", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L140-L156
train
nareix/joy4
av/pubsub/queue.go
DelayedGopCount
func (self *Queue) DelayedGopCount(n int) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if videoidx != -1 { for gop := 0; buf.IsValidPos(i) && gop < n; i-- { pkt := buf.Get(i) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyF...
go
func (self *Queue) DelayedGopCount(n int) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if videoidx != -1 { for gop := 0; buf.IsValidPos(i) && gop < n; i-- { pkt := buf.Get(i) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyF...
[ "func", "(", "self", "*", "Queue", ")", "DelayedGopCount", "(", "n", "int", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", "Buf", ",", "vid...
// Create cursor position at specific delayed GOP count in buffered packets.
[ "Create", "cursor", "position", "at", "specific", "delayed", "GOP", "count", "in", "buffered", "packets", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L159-L174
train
nareix/joy4
av/pubsub/queue.go
ReadPacket
func (self *QueueCursor) ReadPacket() (pkt av.Packet, err error) { self.que.cond.L.Lock() buf := self.que.buf if !self.gotpos { self.pos = self.init(buf, self.que.videoidx) self.gotpos = true } for { if self.pos.LT(buf.Head) { self.pos = buf.Head } else if self.pos.GT(buf.Tail) { self.pos = buf.Tail ...
go
func (self *QueueCursor) ReadPacket() (pkt av.Packet, err error) { self.que.cond.L.Lock() buf := self.que.buf if !self.gotpos { self.pos = self.init(buf, self.que.videoidx) self.gotpos = true } for { if self.pos.LT(buf.Head) { self.pos = buf.Head } else if self.pos.GT(buf.Tail) { self.pos = buf.Tail ...
[ "func", "(", "self", "*", "QueueCursor", ")", "ReadPacket", "(", ")", "(", "pkt", "av", ".", "Packet", ",", "err", "error", ")", "{", "self", ".", "que", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "buf", ":=", "self", ".", "que", ".", ...
// ReadPacket will not consume packets in Queue, it's just a cursor.
[ "ReadPacket", "will", "not", "consume", "packets", "in", "Queue", "it", "s", "just", "a", "cursor", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L191-L217
train
go-martini/martini
martini.go
New
func New() *Martini { m := &Martini{Injector: inject.New(), action: func() {}, logger: log.New(os.Stdout, "[martini] ", 0)} m.Map(m.logger) m.Map(defaultReturnHandler()) return m }
go
func New() *Martini { m := &Martini{Injector: inject.New(), action: func() {}, logger: log.New(os.Stdout, "[martini] ", 0)} m.Map(m.logger) m.Map(defaultReturnHandler()) return m }
[ "func", "New", "(", ")", "*", "Martini", "{", "m", ":=", "&", "Martini", "{", "Injector", ":", "inject", ".", "New", "(", ")", ",", "action", ":", "func", "(", ")", "{", "}", ",", "logger", ":", "log", ".", "New", "(", "os", ".", "Stdout", ",...
// New creates a bare bones Martini instance. Use this method if you want to have full control over the middleware that is used.
[ "New", "creates", "a", "bare", "bones", "Martini", "instance", ".", "Use", "this", "method", "if", "you", "want", "to", "have", "full", "control", "over", "the", "middleware", "that", "is", "used", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L38-L43
train
go-martini/martini
martini.go
Logger
func (m *Martini) Logger(logger *log.Logger) { m.logger = logger m.Map(m.logger) }
go
func (m *Martini) Logger(logger *log.Logger) { m.logger = logger m.Map(m.logger) }
[ "func", "(", "m", "*", "Martini", ")", "Logger", "(", "logger", "*", "log", ".", "Logger", ")", "{", "m", ".", "logger", "=", "logger", "\n", "m", ".", "Map", "(", "m", ".", "logger", ")", "\n", "}" ]
// Logger sets the logger
[ "Logger", "sets", "the", "logger" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L61-L64
train
go-martini/martini
martini.go
Use
func (m *Martini) Use(handler Handler) { validateHandler(handler) m.handlers = append(m.handlers, handler) }
go
func (m *Martini) Use(handler Handler) { validateHandler(handler) m.handlers = append(m.handlers, handler) }
[ "func", "(", "m", "*", "Martini", ")", "Use", "(", "handler", "Handler", ")", "{", "validateHandler", "(", "handler", ")", "\n\n", "m", ".", "handlers", "=", "append", "(", "m", ".", "handlers", ",", "handler", ")", "\n", "}" ]
// Use adds a middleware Handler to the stack. Will panic if the handler is not a callable func. Middleware Handlers are invoked in the order that they are added.
[ "Use", "adds", "a", "middleware", "Handler", "to", "the", "stack", ".", "Will", "panic", "if", "the", "handler", "is", "not", "a", "callable", "func", ".", "Middleware", "Handlers", "are", "invoked", "in", "the", "order", "that", "they", "are", "added", ...
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L67-L71
train
go-martini/martini
martini.go
ServeHTTP
func (m *Martini) ServeHTTP(res http.ResponseWriter, req *http.Request) { m.createContext(res, req).run() }
go
func (m *Martini) ServeHTTP(res http.ResponseWriter, req *http.Request) { m.createContext(res, req).run() }
[ "func", "(", "m", "*", "Martini", ")", "ServeHTTP", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "m", ".", "createContext", "(", "res", ",", "req", ")", ".", "run", "(", ")", "\n", "}" ]
// ServeHTTP is the HTTP Entry point for a Martini instance. Useful if you want to control your own HTTP server.
[ "ServeHTTP", "is", "the", "HTTP", "Entry", "point", "for", "a", "Martini", "instance", ".", "Useful", "if", "you", "want", "to", "control", "your", "own", "HTTP", "server", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L74-L76
train
go-martini/martini
martini.go
RunOnAddr
func (m *Martini) RunOnAddr(addr string) { // TODO: Should probably be implemented using a new instance of http.Server in place of // calling http.ListenAndServer directly, so that it could be stored in the martini struct for later use. // This would also allow to improve testing when a custom host and port are pass...
go
func (m *Martini) RunOnAddr(addr string) { // TODO: Should probably be implemented using a new instance of http.Server in place of // calling http.ListenAndServer directly, so that it could be stored in the martini struct for later use. // This would also allow to improve testing when a custom host and port are pass...
[ "func", "(", "m", "*", "Martini", ")", "RunOnAddr", "(", "addr", "string", ")", "{", "// TODO: Should probably be implemented using a new instance of http.Server in place of", "// calling http.ListenAndServer directly, so that it could be stored in the martini struct for later use.", "//...
// Run the http server on a given host and port.
[ "Run", "the", "http", "server", "on", "a", "given", "host", "and", "port", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L79-L87
train
go-martini/martini
martini.go
Classic
func Classic() *ClassicMartini { r := NewRouter() m := New() m.Use(Logger()) m.Use(Recovery()) m.Use(Static("public")) m.MapTo(r, (*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
go
func Classic() *ClassicMartini { r := NewRouter() m := New() m.Use(Logger()) m.Use(Recovery()) m.Use(Static("public")) m.MapTo(r, (*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
[ "func", "Classic", "(", ")", "*", "ClassicMartini", "{", "r", ":=", "NewRouter", "(", ")", "\n", "m", ":=", "New", "(", ")", "\n", "m", ".", "Use", "(", "Logger", "(", ")", ")", "\n", "m", ".", "Use", "(", "Recovery", "(", ")", ")", "\n", "m"...
// Classic creates a classic Martini with some basic default middleware - martini.Logger, martini.Recovery and martini.Static. // Classic also maps martini.Routes as a service.
[ "Classic", "creates", "a", "classic", "Martini", "with", "some", "basic", "default", "middleware", "-", "martini", ".", "Logger", "martini", ".", "Recovery", "and", "martini", ".", "Static", ".", "Classic", "also", "maps", "martini", ".", "Routes", "as", "a"...
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L118-L127
train
go-martini/martini
router.go
URLWith
func (r *route) URLWith(args []string) string { if len(args) > 0 { argCount := len(args) i := 0 url := urlReg.ReplaceAllStringFunc(r.pattern, func(m string) string { var val interface{} if i < argCount { val = args[i] } else { val = m } i += 1 return fmt.Sprintf(`%v`, val) }) retur...
go
func (r *route) URLWith(args []string) string { if len(args) > 0 { argCount := len(args) i := 0 url := urlReg.ReplaceAllStringFunc(r.pattern, func(m string) string { var val interface{} if i < argCount { val = args[i] } else { val = m } i += 1 return fmt.Sprintf(`%v`, val) }) retur...
[ "func", "(", "r", "*", "route", ")", "URLWith", "(", "args", "[", "]", "string", ")", "string", "{", "if", "len", "(", "args", ")", ">", "0", "{", "argCount", ":=", "len", "(", "args", ")", "\n", "i", ":=", "0", "\n", "url", ":=", "urlReg", "...
// URLWith returns the url pattern replacing the parameters for its values
[ "URLWith", "returns", "the", "url", "pattern", "replacing", "the", "parameters", "for", "its", "values" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L291-L309
train
go-martini/martini
router.go
URLFor
func (r *router) URLFor(name string, params ...interface{}) string { route := r.findRoute(name) if route == nil { panic("route not found") } var args []string for _, param := range params { switch v := param.(type) { case int: args = append(args, strconv.FormatInt(int64(v), 10)) case string: args =...
go
func (r *router) URLFor(name string, params ...interface{}) string { route := r.findRoute(name) if route == nil { panic("route not found") } var args []string for _, param := range params { switch v := param.(type) { case int: args = append(args, strconv.FormatInt(int64(v), 10)) case string: args =...
[ "func", "(", "r", "*", "router", ")", "URLFor", "(", "name", "string", ",", "params", "...", "interface", "{", "}", ")", "string", "{", "route", ":=", "r", ".", "findRoute", "(", "name", ")", "\n\n", "if", "route", "==", "nil", "{", "panic", "(", ...
// URLFor returns the url for the given route name.
[ "URLFor", "returns", "the", "url", "for", "the", "given", "route", "name", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L338-L360
train
go-martini/martini
router.go
MethodsFor
func (r *router) MethodsFor(path string) []string { methods := []string{} for _, route := range r.getRoutes() { matches := route.regex.FindStringSubmatch(path) if len(matches) > 0 && matches[0] == path && !hasMethod(methods, route.method) { methods = append(methods, route.method) } } return methods }
go
func (r *router) MethodsFor(path string) []string { methods := []string{} for _, route := range r.getRoutes() { matches := route.regex.FindStringSubmatch(path) if len(matches) > 0 && matches[0] == path && !hasMethod(methods, route.method) { methods = append(methods, route.method) } } return methods }
[ "func", "(", "r", "*", "router", ")", "MethodsFor", "(", "path", "string", ")", "[", "]", "string", "{", "methods", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "route", ":=", "range", "r", ".", "getRoutes", "(", ")", "{", "matches"...
// MethodsFor returns all methods available for path
[ "MethodsFor", "returns", "all", "methods", "available", "for", "path" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L383-L392
train
go-martini/martini
logger.go
Logger
func Logger() Handler { return func(res http.ResponseWriter, req *http.Request, c Context, log *log.Logger) { start := time.Now() addr := req.Header.Get("X-Real-IP") if addr == "" { addr = req.Header.Get("X-Forwarded-For") if addr == "" { addr = req.RemoteAddr } } log.Printf("Started %s %s for...
go
func Logger() Handler { return func(res http.ResponseWriter, req *http.Request, c Context, log *log.Logger) { start := time.Now() addr := req.Header.Get("X-Real-IP") if addr == "" { addr = req.Header.Get("X-Forwarded-For") if addr == "" { addr = req.RemoteAddr } } log.Printf("Started %s %s for...
[ "func", "Logger", "(", ")", "Handler", "{", "return", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "c", "Context", ",", "log", "*", "log", ".", "Logger", ")", "{", "start", ":=", "time", ".", "Now...
// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
[ "Logger", "returns", "a", "middleware", "handler", "that", "logs", "the", "request", "as", "it", "goes", "in", "and", "the", "response", "as", "it", "goes", "out", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/logger.go#L10-L29
train