id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
12,500 | performancecopilot/speed | registry.go | StringCount | func (r *PCPRegistry) StringCount() int {
if r.version2 {
return r.stringcount + r.MetricCount() + r.InstanceCount()
}
return r.stringcount
} | go | func (r *PCPRegistry) StringCount() int {
if r.version2 {
return r.stringcount + r.MetricCount() + r.InstanceCount()
}
return r.stringcount
} | [
"func",
"(",
"r",
"*",
"PCPRegistry",
")",
"StringCount",
"(",
")",
"int",
"{",
"if",
"r",
".",
"version2",
"{",
"return",
"r",
".",
"stringcount",
"+",
"r",
".",
"MetricCount",
"(",
")",
"+",
"r",
".",
"InstanceCount",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"stringcount",
"\n",
"}"
] | // StringCount returns the number of strings in the registry | [
"StringCount",
"returns",
"the",
"number",
"of",
"strings",
"in",
"the",
"registry"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L108-L114 |
12,501 | performancecopilot/speed | registry.go | HasInstanceDomain | func (r *PCPRegistry) HasInstanceDomain(name string) bool {
r.indomlock.RLock()
defer r.indomlock.RUnlock()
_, present := r.instanceDomains[name]
return present
} | go | func (r *PCPRegistry) HasInstanceDomain(name string) bool {
r.indomlock.RLock()
defer r.indomlock.RUnlock()
_, present := r.instanceDomains[name]
return present
} | [
"func",
"(",
"r",
"*",
"PCPRegistry",
")",
"HasInstanceDomain",
"(",
"name",
"string",
")",
"bool",
"{",
"r",
".",
"indomlock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"indomlock",
".",
"RUnlock",
"(",
")",
"\n\n",
"_",
",",
"present",
":=",
"r",
".",
"instanceDomains",
"[",
"name",
"]",
"\n",
"return",
"present",
"\n",
"}"
] | // HasInstanceDomain returns true if the registry already has an indom of the specified name | [
"HasInstanceDomain",
"returns",
"true",
"if",
"the",
"registry",
"already",
"has",
"an",
"indom",
"of",
"the",
"specified",
"name"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L117-L123 |
12,502 | performancecopilot/speed | registry.go | HasMetric | func (r *PCPRegistry) HasMetric(name string) bool {
r.metricslock.RLock()
defer r.metricslock.RUnlock()
_, present := r.metrics[name]
return present
} | go | func (r *PCPRegistry) HasMetric(name string) bool {
r.metricslock.RLock()
defer r.metricslock.RUnlock()
_, present := r.metrics[name]
return present
} | [
"func",
"(",
"r",
"*",
"PCPRegistry",
")",
"HasMetric",
"(",
"name",
"string",
")",
"bool",
"{",
"r",
".",
"metricslock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"metricslock",
".",
"RUnlock",
"(",
")",
"\n\n",
"_",
",",
"present",
":=",
"r",
".",
"metrics",
"[",
"name",
"]",
"\n",
"return",
"present",
"\n",
"}"
] | // HasMetric returns true if the registry already has a metric of the specified name | [
"HasMetric",
"returns",
"true",
"if",
"the",
"registry",
"already",
"has",
"a",
"metric",
"of",
"the",
"specified",
"name"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L126-L132 |
12,503 | performancecopilot/speed | registry.go | AddInstanceDomain | func (r *PCPRegistry) AddInstanceDomain(indom InstanceDomain) error {
if r.HasInstanceDomain(indom.Name()) {
return errors.New("InstanceDomain is already defined for the current registry")
}
r.indomlock.Lock()
defer r.indomlock.Unlock()
if r.mapped {
return errors.New("Cannot add an indom when a mapping is active")
}
r.instanceDomains[indom.Name()] = indom.(*PCPInstanceDomain)
r.instanceCount += indom.InstanceCount()
if !r.version2 {
for _, v := range indom.Instances() {
if len(v) > MaxV1NameLength {
r.version2 = true
}
}
}
if indom.(*PCPInstanceDomain).shortDescription != "" {
r.stringcount++
}
if indom.(*PCPInstanceDomain).longDescription != "" {
r.stringcount++
}
return nil
} | go | func (r *PCPRegistry) AddInstanceDomain(indom InstanceDomain) error {
if r.HasInstanceDomain(indom.Name()) {
return errors.New("InstanceDomain is already defined for the current registry")
}
r.indomlock.Lock()
defer r.indomlock.Unlock()
if r.mapped {
return errors.New("Cannot add an indom when a mapping is active")
}
r.instanceDomains[indom.Name()] = indom.(*PCPInstanceDomain)
r.instanceCount += indom.InstanceCount()
if !r.version2 {
for _, v := range indom.Instances() {
if len(v) > MaxV1NameLength {
r.version2 = true
}
}
}
if indom.(*PCPInstanceDomain).shortDescription != "" {
r.stringcount++
}
if indom.(*PCPInstanceDomain).longDescription != "" {
r.stringcount++
}
return nil
} | [
"func",
"(",
"r",
"*",
"PCPRegistry",
")",
"AddInstanceDomain",
"(",
"indom",
"InstanceDomain",
")",
"error",
"{",
"if",
"r",
".",
"HasInstanceDomain",
"(",
"indom",
".",
"Name",
"(",
")",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"r",
".",
"indomlock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"indomlock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
".",
"mapped",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"r",
".",
"instanceDomains",
"[",
"indom",
".",
"Name",
"(",
")",
"]",
"=",
"indom",
".",
"(",
"*",
"PCPInstanceDomain",
")",
"\n",
"r",
".",
"instanceCount",
"+=",
"indom",
".",
"InstanceCount",
"(",
")",
"\n\n",
"if",
"!",
"r",
".",
"version2",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"indom",
".",
"Instances",
"(",
")",
"{",
"if",
"len",
"(",
"v",
")",
">",
"MaxV1NameLength",
"{",
"r",
".",
"version2",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"indom",
".",
"(",
"*",
"PCPInstanceDomain",
")",
".",
"shortDescription",
"!=",
"\"",
"\"",
"{",
"r",
".",
"stringcount",
"++",
"\n",
"}",
"\n\n",
"if",
"indom",
".",
"(",
"*",
"PCPInstanceDomain",
")",
".",
"longDescription",
"!=",
"\"",
"\"",
"{",
"r",
".",
"stringcount",
"++",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // AddInstanceDomain will add a new instance domain to the current registry | [
"AddInstanceDomain",
"will",
"add",
"a",
"new",
"instance",
"domain",
"to",
"the",
"current",
"registry"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L135-L167 |
12,504 | performancecopilot/speed | registry.go | AddMetric | func (r *PCPRegistry) AddMetric(m Metric) error {
if r.mapped {
return errors.New("cannot add a metric when a mapping is active")
}
if r.HasMetric(m.Name()) {
return errors.New("metric is already defined for the current registry")
}
pcpm := m.(PCPMetric)
// if it is an indom metric
if pcpm.Indom() != nil && !r.HasInstanceDomain(pcpm.Indom().Name()) {
err := r.AddInstanceDomain(pcpm.Indom())
if err != nil {
return err
}
}
r.metricslock.Lock()
defer r.metricslock.Unlock()
r.addMetric(pcpm)
return nil
} | go | func (r *PCPRegistry) AddMetric(m Metric) error {
if r.mapped {
return errors.New("cannot add a metric when a mapping is active")
}
if r.HasMetric(m.Name()) {
return errors.New("metric is already defined for the current registry")
}
pcpm := m.(PCPMetric)
// if it is an indom metric
if pcpm.Indom() != nil && !r.HasInstanceDomain(pcpm.Indom().Name()) {
err := r.AddInstanceDomain(pcpm.Indom())
if err != nil {
return err
}
}
r.metricslock.Lock()
defer r.metricslock.Unlock()
r.addMetric(pcpm)
return nil
} | [
"func",
"(",
"r",
"*",
"PCPRegistry",
")",
"AddMetric",
"(",
"m",
"Metric",
")",
"error",
"{",
"if",
"r",
".",
"mapped",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"HasMetric",
"(",
"m",
".",
"Name",
"(",
")",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pcpm",
":=",
"m",
".",
"(",
"PCPMetric",
")",
"\n\n",
"// if it is an indom metric",
"if",
"pcpm",
".",
"Indom",
"(",
")",
"!=",
"nil",
"&&",
"!",
"r",
".",
"HasInstanceDomain",
"(",
"pcpm",
".",
"Indom",
"(",
")",
".",
"Name",
"(",
")",
")",
"{",
"err",
":=",
"r",
".",
"AddInstanceDomain",
"(",
"pcpm",
".",
"Indom",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"r",
".",
"metricslock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"metricslock",
".",
"Unlock",
"(",
")",
"\n\n",
"r",
".",
"addMetric",
"(",
"pcpm",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // AddMetric will add a new metric to the current registry | [
"AddMetric",
"will",
"add",
"a",
"new",
"metric",
"to",
"the",
"current",
"registry"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L196-L220 |
12,505 | performancecopilot/speed | registry.go | AddInstanceDomainByName | func (r *PCPRegistry) AddInstanceDomainByName(name string, instances []string) (InstanceDomain, error) {
if r.HasInstanceDomain(name) {
return nil, errors.New("The InstanceDomain already exists for this registry")
}
indom, err := NewPCPInstanceDomain(name, instances)
if err != nil {
return nil, err
}
err = r.AddInstanceDomain(indom)
if err != nil {
return nil, err
}
return indom, nil
} | go | func (r *PCPRegistry) AddInstanceDomainByName(name string, instances []string) (InstanceDomain, error) {
if r.HasInstanceDomain(name) {
return nil, errors.New("The InstanceDomain already exists for this registry")
}
indom, err := NewPCPInstanceDomain(name, instances)
if err != nil {
return nil, err
}
err = r.AddInstanceDomain(indom)
if err != nil {
return nil, err
}
return indom, nil
} | [
"func",
"(",
"r",
"*",
"PCPRegistry",
")",
"AddInstanceDomainByName",
"(",
"name",
"string",
",",
"instances",
"[",
"]",
"string",
")",
"(",
"InstanceDomain",
",",
"error",
")",
"{",
"if",
"r",
".",
"HasInstanceDomain",
"(",
"name",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"indom",
",",
"err",
":=",
"NewPCPInstanceDomain",
"(",
"name",
",",
"instances",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"r",
".",
"AddInstanceDomain",
"(",
"indom",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"indom",
",",
"nil",
"\n",
"}"
] | // AddInstanceDomainByName adds an instance domain using passed parameters | [
"AddInstanceDomainByName",
"adds",
"an",
"instance",
"domain",
"using",
"passed",
"parameters"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L223-L239 |
12,506 | performancecopilot/speed | registry.go | AddMetricByString | func (r *PCPRegistry) AddMetricByString(str string, val interface{}, t MetricType, s MetricSemantics, u MetricUnit) (Metric, error) {
metric, indom, instances, err := parseString(str)
if err != nil {
return nil, err
}
if instances == nil {
return r.addSingletonMetricByString(metric, val, t, s, u)
}
return r.addInstanceMetricByString(metric, val, indom, instances, t, s, u)
} | go | func (r *PCPRegistry) AddMetricByString(str string, val interface{}, t MetricType, s MetricSemantics, u MetricUnit) (Metric, error) {
metric, indom, instances, err := parseString(str)
if err != nil {
return nil, err
}
if instances == nil {
return r.addSingletonMetricByString(metric, val, t, s, u)
}
return r.addInstanceMetricByString(metric, val, indom, instances, t, s, u)
} | [
"func",
"(",
"r",
"*",
"PCPRegistry",
")",
"AddMetricByString",
"(",
"str",
"string",
",",
"val",
"interface",
"{",
"}",
",",
"t",
"MetricType",
",",
"s",
"MetricSemantics",
",",
"u",
"MetricUnit",
")",
"(",
"Metric",
",",
"error",
")",
"{",
"metric",
",",
"indom",
",",
"instances",
",",
"err",
":=",
"parseString",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"instances",
"==",
"nil",
"{",
"return",
"r",
".",
"addSingletonMetricByString",
"(",
"metric",
",",
"val",
",",
"t",
",",
"s",
",",
"u",
")",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"addInstanceMetricByString",
"(",
"metric",
",",
"val",
",",
"indom",
",",
"instances",
",",
"t",
",",
"s",
",",
"u",
")",
"\n",
"}"
] | // AddMetricByString dynamically creates a PCPMetric | [
"AddMetricByString",
"dynamically",
"creates",
"a",
"PCPMetric"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L322-L333 |
12,507 | performancecopilot/speed | speed.go | init | func init() {
if err := initConfig(); err != nil {
fmt.Fprintln(os.Stderr, errors.Errorf("error initializing config. maybe PCP isn't installed properly"))
}
var err error
histogramIndom, err = NewPCPInstanceDomain("histogram", histogramInstances)
if err != nil {
fmt.Fprintln(os.Stderr, errors.Errorf("could not initialize an instance domain for histograms"))
}
} | go | func init() {
if err := initConfig(); err != nil {
fmt.Fprintln(os.Stderr, errors.Errorf("error initializing config. maybe PCP isn't installed properly"))
}
var err error
histogramIndom, err = NewPCPInstanceDomain("histogram", histogramInstances)
if err != nil {
fmt.Fprintln(os.Stderr, errors.Errorf("could not initialize an instance domain for histograms"))
}
} | [
"func",
"init",
"(",
")",
"{",
"if",
"err",
":=",
"initConfig",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"histogramIndom",
",",
"err",
"=",
"NewPCPInstanceDomain",
"(",
"\"",
"\"",
",",
"histogramInstances",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"}"
] | // init maintains a central location of all things that happen when the package is initialized
// instead of everything being scattered in multiple source files | [
"init",
"maintains",
"a",
"central",
"location",
"of",
"all",
"things",
"that",
"happen",
"when",
"the",
"package",
"is",
"initialized",
"instead",
"of",
"everything",
"being",
"scattered",
"in",
"multiple",
"source",
"files"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/speed.go#L27-L37 |
12,508 | performancecopilot/speed | mmvdump/mmvdump.go | Dump | func Dump(data []byte) (
h *Header,
tocs []*Toc,
metrics map[uint64]Metric,
values map[uint64]*Value,
instances map[uint64]Instance,
indoms map[uint64]*InstanceDomain,
strings map[uint64]*String,
err error,
) {
h, err = readHeader(data)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, err
}
tocs, err = readTocs(data, h.Toc)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, err
}
var ierr, inerr, merr, verr, serr error
metrics, values, instances, indoms, strings, ierr, inerr, merr, verr, serr = readComponents(data, tocs, h.Version)
switch {
case ierr != nil:
return nil, nil, nil, nil, nil, nil, nil, ierr
case inerr != nil:
return nil, nil, nil, nil, nil, nil, nil, inerr
case merr != nil:
return nil, nil, nil, nil, nil, nil, nil, merr
case verr != nil:
return nil, nil, nil, nil, nil, nil, nil, verr
case serr != nil:
return nil, nil, nil, nil, nil, nil, nil, serr
}
return
} | go | func Dump(data []byte) (
h *Header,
tocs []*Toc,
metrics map[uint64]Metric,
values map[uint64]*Value,
instances map[uint64]Instance,
indoms map[uint64]*InstanceDomain,
strings map[uint64]*String,
err error,
) {
h, err = readHeader(data)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, err
}
tocs, err = readTocs(data, h.Toc)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, err
}
var ierr, inerr, merr, verr, serr error
metrics, values, instances, indoms, strings, ierr, inerr, merr, verr, serr = readComponents(data, tocs, h.Version)
switch {
case ierr != nil:
return nil, nil, nil, nil, nil, nil, nil, ierr
case inerr != nil:
return nil, nil, nil, nil, nil, nil, nil, inerr
case merr != nil:
return nil, nil, nil, nil, nil, nil, nil, merr
case verr != nil:
return nil, nil, nil, nil, nil, nil, nil, verr
case serr != nil:
return nil, nil, nil, nil, nil, nil, nil, serr
}
return
} | [
"func",
"Dump",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"h",
"*",
"Header",
",",
"tocs",
"[",
"]",
"*",
"Toc",
",",
"metrics",
"map",
"[",
"uint64",
"]",
"Metric",
",",
"values",
"map",
"[",
"uint64",
"]",
"*",
"Value",
",",
"instances",
"map",
"[",
"uint64",
"]",
"Instance",
",",
"indoms",
"map",
"[",
"uint64",
"]",
"*",
"InstanceDomain",
",",
"strings",
"map",
"[",
"uint64",
"]",
"*",
"String",
",",
"err",
"error",
",",
")",
"{",
"h",
",",
"err",
"=",
"readHeader",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tocs",
",",
"err",
"=",
"readTocs",
"(",
"data",
",",
"h",
".",
"Toc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"ierr",
",",
"inerr",
",",
"merr",
",",
"verr",
",",
"serr",
"error",
"\n\n",
"metrics",
",",
"values",
",",
"instances",
",",
"indoms",
",",
"strings",
",",
"ierr",
",",
"inerr",
",",
"merr",
",",
"verr",
",",
"serr",
"=",
"readComponents",
"(",
"data",
",",
"tocs",
",",
"h",
".",
"Version",
")",
"\n\n",
"switch",
"{",
"case",
"ierr",
"!=",
"nil",
":",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"ierr",
"\n",
"case",
"inerr",
"!=",
"nil",
":",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"inerr",
"\n",
"case",
"merr",
"!=",
"nil",
":",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"merr",
"\n",
"case",
"verr",
"!=",
"nil",
":",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"verr",
"\n",
"case",
"serr",
"!=",
"nil",
":",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"serr",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Dump creates a data dump from the passed data | [
"Dump",
"creates",
"a",
"data",
"dump",
"from",
"the",
"passed",
"data"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/mmvdump/mmvdump.go#L287-L325 |
12,509 | performancecopilot/speed | mmvdump/mmvdump.go | FixedVal | func FixedVal(data uint64, t Type) (interface{}, error) {
switch t {
case Int32Type:
return int32(data), nil
case Uint32Type:
return uint32(data), nil
case Int64Type:
return int64(data), nil
case Uint64Type:
return data, nil
case FloatType:
return math.Float32frombits(uint32(data)), nil
case DoubleType:
return math.Float64frombits(data), nil
}
return nil, errors.New("invalid type")
} | go | func FixedVal(data uint64, t Type) (interface{}, error) {
switch t {
case Int32Type:
return int32(data), nil
case Uint32Type:
return uint32(data), nil
case Int64Type:
return int64(data), nil
case Uint64Type:
return data, nil
case FloatType:
return math.Float32frombits(uint32(data)), nil
case DoubleType:
return math.Float64frombits(data), nil
}
return nil, errors.New("invalid type")
} | [
"func",
"FixedVal",
"(",
"data",
"uint64",
",",
"t",
"Type",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"switch",
"t",
"{",
"case",
"Int32Type",
":",
"return",
"int32",
"(",
"data",
")",
",",
"nil",
"\n",
"case",
"Uint32Type",
":",
"return",
"uint32",
"(",
"data",
")",
",",
"nil",
"\n",
"case",
"Int64Type",
":",
"return",
"int64",
"(",
"data",
")",
",",
"nil",
"\n",
"case",
"Uint64Type",
":",
"return",
"data",
",",
"nil",
"\n",
"case",
"FloatType",
":",
"return",
"math",
".",
"Float32frombits",
"(",
"uint32",
"(",
"data",
")",
")",
",",
"nil",
"\n",
"case",
"DoubleType",
":",
"return",
"math",
".",
"Float64frombits",
"(",
"data",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // FixedVal will infer a fixed size value from the passed data | [
"FixedVal",
"will",
"infer",
"a",
"fixed",
"size",
"value",
"from",
"the",
"passed",
"data"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/mmvdump/mmvdump.go#L328-L345 |
12,510 | performancecopilot/speed | bytewriter/bytewriter.go | MustWrite | func (w *ByteWriter) MustWrite(data []byte, offset int) int {
off, err := w.Write(data, offset)
if err != nil {
panic(err)
}
return off
} | go | func (w *ByteWriter) MustWrite(data []byte, offset int) int {
off, err := w.Write(data, offset)
if err != nil {
panic(err)
}
return off
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWrite",
"(",
"data",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"int",
"{",
"off",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"data",
",",
"offset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"off",
"\n",
"}"
] | // MustWrite is a write that will panic if Write returns an error | [
"MustWrite",
"is",
"a",
"write",
"that",
"will",
"panic",
"if",
"Write",
"returns",
"an",
"error"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L49-L55 |
12,511 | performancecopilot/speed | bytewriter/bytewriter.go | WriteVal | func (w *ByteWriter) WriteVal(val interface{}, offset int) (int, error) {
if s, isString := val.(string); isString {
return w.WriteString(s, offset)
}
buf := bytes.NewBuffer(make([]byte, 0))
err := binary.Write(buf, byteOrder, val)
if err != nil {
return 0, err
}
return w.Write(buf.Bytes(), offset)
} | go | func (w *ByteWriter) WriteVal(val interface{}, offset int) (int, error) {
if s, isString := val.(string); isString {
return w.WriteString(s, offset)
}
buf := bytes.NewBuffer(make([]byte, 0))
err := binary.Write(buf, byteOrder, val)
if err != nil {
return 0, err
}
return w.Write(buf.Bytes(), offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"WriteVal",
"(",
"val",
"interface",
"{",
"}",
",",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"s",
",",
"isString",
":=",
"val",
".",
"(",
"string",
")",
";",
"isString",
"{",
"return",
"w",
".",
"WriteString",
"(",
"s",
",",
"offset",
")",
"\n",
"}",
"\n\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
")",
")",
"\n\n",
"err",
":=",
"binary",
".",
"Write",
"(",
"buf",
",",
"byteOrder",
",",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"w",
".",
"Write",
"(",
"buf",
".",
"Bytes",
"(",
")",
",",
"offset",
")",
"\n",
"}"
] | // WriteVal writes an arbitrary value to the buffer | [
"WriteVal",
"writes",
"an",
"arbitrary",
"value",
"to",
"the",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L58-L71 |
12,512 | performancecopilot/speed | bytewriter/bytewriter.go | MustWriteVal | func (w *ByteWriter) MustWriteVal(val interface{}, offset int) int {
if off, err := w.WriteVal(val, offset); err != nil {
panic(err)
} else {
return off
}
} | go | func (w *ByteWriter) MustWriteVal(val interface{}, offset int) int {
if off, err := w.WriteVal(val, offset); err != nil {
panic(err)
} else {
return off
}
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWriteVal",
"(",
"val",
"interface",
"{",
"}",
",",
"offset",
"int",
")",
"int",
"{",
"if",
"off",
",",
"err",
":=",
"w",
".",
"WriteVal",
"(",
"val",
",",
"offset",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"return",
"off",
"\n",
"}",
"\n",
"}"
] | // MustWriteVal panics if WriteVal fails | [
"MustWriteVal",
"panics",
"if",
"WriteVal",
"fails"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L74-L80 |
12,513 | performancecopilot/speed | bytewriter/bytewriter.go | WriteString | func (w *ByteWriter) WriteString(val string, offset int) (int, error) {
_, err := w.Write([]byte(val), offset)
return offset + len(val), err
} | go | func (w *ByteWriter) WriteString(val string, offset int) (int, error) {
_, err := w.Write([]byte(val), offset)
return offset + len(val), err
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"WriteString",
"(",
"val",
"string",
",",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"val",
")",
",",
"offset",
")",
"\n",
"return",
"offset",
"+",
"len",
"(",
"val",
")",
",",
"err",
"\n",
"}"
] | // WriteString writes a string to the buffer | [
"WriteString",
"writes",
"a",
"string",
"to",
"the",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L83-L86 |
12,514 | performancecopilot/speed | bytewriter/bytewriter.go | MustWriteString | func (w *ByteWriter) MustWriteString(val string, offset int) int {
if off, err := w.WriteString(val, offset); err != nil {
panic(err)
} else {
return off
}
} | go | func (w *ByteWriter) MustWriteString(val string, offset int) int {
if off, err := w.WriteString(val, offset); err != nil {
panic(err)
} else {
return off
}
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWriteString",
"(",
"val",
"string",
",",
"offset",
"int",
")",
"int",
"{",
"if",
"off",
",",
"err",
":=",
"w",
".",
"WriteString",
"(",
"val",
",",
"offset",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"return",
"off",
"\n",
"}",
"\n",
"}"
] | // MustWriteString panics if WriteString fails | [
"MustWriteString",
"panics",
"if",
"WriteString",
"fails"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L89-L95 |
12,515 | performancecopilot/speed | bytewriter/bytewriter.go | WriteInt32 | func (w *ByteWriter) WriteInt32(val int32, offset int) (int, error) {
return w.WriteVal(val, offset)
} | go | func (w *ByteWriter) WriteInt32(val int32, offset int) (int, error) {
return w.WriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"WriteInt32",
"(",
"val",
"int32",
",",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"w",
".",
"WriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // WriteInt32 writes an int32 to the buffer | [
"WriteInt32",
"writes",
"an",
"int32",
"to",
"the",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L98-L100 |
12,516 | performancecopilot/speed | bytewriter/bytewriter.go | MustWriteInt32 | func (w *ByteWriter) MustWriteInt32(val int32, offset int) int {
return w.MustWriteVal(val, offset)
} | go | func (w *ByteWriter) MustWriteInt32(val int32, offset int) int {
return w.MustWriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWriteInt32",
"(",
"val",
"int32",
",",
"offset",
"int",
")",
"int",
"{",
"return",
"w",
".",
"MustWriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // MustWriteInt32 panics if WriteInt32 fails | [
"MustWriteInt32",
"panics",
"if",
"WriteInt32",
"fails"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L103-L105 |
12,517 | performancecopilot/speed | bytewriter/bytewriter.go | WriteInt64 | func (w *ByteWriter) WriteInt64(val int64, offset int) (int, error) {
return w.WriteVal(val, offset)
} | go | func (w *ByteWriter) WriteInt64(val int64, offset int) (int, error) {
return w.WriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"WriteInt64",
"(",
"val",
"int64",
",",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"w",
".",
"WriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // WriteInt64 writes an int64 to the buffer | [
"WriteInt64",
"writes",
"an",
"int64",
"to",
"the",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L108-L110 |
12,518 | performancecopilot/speed | bytewriter/bytewriter.go | MustWriteInt64 | func (w *ByteWriter) MustWriteInt64(val int64, offset int) int {
return w.MustWriteVal(val, offset)
} | go | func (w *ByteWriter) MustWriteInt64(val int64, offset int) int {
return w.MustWriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWriteInt64",
"(",
"val",
"int64",
",",
"offset",
"int",
")",
"int",
"{",
"return",
"w",
".",
"MustWriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // MustWriteInt64 panics if WriteInt64 fails | [
"MustWriteInt64",
"panics",
"if",
"WriteInt64",
"fails"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L113-L115 |
12,519 | performancecopilot/speed | bytewriter/bytewriter.go | WriteUint32 | func (w *ByteWriter) WriteUint32(val uint32, offset int) (int, error) {
return w.WriteVal(val, offset)
} | go | func (w *ByteWriter) WriteUint32(val uint32, offset int) (int, error) {
return w.WriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"WriteUint32",
"(",
"val",
"uint32",
",",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"w",
".",
"WriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // WriteUint32 writes an uint32 to the buffer | [
"WriteUint32",
"writes",
"an",
"uint32",
"to",
"the",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L118-L120 |
12,520 | performancecopilot/speed | bytewriter/bytewriter.go | MustWriteUint32 | func (w *ByteWriter) MustWriteUint32(val uint32, offset int) int {
return w.MustWriteVal(val, offset)
} | go | func (w *ByteWriter) MustWriteUint32(val uint32, offset int) int {
return w.MustWriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWriteUint32",
"(",
"val",
"uint32",
",",
"offset",
"int",
")",
"int",
"{",
"return",
"w",
".",
"MustWriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // MustWriteUint32 panics if WriteInt32 fails | [
"MustWriteUint32",
"panics",
"if",
"WriteInt32",
"fails"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L123-L125 |
12,521 | performancecopilot/speed | bytewriter/bytewriter.go | WriteUint64 | func (w *ByteWriter) WriteUint64(val uint64, offset int) (int, error) {
return w.WriteVal(val, offset)
} | go | func (w *ByteWriter) WriteUint64(val uint64, offset int) (int, error) {
return w.WriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"WriteUint64",
"(",
"val",
"uint64",
",",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"w",
".",
"WriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // WriteUint64 writes an uint64 to the buffer | [
"WriteUint64",
"writes",
"an",
"uint64",
"to",
"the",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L128-L130 |
12,522 | performancecopilot/speed | bytewriter/bytewriter.go | MustWriteUint64 | func (w *ByteWriter) MustWriteUint64(val uint64, offset int) int {
return w.MustWriteVal(val, offset)
} | go | func (w *ByteWriter) MustWriteUint64(val uint64, offset int) int {
return w.MustWriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWriteUint64",
"(",
"val",
"uint64",
",",
"offset",
"int",
")",
"int",
"{",
"return",
"w",
".",
"MustWriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // MustWriteUint64 panics if WriteUint64 fails | [
"MustWriteUint64",
"panics",
"if",
"WriteUint64",
"fails"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L133-L135 |
12,523 | performancecopilot/speed | bytewriter/bytewriter.go | WriteFloat32 | func (w *ByteWriter) WriteFloat32(val float32, offset int) (int, error) {
return w.WriteVal(val, offset)
} | go | func (w *ByteWriter) WriteFloat32(val float32, offset int) (int, error) {
return w.WriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"WriteFloat32",
"(",
"val",
"float32",
",",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"w",
".",
"WriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // WriteFloat32 writes an float32 to the buffer | [
"WriteFloat32",
"writes",
"an",
"float32",
"to",
"the",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L138-L140 |
12,524 | performancecopilot/speed | bytewriter/bytewriter.go | MustWriteFloat32 | func (w *ByteWriter) MustWriteFloat32(val float32, offset int) int {
return w.MustWriteVal(val, offset)
} | go | func (w *ByteWriter) MustWriteFloat32(val float32, offset int) int {
return w.MustWriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWriteFloat32",
"(",
"val",
"float32",
",",
"offset",
"int",
")",
"int",
"{",
"return",
"w",
".",
"MustWriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // MustWriteFloat32 panics if WriteFloat32 fails | [
"MustWriteFloat32",
"panics",
"if",
"WriteFloat32",
"fails"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L143-L145 |
12,525 | performancecopilot/speed | bytewriter/bytewriter.go | WriteFloat64 | func (w *ByteWriter) WriteFloat64(val float64, offset int) (int, error) {
return w.WriteVal(val, offset)
} | go | func (w *ByteWriter) WriteFloat64(val float64, offset int) (int, error) {
return w.WriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"WriteFloat64",
"(",
"val",
"float64",
",",
"offset",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"w",
".",
"WriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // WriteFloat64 writes an float64 to the buffer | [
"WriteFloat64",
"writes",
"an",
"float64",
"to",
"the",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L148-L150 |
12,526 | performancecopilot/speed | bytewriter/bytewriter.go | MustWriteFloat64 | func (w *ByteWriter) MustWriteFloat64(val float64, offset int) int {
return w.MustWriteVal(val, offset)
} | go | func (w *ByteWriter) MustWriteFloat64(val float64, offset int) int {
return w.MustWriteVal(val, offset)
} | [
"func",
"(",
"w",
"*",
"ByteWriter",
")",
"MustWriteFloat64",
"(",
"val",
"float64",
",",
"offset",
"int",
")",
"int",
"{",
"return",
"w",
".",
"MustWriteVal",
"(",
"val",
",",
"offset",
")",
"\n",
"}"
] | // MustWriteFloat64 panics if WriteFloat64 fails | [
"MustWriteFloat64",
"panics",
"if",
"WriteFloat64",
"fails"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/bytewriter.go#L153-L155 |
12,527 | performancecopilot/speed | mmvdump/writer.go | Write | func Write(
w io.Writer,
header *Header,
tocs []*Toc,
metrics map[uint64]Metric,
values map[uint64]*Value,
instances map[uint64]Instance,
indoms map[uint64]*InstanceDomain,
strings map[uint64]*String,
) error {
if _, err := fmt.Fprintf(w, `Version = %v
Generated = %v
Toc Count = %v
Cluster = %v
Process = %v
Flags = 0x%x
`, header.Version, header.G1, header.Toc, header.Cluster, header.Process, int(header.Flag)); err != nil {
return err
}
return writeComponents(w, header, tocs, metrics, values, instances, indoms, strings)
} | go | func Write(
w io.Writer,
header *Header,
tocs []*Toc,
metrics map[uint64]Metric,
values map[uint64]*Value,
instances map[uint64]Instance,
indoms map[uint64]*InstanceDomain,
strings map[uint64]*String,
) error {
if _, err := fmt.Fprintf(w, `Version = %v
Generated = %v
Toc Count = %v
Cluster = %v
Process = %v
Flags = 0x%x
`, header.Version, header.G1, header.Toc, header.Cluster, header.Process, int(header.Flag)); err != nil {
return err
}
return writeComponents(w, header, tocs, metrics, values, instances, indoms, strings)
} | [
"func",
"Write",
"(",
"w",
"io",
".",
"Writer",
",",
"header",
"*",
"Header",
",",
"tocs",
"[",
"]",
"*",
"Toc",
",",
"metrics",
"map",
"[",
"uint64",
"]",
"Metric",
",",
"values",
"map",
"[",
"uint64",
"]",
"*",
"Value",
",",
"instances",
"map",
"[",
"uint64",
"]",
"Instance",
",",
"indoms",
"map",
"[",
"uint64",
"]",
"*",
"InstanceDomain",
",",
"strings",
"map",
"[",
"uint64",
"]",
"*",
"String",
",",
")",
"error",
"{",
"if",
"_",
",",
"err",
":=",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"`Version = %v\nGenerated = %v\nToc Count = %v\nCluster = %v\nProcess = %v\nFlags = 0x%x\n\n`",
",",
"header",
".",
"Version",
",",
"header",
".",
"G1",
",",
"header",
".",
"Toc",
",",
"header",
".",
"Cluster",
",",
"header",
".",
"Process",
",",
"int",
"(",
"header",
".",
"Flag",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"writeComponents",
"(",
"w",
",",
"header",
",",
"tocs",
",",
"metrics",
",",
"values",
",",
"instances",
",",
"indoms",
",",
"strings",
")",
"\n",
"}"
] | // Write creates a writable representation of a MMV dump
// and writes it to the passed writer. | [
"Write",
"creates",
"a",
"writable",
"representation",
"of",
"a",
"MMV",
"dump",
"and",
"writes",
"it",
"to",
"the",
"passed",
"writer",
"."
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/mmvdump/writer.go#L252-L274 |
12,528 | performancecopilot/speed | instance_domain.go | HasInstance | func (indom *PCPInstanceDomain) HasInstance(name string) bool {
_, present := indom.instances[name]
return present
} | go | func (indom *PCPInstanceDomain) HasInstance(name string) bool {
_, present := indom.instances[name]
return present
} | [
"func",
"(",
"indom",
"*",
"PCPInstanceDomain",
")",
"HasInstance",
"(",
"name",
"string",
")",
"bool",
"{",
"_",
",",
"present",
":=",
"indom",
".",
"instances",
"[",
"name",
"]",
"\n",
"return",
"present",
"\n",
"}"
] | // HasInstance returns true if an instance of the specified name is in the Indom | [
"HasInstance",
"returns",
"true",
"if",
"an",
"instance",
"of",
"the",
"specified",
"name",
"is",
"in",
"the",
"Indom"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/instance_domain.go#L75-L78 |
12,529 | performancecopilot/speed | instance_domain.go | Instances | func (indom *PCPInstanceDomain) Instances() []string {
ans, i := make([]string, len(indom.instances)), 0
for k := range indom.instances {
ans[i] = k
i++
}
return ans
} | go | func (indom *PCPInstanceDomain) Instances() []string {
ans, i := make([]string, len(indom.instances)), 0
for k := range indom.instances {
ans[i] = k
i++
}
return ans
} | [
"func",
"(",
"indom",
"*",
"PCPInstanceDomain",
")",
"Instances",
"(",
")",
"[",
"]",
"string",
"{",
"ans",
",",
"i",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"indom",
".",
"instances",
")",
")",
",",
"0",
"\n",
"for",
"k",
":=",
"range",
"indom",
".",
"instances",
"{",
"ans",
"[",
"i",
"]",
"=",
"k",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"return",
"ans",
"\n",
"}"
] | // Instances returns a slice of defined instances for the instance domain | [
"Instances",
"returns",
"a",
"slice",
"of",
"defined",
"instances",
"for",
"the",
"instance",
"domain"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/instance_domain.go#L92-L99 |
12,530 | performancecopilot/speed | instance_domain.go | MatchInstances | func (indom *PCPInstanceDomain) MatchInstances(ins []string) bool {
if len(ins) != len(indom.instances) {
return false
}
for _, i := range ins {
if _, ok := indom.instances[i]; !ok {
return false
}
}
return true
} | go | func (indom *PCPInstanceDomain) MatchInstances(ins []string) bool {
if len(ins) != len(indom.instances) {
return false
}
for _, i := range ins {
if _, ok := indom.instances[i]; !ok {
return false
}
}
return true
} | [
"func",
"(",
"indom",
"*",
"PCPInstanceDomain",
")",
"MatchInstances",
"(",
"ins",
"[",
"]",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"ins",
")",
"!=",
"len",
"(",
"indom",
".",
"instances",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"i",
":=",
"range",
"ins",
"{",
"if",
"_",
",",
"ok",
":=",
"indom",
".",
"instances",
"[",
"i",
"]",
";",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // MatchInstances returns true if the passed InstanceDomain
// has exactly the same instances as the passed array | [
"MatchInstances",
"returns",
"true",
"if",
"the",
"passed",
"InstanceDomain",
"has",
"exactly",
"the",
"same",
"instances",
"as",
"the",
"passed",
"array"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/instance_domain.go#L103-L115 |
12,531 | performancecopilot/speed | bytewriter/memorymappedwriter.go | NewMemoryMappedWriter | func NewMemoryMappedWriter(loc string, size int) (*MemoryMappedWriter, error) {
if _, err := os.Stat(loc); err == nil {
err = os.Remove(loc)
if err != nil {
return nil, err
}
}
// ensure destination directory exists
dir := filepath.Dir(loc)
err := os.MkdirAll(dir, 0700)
if err != nil {
return nil, err
}
f, err := os.OpenFile(loc, os.O_CREATE|os.O_RDWR|os.O_EXCL, 0644)
if err != nil {
return nil, err
}
l, err := f.Write(make([]byte, size))
if err != nil {
return nil, err
}
if l < size {
return nil, errors.Errorf("Could not initialize %d bytes", size)
}
b, err := mmap.Map(f, mmap.RDWR, 0)
if err != nil {
return nil, err
}
return &MemoryMappedWriter{
NewByteWriterSlice(b),
f,
loc,
size,
}, nil
} | go | func NewMemoryMappedWriter(loc string, size int) (*MemoryMappedWriter, error) {
if _, err := os.Stat(loc); err == nil {
err = os.Remove(loc)
if err != nil {
return nil, err
}
}
// ensure destination directory exists
dir := filepath.Dir(loc)
err := os.MkdirAll(dir, 0700)
if err != nil {
return nil, err
}
f, err := os.OpenFile(loc, os.O_CREATE|os.O_RDWR|os.O_EXCL, 0644)
if err != nil {
return nil, err
}
l, err := f.Write(make([]byte, size))
if err != nil {
return nil, err
}
if l < size {
return nil, errors.Errorf("Could not initialize %d bytes", size)
}
b, err := mmap.Map(f, mmap.RDWR, 0)
if err != nil {
return nil, err
}
return &MemoryMappedWriter{
NewByteWriterSlice(b),
f,
loc,
size,
}, nil
} | [
"func",
"NewMemoryMappedWriter",
"(",
"loc",
"string",
",",
"size",
"int",
")",
"(",
"*",
"MemoryMappedWriter",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"loc",
")",
";",
"err",
"==",
"nil",
"{",
"err",
"=",
"os",
".",
"Remove",
"(",
"loc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// ensure destination directory exists",
"dir",
":=",
"filepath",
".",
"Dir",
"(",
"loc",
")",
"\n",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"dir",
",",
"0700",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"loc",
",",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_RDWR",
"|",
"os",
".",
"O_EXCL",
",",
"0644",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"l",
",",
"err",
":=",
"f",
".",
"Write",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"l",
"<",
"size",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"size",
")",
"\n",
"}",
"\n\n",
"b",
",",
"err",
":=",
"mmap",
".",
"Map",
"(",
"f",
",",
"mmap",
".",
"RDWR",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"MemoryMappedWriter",
"{",
"NewByteWriterSlice",
"(",
"b",
")",
",",
"f",
",",
"loc",
",",
"size",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewMemoryMappedWriter will create and return a new instance of a MemoryMappedWriter | [
"NewMemoryMappedWriter",
"will",
"create",
"and",
"return",
"a",
"new",
"instance",
"of",
"a",
"MemoryMappedWriter"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/memorymappedwriter.go#L20-L59 |
12,532 | performancecopilot/speed | bytewriter/memorymappedwriter.go | Unmap | func (b *MemoryMappedWriter) Unmap(removefile bool) error {
m := mmap.MMap(b.buffer)
if err := m.Unmap(); err != nil {
return err
}
if err := b.handle.Close(); err != nil {
return err
}
if removefile {
if err := os.Remove(b.loc); err != nil {
return err
}
}
return nil
} | go | func (b *MemoryMappedWriter) Unmap(removefile bool) error {
m := mmap.MMap(b.buffer)
if err := m.Unmap(); err != nil {
return err
}
if err := b.handle.Close(); err != nil {
return err
}
if removefile {
if err := os.Remove(b.loc); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"b",
"*",
"MemoryMappedWriter",
")",
"Unmap",
"(",
"removefile",
"bool",
")",
"error",
"{",
"m",
":=",
"mmap",
".",
"MMap",
"(",
"b",
".",
"buffer",
")",
"\n",
"if",
"err",
":=",
"m",
".",
"Unmap",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"b",
".",
"handle",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"removefile",
"{",
"if",
"err",
":=",
"os",
".",
"Remove",
"(",
"b",
".",
"loc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Unmap will manually delete the memory mapping of a mapped buffer | [
"Unmap",
"will",
"manually",
"delete",
"the",
"memory",
"mapping",
"of",
"a",
"mapped",
"buffer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/bytewriter/memorymappedwriter.go#L62-L79 |
12,533 | performancecopilot/speed | client.go | NewPCPClientWithRegistry | func NewPCPClientWithRegistry(name string, registry *PCPRegistry) (*PCPClient, error) {
fileLocation, err := mmvFileLocation(name)
if err != nil {
return nil, errors.Wrap(err, "could not get a location for storing MMV file")
}
return &PCPClient{
loc: fileLocation,
r: registry,
clusterID: hash(name, PCPClusterIDBitLength),
flag: ProcessFlag,
}, nil
} | go | func NewPCPClientWithRegistry(name string, registry *PCPRegistry) (*PCPClient, error) {
fileLocation, err := mmvFileLocation(name)
if err != nil {
return nil, errors.Wrap(err, "could not get a location for storing MMV file")
}
return &PCPClient{
loc: fileLocation,
r: registry,
clusterID: hash(name, PCPClusterIDBitLength),
flag: ProcessFlag,
}, nil
} | [
"func",
"NewPCPClientWithRegistry",
"(",
"name",
"string",
",",
"registry",
"*",
"PCPRegistry",
")",
"(",
"*",
"PCPClient",
",",
"error",
")",
"{",
"fileLocation",
",",
"err",
":=",
"mmvFileLocation",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"PCPClient",
"{",
"loc",
":",
"fileLocation",
",",
"r",
":",
"registry",
",",
"clusterID",
":",
"hash",
"(",
"name",
",",
"PCPClusterIDBitLength",
")",
",",
"flag",
":",
"ProcessFlag",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewPCPClientWithRegistry initializes a new PCPClient object with the given registry | [
"NewPCPClientWithRegistry",
"initializes",
"a",
"new",
"PCPClient",
"object",
"with",
"the",
"given",
"registry"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L127-L139 |
12,534 | performancecopilot/speed | client.go | SetFlag | func (c *PCPClient) SetFlag(flag MMVFlag) error {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.r.mapped {
return errors.New("cannot set mmv flag for an active client")
}
c.flag = flag
return nil
} | go | func (c *PCPClient) SetFlag(flag MMVFlag) error {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.r.mapped {
return errors.New("cannot set mmv flag for an active client")
}
c.flag = flag
return nil
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"SetFlag",
"(",
"flag",
"MMVFlag",
")",
"error",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"r",
".",
"mapped",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
".",
"flag",
"=",
"flag",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetFlag sets the MMVflag for the client | [
"SetFlag",
"sets",
"the",
"MMVflag",
"for",
"the",
"client"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L147-L157 |
12,535 | performancecopilot/speed | client.go | Length | func (c *PCPClient) Length() int {
var (
InstanceLength = Instance1Length
MetricLength = Metric1Length
)
if c.r.version2 {
InstanceLength = Instance2Length
MetricLength = Metric2Length
}
return HeaderLength +
(c.tocCount() * TocLength) +
(c.r.InstanceCount() * InstanceLength) +
(c.r.InstanceDomainCount() * InstanceDomainLength) +
(c.r.MetricCount() * MetricLength) +
(c.r.ValuesCount() * ValueLength) +
(c.r.StringCount() * StringLength)
} | go | func (c *PCPClient) Length() int {
var (
InstanceLength = Instance1Length
MetricLength = Metric1Length
)
if c.r.version2 {
InstanceLength = Instance2Length
MetricLength = Metric2Length
}
return HeaderLength +
(c.tocCount() * TocLength) +
(c.r.InstanceCount() * InstanceLength) +
(c.r.InstanceDomainCount() * InstanceDomainLength) +
(c.r.MetricCount() * MetricLength) +
(c.r.ValuesCount() * ValueLength) +
(c.r.StringCount() * StringLength)
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"Length",
"(",
")",
"int",
"{",
"var",
"(",
"InstanceLength",
"=",
"Instance1Length",
"\n",
"MetricLength",
"=",
"Metric1Length",
"\n",
")",
"\n\n",
"if",
"c",
".",
"r",
".",
"version2",
"{",
"InstanceLength",
"=",
"Instance2Length",
"\n",
"MetricLength",
"=",
"Metric2Length",
"\n",
"}",
"\n\n",
"return",
"HeaderLength",
"+",
"(",
"c",
".",
"tocCount",
"(",
")",
"*",
"TocLength",
")",
"+",
"(",
"c",
".",
"r",
".",
"InstanceCount",
"(",
")",
"*",
"InstanceLength",
")",
"+",
"(",
"c",
".",
"r",
".",
"InstanceDomainCount",
"(",
")",
"*",
"InstanceDomainLength",
")",
"+",
"(",
"c",
".",
"r",
".",
"MetricCount",
"(",
")",
"*",
"MetricLength",
")",
"+",
"(",
"c",
".",
"r",
".",
"ValuesCount",
"(",
")",
"*",
"ValueLength",
")",
"+",
"(",
"c",
".",
"r",
".",
"StringCount",
"(",
")",
"*",
"StringLength",
")",
"\n",
"}"
] | // Length returns the byte length of data in the mmv file written by the current writer | [
"Length",
"returns",
"the",
"byte",
"length",
"of",
"data",
"in",
"the",
"mmv",
"file",
"written",
"by",
"the",
"current",
"writer"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L174-L192 |
12,536 | performancecopilot/speed | client.go | Start | func (c *PCPClient) Start() error {
c.mutex.Lock()
defer c.mutex.Unlock()
l := c.Length()
writer, err := bytewriter.NewMemoryMappedWriter(c.loc, l)
if err != nil {
return errors.Wrap(err, "cannot create MemoryMappedBuffer in client")
}
c.writer = writer
c.start()
c.r.mapped = true
return nil
} | go | func (c *PCPClient) Start() error {
c.mutex.Lock()
defer c.mutex.Unlock()
l := c.Length()
writer, err := bytewriter.NewMemoryMappedWriter(c.loc, l)
if err != nil {
return errors.Wrap(err, "cannot create MemoryMappedBuffer in client")
}
c.writer = writer
c.start()
c.r.mapped = true
return nil
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"Start",
"(",
")",
"error",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"l",
":=",
"c",
".",
"Length",
"(",
")",
"\n\n",
"writer",
",",
"err",
":=",
"bytewriter",
".",
"NewMemoryMappedWriter",
"(",
"c",
".",
"loc",
",",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
".",
"writer",
"=",
"writer",
"\n",
"c",
".",
"start",
"(",
")",
"\n",
"c",
".",
"r",
".",
"mapped",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] | // Start dumps existing registry data | [
"Start",
"dumps",
"existing",
"registry",
"data"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L195-L210 |
12,537 | performancecopilot/speed | client.go | MustStart | func (c *PCPClient) MustStart() {
if err := c.Start(); err != nil {
panic(err)
}
} | go | func (c *PCPClient) MustStart() {
if err := c.Start(); err != nil {
panic(err)
}
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"MustStart",
"(",
")",
"{",
"if",
"err",
":=",
"c",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // MustStart is a start that panics | [
"MustStart",
"is",
"a",
"start",
"that",
"panics"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L620-L624 |
12,538 | performancecopilot/speed | client.go | Stop | func (c *PCPClient) Stop() error {
c.mutex.Lock()
defer c.mutex.Unlock()
if !c.r.mapped {
return errors.New("trying to stop an already stopped mapping")
}
c.stop()
c.r.mapped = false
err := c.writer.(*bytewriter.MemoryMappedWriter).Unmap(EraseFileOnStop)
c.writer = nil
if err != nil {
return errors.Wrap(err, "client: error unmapping MemoryMappedBuffer")
}
return nil
} | go | func (c *PCPClient) Stop() error {
c.mutex.Lock()
defer c.mutex.Unlock()
if !c.r.mapped {
return errors.New("trying to stop an already stopped mapping")
}
c.stop()
c.r.mapped = false
err := c.writer.(*bytewriter.MemoryMappedWriter).Unmap(EraseFileOnStop)
c.writer = nil
if err != nil {
return errors.Wrap(err, "client: error unmapping MemoryMappedBuffer")
}
return nil
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"Stop",
"(",
")",
"error",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"!",
"c",
".",
"r",
".",
"mapped",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
".",
"stop",
"(",
")",
"\n\n",
"c",
".",
"r",
".",
"mapped",
"=",
"false",
"\n\n",
"err",
":=",
"c",
".",
"writer",
".",
"(",
"*",
"bytewriter",
".",
"MemoryMappedWriter",
")",
".",
"Unmap",
"(",
"EraseFileOnStop",
")",
"\n",
"c",
".",
"writer",
"=",
"nil",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Stop removes existing mapping and cleans up | [
"Stop",
"removes",
"existing",
"mapping",
"and",
"cleans",
"up"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L627-L646 |
12,539 | performancecopilot/speed | client.go | MustStop | func (c *PCPClient) MustStop() {
if err := c.Stop(); err != nil {
panic(err)
}
} | go | func (c *PCPClient) MustStop() {
if err := c.Stop(); err != nil {
panic(err)
}
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"MustStop",
"(",
")",
"{",
"if",
"err",
":=",
"c",
".",
"Stop",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // MustStop is a stop that panics | [
"MustStop",
"is",
"a",
"stop",
"that",
"panics"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L655-L659 |
12,540 | performancecopilot/speed | client.go | MustRegister | func (c *PCPClient) MustRegister(m Metric) {
if err := c.Register(m); err != nil {
panic(err)
}
} | go | func (c *PCPClient) MustRegister(m Metric) {
if err := c.Register(m); err != nil {
panic(err)
}
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"MustRegister",
"(",
"m",
"Metric",
")",
"{",
"if",
"err",
":=",
"c",
".",
"Register",
"(",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // MustRegister is simply a Register that can panic | [
"MustRegister",
"is",
"simply",
"a",
"Register",
"that",
"can",
"panic"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L665-L669 |
12,541 | performancecopilot/speed | client.go | MustRegisterIndom | func (c *PCPClient) MustRegisterIndom(indom InstanceDomain) {
if err := c.RegisterIndom(indom); err != nil {
panic(err)
}
} | go | func (c *PCPClient) MustRegisterIndom(indom InstanceDomain) {
if err := c.RegisterIndom(indom); err != nil {
panic(err)
}
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"MustRegisterIndom",
"(",
"indom",
"InstanceDomain",
")",
"{",
"if",
"err",
":=",
"c",
".",
"RegisterIndom",
"(",
"indom",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // MustRegisterIndom is simply a RegisterIndom that can panic | [
"MustRegisterIndom",
"is",
"simply",
"a",
"RegisterIndom",
"that",
"can",
"panic"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L677-L681 |
12,542 | performancecopilot/speed | client.go | MustRegisterString | func (c *PCPClient) MustRegisterString(str string, val interface{}, t MetricType, s MetricSemantics, u MetricUnit) Metric {
if m, err := c.RegisterString(str, val, t, s, u); err != nil {
panic(err)
} else {
return m
}
} | go | func (c *PCPClient) MustRegisterString(str string, val interface{}, t MetricType, s MetricSemantics, u MetricUnit) Metric {
if m, err := c.RegisterString(str, val, t, s, u); err != nil {
panic(err)
} else {
return m
}
} | [
"func",
"(",
"c",
"*",
"PCPClient",
")",
"MustRegisterString",
"(",
"str",
"string",
",",
"val",
"interface",
"{",
"}",
",",
"t",
"MetricType",
",",
"s",
"MetricSemantics",
",",
"u",
"MetricUnit",
")",
"Metric",
"{",
"if",
"m",
",",
"err",
":=",
"c",
".",
"RegisterString",
"(",
"str",
",",
"val",
",",
"t",
",",
"s",
",",
"u",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"return",
"m",
"\n",
"}",
"\n",
"}"
] | // MustRegisterString is simply a RegisterString that panics | [
"MustRegisterString",
"is",
"simply",
"a",
"RegisterString",
"that",
"panics"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/client.go#L689-L695 |
12,543 | performancecopilot/speed | config.go | initConfig | func initConfig() error {
re, _ := regexp.Compile(pat)
r, ok := os.LookupEnv("PCP_DIR")
if !ok {
r = "/"
}
rootPath = r
c, ok := os.LookupEnv("PCP_CONF")
if !ok {
c = filepath.Join(rootPath, "etc", "pcp.conf")
}
confPath = c
f, err := os.Open(confPath)
if err != nil {
return err
}
// if we reach at this point, it means we have a valid config
// that can be read, so we can make the map non-nil
config = make(map[string]string)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
t := scanner.Text()
if re.MatchString(t) {
matches := re.FindStringSubmatch(t)
config[matches[1]] = matches[2]
}
}
return nil
} | go | func initConfig() error {
re, _ := regexp.Compile(pat)
r, ok := os.LookupEnv("PCP_DIR")
if !ok {
r = "/"
}
rootPath = r
c, ok := os.LookupEnv("PCP_CONF")
if !ok {
c = filepath.Join(rootPath, "etc", "pcp.conf")
}
confPath = c
f, err := os.Open(confPath)
if err != nil {
return err
}
// if we reach at this point, it means we have a valid config
// that can be read, so we can make the map non-nil
config = make(map[string]string)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
t := scanner.Text()
if re.MatchString(t) {
matches := re.FindStringSubmatch(t)
config[matches[1]] = matches[2]
}
}
return nil
} | [
"func",
"initConfig",
"(",
")",
"error",
"{",
"re",
",",
"_",
":=",
"regexp",
".",
"Compile",
"(",
"pat",
")",
"\n\n",
"r",
",",
"ok",
":=",
"os",
".",
"LookupEnv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"ok",
"{",
"r",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"rootPath",
"=",
"r",
"\n\n",
"c",
",",
"ok",
":=",
"os",
".",
"LookupEnv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"ok",
"{",
"c",
"=",
"filepath",
".",
"Join",
"(",
"rootPath",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"confPath",
"=",
"c",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"confPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// if we reach at this point, it means we have a valid config",
"// that can be read, so we can make the map non-nil",
"config",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"f",
")",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"t",
":=",
"scanner",
".",
"Text",
"(",
")",
"\n",
"if",
"re",
".",
"MatchString",
"(",
"t",
")",
"{",
"matches",
":=",
"re",
".",
"FindStringSubmatch",
"(",
"t",
")",
"\n",
"config",
"[",
"matches",
"[",
"1",
"]",
"]",
"=",
"matches",
"[",
"2",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // initConfig initializes the config constants | [
"initConfig",
"initializes",
"the",
"config",
"constants"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/config.go#L23-L56 |
12,544 | performancecopilot/speed | instance.go | Keys | func (i Instances) Keys() []string {
s := make([]string, 0, len(i))
for k := range i {
s = append(s, k)
}
return s
} | go | func (i Instances) Keys() []string {
s := make([]string, 0, len(i))
for k := range i {
s = append(s, k)
}
return s
} | [
"func",
"(",
"i",
"Instances",
")",
"Keys",
"(",
")",
"[",
"]",
"string",
"{",
"s",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"i",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"i",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"k",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // Keys collects and returns all the keys in all instance values | [
"Keys",
"collects",
"and",
"returns",
"all",
"the",
"keys",
"in",
"all",
"instance",
"values"
] | 22ca883d94397b1f6c7a2ab155d9972af6b26813 | https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/instance.go#L7-L13 |
12,545 | kataras/go-websocket | client.go | ClientHandler | func ClientHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/javascript")
_, err := w.Write(ClientSource)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
w.WriteHeader(http.StatusInternalServerError)
}
} | go | func ClientHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/javascript")
_, err := w.Write(ClientSource)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
w.WriteHeader(http.StatusInternalServerError)
}
} | [
"func",
"ClientHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"ClientSource",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}",
"\n",
"}"
] | // ClientHandler is the handler which serves the javascript client-side.
// It can be used as an alternative of a custom http route to register the client-side javascript code,
// Use the Server's `ClientSource` field instead to serve the custom code if you changed the default prefix for custom websocket events. | [
"ClientHandler",
"is",
"the",
"handler",
"which",
"serves",
"the",
"javascript",
"client",
"-",
"side",
".",
"It",
"can",
"be",
"used",
"as",
"an",
"alternative",
"of",
"a",
"custom",
"http",
"route",
"to",
"register",
"the",
"client",
"-",
"side",
"javascript",
"code",
"Use",
"the",
"Server",
"s",
"ClientSource",
"field",
"instead",
"to",
"serve",
"the",
"custom",
"code",
"if",
"you",
"changed",
"the",
"default",
"prefix",
"for",
"custom",
"websocket",
"events",
"."
] | e70ced2a8314efbd26a5f62e1a3a526948313950 | https://github.com/kataras/go-websocket/blob/e70ced2a8314efbd26a5f62e1a3a526948313950/client.go#L10-L17 |
12,546 | korylprince/go-ad-auth | passwd.go | ModifyDNPassword | func (c *Conn) ModifyDNPassword(dn, newPasswd string) error {
utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
encoded, err := utf16.NewEncoder().String(fmt.Sprintf(`"%s"`, newPasswd))
if err != nil {
return fmt.Errorf("Password error: Unable to encode password: %v", err)
}
req := ldap.NewModifyRequest(dn)
req.Replace("unicodePwd", []string{encoded})
err = c.Conn.Modify(req)
if err != nil {
return fmt.Errorf("Password error: Unable to modify password: %v", err)
}
return nil
} | go | func (c *Conn) ModifyDNPassword(dn, newPasswd string) error {
utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
encoded, err := utf16.NewEncoder().String(fmt.Sprintf(`"%s"`, newPasswd))
if err != nil {
return fmt.Errorf("Password error: Unable to encode password: %v", err)
}
req := ldap.NewModifyRequest(dn)
req.Replace("unicodePwd", []string{encoded})
err = c.Conn.Modify(req)
if err != nil {
return fmt.Errorf("Password error: Unable to modify password: %v", err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ModifyDNPassword",
"(",
"dn",
",",
"newPasswd",
"string",
")",
"error",
"{",
"utf16",
":=",
"unicode",
".",
"UTF16",
"(",
"unicode",
".",
"LittleEndian",
",",
"unicode",
".",
"IgnoreBOM",
")",
"\n",
"encoded",
",",
"err",
":=",
"utf16",
".",
"NewEncoder",
"(",
")",
".",
"String",
"(",
"fmt",
".",
"Sprintf",
"(",
"`\"%s\"`",
",",
"newPasswd",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"req",
":=",
"ldap",
".",
"NewModifyRequest",
"(",
"dn",
")",
"\n",
"req",
".",
"Replace",
"(",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"encoded",
"}",
")",
"\n\n",
"err",
"=",
"c",
".",
"Conn",
".",
"Modify",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | //ModifyDNPassword sets a new password for the given user or returns an error if one occurred.
//ModifyDNPassword is used for resetting user passwords using administrative privileges. | [
"ModifyDNPassword",
"sets",
"a",
"new",
"password",
"for",
"the",
"given",
"user",
"or",
"returns",
"an",
"error",
"if",
"one",
"occurred",
".",
"ModifyDNPassword",
"is",
"used",
"for",
"resetting",
"user",
"passwords",
"using",
"administrative",
"privileges",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/passwd.go#L13-L29 |
12,547 | korylprince/go-ad-auth | passwd.go | UpdatePassword | func UpdatePassword(config *Config, username, oldPasswd, newPasswd string) error {
utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
oldEncoded, err := utf16.NewEncoder().String(fmt.Sprintf(`"%s"`, oldPasswd))
if err != nil {
return fmt.Errorf("Password error: Unable to encode old password: %v", err)
}
newEncoded, err := utf16.NewEncoder().String(fmt.Sprintf(`"%s"`, newPasswd))
if err != nil {
return fmt.Errorf("Password error: Unable to encode new password: %v", err)
}
upn, err := config.UPN(username)
if err != nil {
return err
}
conn, err := config.Connect()
if err != nil {
return err
}
defer conn.Conn.Close()
//bind
status, err := conn.Bind(upn, oldPasswd)
if err != nil {
return err
}
if !status {
return errors.New("Password error: credentials not valid")
}
dn, err := conn.GetDN("userPrincipalName", upn)
if err != nil {
return err
}
req := ldap.NewModifyRequest(dn)
req.Delete("unicodePwd", []string{oldEncoded})
req.Add("unicodePwd", []string{newEncoded})
err = conn.Conn.Modify(req)
if err != nil {
return fmt.Errorf("Password error: Unable to modify password: %v", err)
}
return nil
} | go | func UpdatePassword(config *Config, username, oldPasswd, newPasswd string) error {
utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
oldEncoded, err := utf16.NewEncoder().String(fmt.Sprintf(`"%s"`, oldPasswd))
if err != nil {
return fmt.Errorf("Password error: Unable to encode old password: %v", err)
}
newEncoded, err := utf16.NewEncoder().String(fmt.Sprintf(`"%s"`, newPasswd))
if err != nil {
return fmt.Errorf("Password error: Unable to encode new password: %v", err)
}
upn, err := config.UPN(username)
if err != nil {
return err
}
conn, err := config.Connect()
if err != nil {
return err
}
defer conn.Conn.Close()
//bind
status, err := conn.Bind(upn, oldPasswd)
if err != nil {
return err
}
if !status {
return errors.New("Password error: credentials not valid")
}
dn, err := conn.GetDN("userPrincipalName", upn)
if err != nil {
return err
}
req := ldap.NewModifyRequest(dn)
req.Delete("unicodePwd", []string{oldEncoded})
req.Add("unicodePwd", []string{newEncoded})
err = conn.Conn.Modify(req)
if err != nil {
return fmt.Errorf("Password error: Unable to modify password: %v", err)
}
return nil
} | [
"func",
"UpdatePassword",
"(",
"config",
"*",
"Config",
",",
"username",
",",
"oldPasswd",
",",
"newPasswd",
"string",
")",
"error",
"{",
"utf16",
":=",
"unicode",
".",
"UTF16",
"(",
"unicode",
".",
"LittleEndian",
",",
"unicode",
".",
"IgnoreBOM",
")",
"\n",
"oldEncoded",
",",
"err",
":=",
"utf16",
".",
"NewEncoder",
"(",
")",
".",
"String",
"(",
"fmt",
".",
"Sprintf",
"(",
"`\"%s\"`",
",",
"oldPasswd",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"newEncoded",
",",
"err",
":=",
"utf16",
".",
"NewEncoder",
"(",
")",
".",
"String",
"(",
"fmt",
".",
"Sprintf",
"(",
"`\"%s\"`",
",",
"newPasswd",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"upn",
",",
"err",
":=",
"config",
".",
"UPN",
"(",
"username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"conn",
",",
"err",
":=",
"config",
".",
"Connect",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Conn",
".",
"Close",
"(",
")",
"\n\n",
"//bind",
"status",
",",
"err",
":=",
"conn",
".",
"Bind",
"(",
"upn",
",",
"oldPasswd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"status",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"dn",
",",
"err",
":=",
"conn",
".",
"GetDN",
"(",
"\"",
"\"",
",",
"upn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"req",
":=",
"ldap",
".",
"NewModifyRequest",
"(",
"dn",
")",
"\n",
"req",
".",
"Delete",
"(",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"oldEncoded",
"}",
")",
"\n",
"req",
".",
"Add",
"(",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"newEncoded",
"}",
")",
"\n\n",
"err",
"=",
"conn",
".",
"Conn",
".",
"Modify",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | //UpdatePassword checks if the given credentials are valid and updates the password if they are,
//or returns an error if one occurred. UpdatePassword is used for users resetting their own password. | [
"UpdatePassword",
"checks",
"if",
"the",
"given",
"credentials",
"are",
"valid",
"and",
"updates",
"the",
"password",
"if",
"they",
"are",
"or",
"returns",
"an",
"error",
"if",
"one",
"occurred",
".",
"UpdatePassword",
"is",
"used",
"for",
"users",
"resetting",
"their",
"own",
"password",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/passwd.go#L33-L80 |
12,548 | korylprince/go-ad-auth | search.go | Search | func (c *Conn) Search(filter string, attrs []string, sizeLimit int) ([]*ldap.Entry, error) {
search := ldap.NewSearchRequest(
c.Config.BaseDN,
ldap.ScopeWholeSubtree,
ldap.DerefAlways,
sizeLimit,
0,
false,
filter,
attrs,
nil,
)
result, err := c.Conn.Search(search)
if err != nil {
return nil, fmt.Errorf(`Search error "%s": %v`, filter, err)
}
return result.Entries, nil
} | go | func (c *Conn) Search(filter string, attrs []string, sizeLimit int) ([]*ldap.Entry, error) {
search := ldap.NewSearchRequest(
c.Config.BaseDN,
ldap.ScopeWholeSubtree,
ldap.DerefAlways,
sizeLimit,
0,
false,
filter,
attrs,
nil,
)
result, err := c.Conn.Search(search)
if err != nil {
return nil, fmt.Errorf(`Search error "%s": %v`, filter, err)
}
return result.Entries, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Search",
"(",
"filter",
"string",
",",
"attrs",
"[",
"]",
"string",
",",
"sizeLimit",
"int",
")",
"(",
"[",
"]",
"*",
"ldap",
".",
"Entry",
",",
"error",
")",
"{",
"search",
":=",
"ldap",
".",
"NewSearchRequest",
"(",
"c",
".",
"Config",
".",
"BaseDN",
",",
"ldap",
".",
"ScopeWholeSubtree",
",",
"ldap",
".",
"DerefAlways",
",",
"sizeLimit",
",",
"0",
",",
"false",
",",
"filter",
",",
"attrs",
",",
"nil",
",",
")",
"\n",
"result",
",",
"err",
":=",
"c",
".",
"Conn",
".",
"Search",
"(",
"search",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"`Search error \"%s\": %v`",
",",
"filter",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"result",
".",
"Entries",
",",
"nil",
"\n",
"}"
] | //Search returns the entries for the given search criteria or an error if one occurred. | [
"Search",
"returns",
"the",
"entries",
"for",
"the",
"given",
"search",
"criteria",
"or",
"an",
"error",
"if",
"one",
"occurred",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/search.go#L10-L28 |
12,549 | korylprince/go-ad-auth | search.go | SearchOne | func (c *Conn) SearchOne(filter string, attrs []string) (*ldap.Entry, error) {
search := ldap.NewSearchRequest(
c.Config.BaseDN,
ldap.ScopeWholeSubtree,
ldap.DerefAlways,
1,
0,
false,
filter,
attrs,
nil,
)
result, err := c.Conn.Search(search)
if err != nil {
if e, ok := err.(*ldap.Error); ok {
if e.ResultCode == ldap.LDAPResultSizeLimitExceeded {
return nil, fmt.Errorf(`Search error "%s": more than one entries returned`, filter)
}
}
return nil, fmt.Errorf(`Search error "%s": %v`, filter, err)
}
if len(result.Entries) == 0 {
return nil, fmt.Errorf(`Search error "%s": no entries returned`, filter)
}
return result.Entries[0], nil
} | go | func (c *Conn) SearchOne(filter string, attrs []string) (*ldap.Entry, error) {
search := ldap.NewSearchRequest(
c.Config.BaseDN,
ldap.ScopeWholeSubtree,
ldap.DerefAlways,
1,
0,
false,
filter,
attrs,
nil,
)
result, err := c.Conn.Search(search)
if err != nil {
if e, ok := err.(*ldap.Error); ok {
if e.ResultCode == ldap.LDAPResultSizeLimitExceeded {
return nil, fmt.Errorf(`Search error "%s": more than one entries returned`, filter)
}
}
return nil, fmt.Errorf(`Search error "%s": %v`, filter, err)
}
if len(result.Entries) == 0 {
return nil, fmt.Errorf(`Search error "%s": no entries returned`, filter)
}
return result.Entries[0], nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SearchOne",
"(",
"filter",
"string",
",",
"attrs",
"[",
"]",
"string",
")",
"(",
"*",
"ldap",
".",
"Entry",
",",
"error",
")",
"{",
"search",
":=",
"ldap",
".",
"NewSearchRequest",
"(",
"c",
".",
"Config",
".",
"BaseDN",
",",
"ldap",
".",
"ScopeWholeSubtree",
",",
"ldap",
".",
"DerefAlways",
",",
"1",
",",
"0",
",",
"false",
",",
"filter",
",",
"attrs",
",",
"nil",
",",
")",
"\n\n",
"result",
",",
"err",
":=",
"c",
".",
"Conn",
".",
"Search",
"(",
"search",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"ldap",
".",
"Error",
")",
";",
"ok",
"{",
"if",
"e",
".",
"ResultCode",
"==",
"ldap",
".",
"LDAPResultSizeLimitExceeded",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"`Search error \"%s\": more than one entries returned`",
",",
"filter",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"`Search error \"%s\": %v`",
",",
"filter",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"result",
".",
"Entries",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"`Search error \"%s\": no entries returned`",
",",
"filter",
")",
"\n",
"}",
"\n\n",
"return",
"result",
".",
"Entries",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | //SearchOne returns the single entry for the given search criteria or an error if one occurred.
//An error is returned if exactly one entry is not returned. | [
"SearchOne",
"returns",
"the",
"single",
"entry",
"for",
"the",
"given",
"search",
"criteria",
"or",
"an",
"error",
"if",
"one",
"occurred",
".",
"An",
"error",
"is",
"returned",
"if",
"exactly",
"one",
"entry",
"is",
"not",
"returned",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/search.go#L32-L61 |
12,550 | korylprince/go-ad-auth | search.go | GetDN | func (c *Conn) GetDN(attr, value string) (string, error) {
entry, err := c.SearchOne(fmt.Sprintf("(%s=%s)", attr, value), nil)
if err != nil {
return "", err
}
return entry.DN, nil
} | go | func (c *Conn) GetDN(attr, value string) (string, error) {
entry, err := c.SearchOne(fmt.Sprintf("(%s=%s)", attr, value), nil)
if err != nil {
return "", err
}
return entry.DN, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetDN",
"(",
"attr",
",",
"value",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"entry",
",",
"err",
":=",
"c",
".",
"SearchOne",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"attr",
",",
"value",
")",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"entry",
".",
"DN",
",",
"nil",
"\n",
"}"
] | //GetDN returns the DN for the object with the given attribute value or an error if one occurred. | [
"GetDN",
"returns",
"the",
"DN",
"for",
"the",
"object",
"with",
"the",
"given",
"attribute",
"value",
"or",
"an",
"error",
"if",
"one",
"occurred",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/search.go#L64-L71 |
12,551 | korylprince/go-ad-auth | auth.go | Authenticate | func Authenticate(config *Config, username, password string) (bool, error) {
upn, err := config.UPN(username)
if err != nil {
return false, err
}
conn, err := config.Connect()
if err != nil {
return false, err
}
defer conn.Conn.Close()
return conn.Bind(upn, password)
} | go | func Authenticate(config *Config, username, password string) (bool, error) {
upn, err := config.UPN(username)
if err != nil {
return false, err
}
conn, err := config.Connect()
if err != nil {
return false, err
}
defer conn.Conn.Close()
return conn.Bind(upn, password)
} | [
"func",
"Authenticate",
"(",
"config",
"*",
"Config",
",",
"username",
",",
"password",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"upn",
",",
"err",
":=",
"config",
".",
"UPN",
"(",
"username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"conn",
",",
"err",
":=",
"config",
".",
"Connect",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Conn",
".",
"Close",
"(",
")",
"\n\n",
"return",
"conn",
".",
"Bind",
"(",
"upn",
",",
"password",
")",
"\n",
"}"
] | //Authenticate checks if the given credentials are valid, or returns an error if one occurred.
//username may be either the sAMAccountName or the userPrincipalName. | [
"Authenticate",
"checks",
"if",
"the",
"given",
"credentials",
"are",
"valid",
"or",
"returns",
"an",
"error",
"if",
"one",
"occurred",
".",
"username",
"may",
"be",
"either",
"the",
"sAMAccountName",
"or",
"the",
"userPrincipalName",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/auth.go#L7-L20 |
12,552 | korylprince/go-ad-auth | conn.go | Connect | func (c *Config) Connect() (*Conn, error) {
switch c.Security {
case SecurityNone:
conn, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", c.Server, c.Port))
if err != nil {
return nil, fmt.Errorf("Connection error: %v", err)
}
return &Conn{Conn: conn, Config: c}, nil
case SecurityTLS:
conn, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", c.Server, c.Port), &tls.Config{ServerName: c.Server})
if err != nil {
return nil, fmt.Errorf("Connection error: %v", err)
}
return &Conn{Conn: conn, Config: c}, nil
case SecurityStartTLS:
conn, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", c.Server, c.Port))
if err != nil {
return nil, fmt.Errorf("Connection error: %v", err)
}
err = conn.StartTLS(&tls.Config{ServerName: c.Server})
if err != nil {
return nil, fmt.Errorf("Connection error: %v", err)
}
return &Conn{Conn: conn, Config: c}, nil
default:
return nil, errors.New("Configuration error: invalid SecurityType")
}
} | go | func (c *Config) Connect() (*Conn, error) {
switch c.Security {
case SecurityNone:
conn, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", c.Server, c.Port))
if err != nil {
return nil, fmt.Errorf("Connection error: %v", err)
}
return &Conn{Conn: conn, Config: c}, nil
case SecurityTLS:
conn, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", c.Server, c.Port), &tls.Config{ServerName: c.Server})
if err != nil {
return nil, fmt.Errorf("Connection error: %v", err)
}
return &Conn{Conn: conn, Config: c}, nil
case SecurityStartTLS:
conn, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", c.Server, c.Port))
if err != nil {
return nil, fmt.Errorf("Connection error: %v", err)
}
err = conn.StartTLS(&tls.Config{ServerName: c.Server})
if err != nil {
return nil, fmt.Errorf("Connection error: %v", err)
}
return &Conn{Conn: conn, Config: c}, nil
default:
return nil, errors.New("Configuration error: invalid SecurityType")
}
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Connect",
"(",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"switch",
"c",
".",
"Security",
"{",
"case",
"SecurityNone",
":",
"conn",
",",
"err",
":=",
"ldap",
".",
"Dial",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Server",
",",
"c",
".",
"Port",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"Conn",
"{",
"Conn",
":",
"conn",
",",
"Config",
":",
"c",
"}",
",",
"nil",
"\n",
"case",
"SecurityTLS",
":",
"conn",
",",
"err",
":=",
"ldap",
".",
"DialTLS",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Server",
",",
"c",
".",
"Port",
")",
",",
"&",
"tls",
".",
"Config",
"{",
"ServerName",
":",
"c",
".",
"Server",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"Conn",
"{",
"Conn",
":",
"conn",
",",
"Config",
":",
"c",
"}",
",",
"nil",
"\n",
"case",
"SecurityStartTLS",
":",
"conn",
",",
"err",
":=",
"ldap",
".",
"Dial",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Server",
",",
"c",
".",
"Port",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"conn",
".",
"StartTLS",
"(",
"&",
"tls",
".",
"Config",
"{",
"ServerName",
":",
"c",
".",
"Server",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"Conn",
"{",
"Conn",
":",
"conn",
",",
"Config",
":",
"c",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | //Connect returns an open connection to an Active Directory server or an error if one occurred. | [
"Connect",
"returns",
"an",
"open",
"connection",
"to",
"an",
"Active",
"Directory",
"server",
"or",
"an",
"error",
"if",
"one",
"occurred",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/conn.go#L18-L45 |
12,553 | korylprince/go-ad-auth | conn.go | Bind | func (c *Conn) Bind(upn, password string) (bool, error) {
if password == "" {
return false, nil
}
err := c.Conn.Bind(upn, password)
if err != nil {
if e, ok := err.(*ldap.Error); ok {
if e.ResultCode == ldap.LDAPResultInvalidCredentials {
return false, nil
}
}
return false, fmt.Errorf("Bind error (%s): %v", upn, err)
}
return true, nil
} | go | func (c *Conn) Bind(upn, password string) (bool, error) {
if password == "" {
return false, nil
}
err := c.Conn.Bind(upn, password)
if err != nil {
if e, ok := err.(*ldap.Error); ok {
if e.ResultCode == ldap.LDAPResultInvalidCredentials {
return false, nil
}
}
return false, fmt.Errorf("Bind error (%s): %v", upn, err)
}
return true, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Bind",
"(",
"upn",
",",
"password",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"password",
"==",
"\"",
"\"",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"err",
":=",
"c",
".",
"Conn",
".",
"Bind",
"(",
"upn",
",",
"password",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"ldap",
".",
"Error",
")",
";",
"ok",
"{",
"if",
"e",
".",
"ResultCode",
"==",
"ldap",
".",
"LDAPResultInvalidCredentials",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"upn",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | //Bind authenticates the connection with the given userPrincipalName and password
//and returns the result or an error if one occurred. | [
"Bind",
"authenticates",
"the",
"connection",
"with",
"the",
"given",
"userPrincipalName",
"and",
"password",
"and",
"returns",
"the",
"result",
"or",
"an",
"error",
"if",
"one",
"occurred",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/conn.go#L49-L65 |
12,554 | korylprince/go-ad-auth | config.go | Domain | func (c *Config) Domain() (string, error) {
domain := ""
for _, v := range strings.Split(strings.ToLower(c.BaseDN), ",") {
if trimmed := strings.TrimSpace(v); strings.HasPrefix(trimmed, "dc=") {
domain = domain + "." + trimmed[3:]
}
}
if len(domain) <= 1 {
return "", errors.New("Configuration error: invalid BaseDN")
}
return domain[1:], nil
} | go | func (c *Config) Domain() (string, error) {
domain := ""
for _, v := range strings.Split(strings.ToLower(c.BaseDN), ",") {
if trimmed := strings.TrimSpace(v); strings.HasPrefix(trimmed, "dc=") {
domain = domain + "." + trimmed[3:]
}
}
if len(domain) <= 1 {
return "", errors.New("Configuration error: invalid BaseDN")
}
return domain[1:], nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Domain",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"domain",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"strings",
".",
"Split",
"(",
"strings",
".",
"ToLower",
"(",
"c",
".",
"BaseDN",
")",
",",
"\"",
"\"",
")",
"{",
"if",
"trimmed",
":=",
"strings",
".",
"TrimSpace",
"(",
"v",
")",
";",
"strings",
".",
"HasPrefix",
"(",
"trimmed",
",",
"\"",
"\"",
")",
"{",
"domain",
"=",
"domain",
"+",
"\"",
"\"",
"+",
"trimmed",
"[",
"3",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"domain",
")",
"<=",
"1",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"domain",
"[",
"1",
":",
"]",
",",
"nil",
"\n",
"}"
] | //Domain returns the domain derived from BaseDN or an error if misconfigured. | [
"Domain",
"returns",
"the",
"domain",
"derived",
"from",
"BaseDN",
"or",
"an",
"error",
"if",
"misconfigured",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/config.go#L29-L40 |
12,555 | korylprince/go-ad-auth | config.go | UPN | func (c *Config) UPN(username string) (string, error) {
if _, err := mail.ParseAddress(username); err == nil {
return username, nil
}
domain, err := c.Domain()
if err != nil {
return "", err
}
return fmt.Sprintf("%s@%s", username, domain), nil
} | go | func (c *Config) UPN(username string) (string, error) {
if _, err := mail.ParseAddress(username); err == nil {
return username, nil
}
domain, err := c.Domain()
if err != nil {
return "", err
}
return fmt.Sprintf("%s@%s", username, domain), nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"UPN",
"(",
"username",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"mail",
".",
"ParseAddress",
"(",
"username",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"username",
",",
"nil",
"\n",
"}",
"\n\n",
"domain",
",",
"err",
":=",
"c",
".",
"Domain",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"username",
",",
"domain",
")",
",",
"nil",
"\n",
"}"
] | //UPN returns the userPrincipalName for the given username or an error if misconfigured. | [
"UPN",
"returns",
"the",
"userPrincipalName",
"for",
"the",
"given",
"username",
"or",
"an",
"error",
"if",
"misconfigured",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/config.go#L43-L54 |
12,556 | korylprince/go-ad-auth | group.go | GroupDN | func (c *Conn) GroupDN(group string) (string, error) {
if strings.HasSuffix(group, c.Config.BaseDN) {
return group, nil
}
return c.GetDN("cn", group)
} | go | func (c *Conn) GroupDN(group string) (string, error) {
if strings.HasSuffix(group, c.Config.BaseDN) {
return group, nil
}
return c.GetDN("cn", group)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GroupDN",
"(",
"group",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"strings",
".",
"HasSuffix",
"(",
"group",
",",
"c",
".",
"Config",
".",
"BaseDN",
")",
"{",
"return",
"group",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"GetDN",
"(",
"\"",
"\"",
",",
"group",
")",
"\n",
"}"
] | //GroupDN returns the DN of the group with the given cn or an error if one occurred. | [
"GroupDN",
"returns",
"the",
"DN",
"of",
"the",
"group",
"with",
"the",
"given",
"cn",
"or",
"an",
"error",
"if",
"one",
"occurred",
"."
] | 2c1a6d8ba1d783acf3b062355e8f4b075686810f | https://github.com/korylprince/go-ad-auth/blob/2c1a6d8ba1d783acf3b062355e8f4b075686810f/group.go#L8-L14 |
12,557 | albrow/forms | validator.go | Field | func (vr *ValidationResult) Field(field string) *ValidationResult {
vr.field = field
return vr
} | go | func (vr *ValidationResult) Field(field string) *ValidationResult {
vr.field = field
return vr
} | [
"func",
"(",
"vr",
"*",
"ValidationResult",
")",
"Field",
"(",
"field",
"string",
")",
"*",
"ValidationResult",
"{",
"vr",
".",
"field",
"=",
"field",
"\n",
"return",
"vr",
"\n",
"}"
] | // Field changes the field name associated with the validation result. | [
"Field",
"changes",
"the",
"field",
"name",
"associated",
"with",
"the",
"validation",
"result",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/validator.go#L39-L42 |
12,558 | albrow/forms | validator.go | Message | func (vr *ValidationResult) Message(msg string) *ValidationResult {
vr.message = msg
return vr
} | go | func (vr *ValidationResult) Message(msg string) *ValidationResult {
vr.message = msg
return vr
} | [
"func",
"(",
"vr",
"*",
"ValidationResult",
")",
"Message",
"(",
"msg",
"string",
")",
"*",
"ValidationResult",
"{",
"vr",
".",
"message",
"=",
"msg",
"\n",
"return",
"vr",
"\n",
"}"
] | // Message changes the error message associated with the validation
// result. msg should typically be a user-readable sentence, such as
// "username is required." | [
"Message",
"changes",
"the",
"error",
"message",
"associated",
"with",
"the",
"validation",
"result",
".",
"msg",
"should",
"typically",
"be",
"a",
"user",
"-",
"readable",
"sentence",
"such",
"as",
"username",
"is",
"required",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/validator.go#L47-L50 |
12,559 | albrow/forms | validator.go | AddError | func (v *Validator) AddError(field string, msg string) *ValidationResult {
result := &ValidationResult{
field: field,
message: msg,
}
v.results = append(v.results, result)
return result
} | go | func (v *Validator) AddError(field string, msg string) *ValidationResult {
result := &ValidationResult{
field: field,
message: msg,
}
v.results = append(v.results, result)
return result
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"AddError",
"(",
"field",
"string",
",",
"msg",
"string",
")",
"*",
"ValidationResult",
"{",
"result",
":=",
"&",
"ValidationResult",
"{",
"field",
":",
"field",
",",
"message",
":",
"msg",
",",
"}",
"\n",
"v",
".",
"results",
"=",
"append",
"(",
"v",
".",
"results",
",",
"result",
")",
"\n",
"return",
"result",
"\n",
"}"
] | // AddError adds an error associated with field to the validator. msg
// should typically be a user-readable sentence, such as "username
// is required." | [
"AddError",
"adds",
"an",
"error",
"associated",
"with",
"field",
"to",
"the",
"validator",
".",
"msg",
"should",
"typically",
"be",
"a",
"user",
"-",
"readable",
"sentence",
"such",
"as",
"username",
"is",
"required",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/validator.go#L55-L62 |
12,560 | albrow/forms | validator.go | Messages | func (v *Validator) Messages() []string {
msgs := []string{}
for _, vr := range v.results {
msgs = append(msgs, vr.message)
}
return msgs
} | go | func (v *Validator) Messages() []string {
msgs := []string{}
for _, vr := range v.results {
msgs = append(msgs, vr.message)
}
return msgs
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"Messages",
"(",
")",
"[",
"]",
"string",
"{",
"msgs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"vr",
":=",
"range",
"v",
".",
"results",
"{",
"msgs",
"=",
"append",
"(",
"msgs",
",",
"vr",
".",
"message",
")",
"\n",
"}",
"\n",
"return",
"msgs",
"\n",
"}"
] | // Messages returns the messages for all validation results for
// the Validator, in order. | [
"Messages",
"returns",
"the",
"messages",
"for",
"all",
"validation",
"results",
"for",
"the",
"Validator",
"in",
"order",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/validator.go#L72-L78 |
12,561 | albrow/forms | validator.go | Fields | func (v *Validator) Fields() []string {
fields := []string{}
for _, vr := range v.results {
fields = append(fields, vr.field)
}
return fields
} | go | func (v *Validator) Fields() []string {
fields := []string{}
for _, vr := range v.results {
fields = append(fields, vr.field)
}
return fields
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"Fields",
"(",
")",
"[",
"]",
"string",
"{",
"fields",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"vr",
":=",
"range",
"v",
".",
"results",
"{",
"fields",
"=",
"append",
"(",
"fields",
",",
"vr",
".",
"field",
")",
"\n",
"}",
"\n",
"return",
"fields",
"\n",
"}"
] | // Fields returns the fields for all validation results for
// the Validator, in order. | [
"Fields",
"returns",
"the",
"fields",
"for",
"all",
"validation",
"results",
"for",
"the",
"Validator",
"in",
"order",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/validator.go#L82-L88 |
12,562 | albrow/forms | validator.go | ErrorMap | func (v *Validator) ErrorMap() map[string][]string {
errMap := map[string][]string{}
for _, vr := range v.results {
if _, found := errMap[vr.field]; found {
errMap[vr.field] = append(errMap[vr.field], vr.message)
} else {
errMap[vr.field] = []string{vr.message}
}
}
return errMap
} | go | func (v *Validator) ErrorMap() map[string][]string {
errMap := map[string][]string{}
for _, vr := range v.results {
if _, found := errMap[vr.field]; found {
errMap[vr.field] = append(errMap[vr.field], vr.message)
} else {
errMap[vr.field] = []string{vr.message}
}
}
return errMap
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"ErrorMap",
"(",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"errMap",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"vr",
":=",
"range",
"v",
".",
"results",
"{",
"if",
"_",
",",
"found",
":=",
"errMap",
"[",
"vr",
".",
"field",
"]",
";",
"found",
"{",
"errMap",
"[",
"vr",
".",
"field",
"]",
"=",
"append",
"(",
"errMap",
"[",
"vr",
".",
"field",
"]",
",",
"vr",
".",
"message",
")",
"\n",
"}",
"else",
"{",
"errMap",
"[",
"vr",
".",
"field",
"]",
"=",
"[",
"]",
"string",
"{",
"vr",
".",
"message",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"errMap",
"\n",
"}"
] | // ErrorMap reutrns all the fields and error messages for
// the validator in the form of a map. The keys of the map
// are field names, and the values are any error messages
// associated with that field name. | [
"ErrorMap",
"reutrns",
"all",
"the",
"fields",
"and",
"error",
"messages",
"for",
"the",
"validator",
"in",
"the",
"form",
"of",
"a",
"map",
".",
"The",
"keys",
"of",
"the",
"map",
"are",
"field",
"names",
"and",
"the",
"values",
"are",
"any",
"error",
"messages",
"associated",
"with",
"that",
"field",
"name",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/validator.go#L94-L104 |
12,563 | albrow/forms | validator.go | AcceptFileExts | func (v *Validator) AcceptFileExts(field string, exts ...string) *ValidationResult {
if !v.data.FileExists(field) {
return validationOk
}
header := v.data.GetFile(field)
gotExt := filepath.Ext(header.Filename)
for _, ext := range exts {
if ext == gotExt[1:] {
return validationOk
}
}
return v.addFileExtError(field, gotExt, exts...)
} | go | func (v *Validator) AcceptFileExts(field string, exts ...string) *ValidationResult {
if !v.data.FileExists(field) {
return validationOk
}
header := v.data.GetFile(field)
gotExt := filepath.Ext(header.Filename)
for _, ext := range exts {
if ext == gotExt[1:] {
return validationOk
}
}
return v.addFileExtError(field, gotExt, exts...)
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"AcceptFileExts",
"(",
"field",
"string",
",",
"exts",
"...",
"string",
")",
"*",
"ValidationResult",
"{",
"if",
"!",
"v",
".",
"data",
".",
"FileExists",
"(",
"field",
")",
"{",
"return",
"validationOk",
"\n",
"}",
"\n",
"header",
":=",
"v",
".",
"data",
".",
"GetFile",
"(",
"field",
")",
"\n",
"gotExt",
":=",
"filepath",
".",
"Ext",
"(",
"header",
".",
"Filename",
")",
"\n",
"for",
"_",
",",
"ext",
":=",
"range",
"exts",
"{",
"if",
"ext",
"==",
"gotExt",
"[",
"1",
":",
"]",
"{",
"return",
"validationOk",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"v",
".",
"addFileExtError",
"(",
"field",
",",
"gotExt",
",",
"exts",
"...",
")",
"\n",
"}"
] | // AcceptFileExts will add an error to the Validator if the extension
// of the file identified by field is not in exts. exts should be one ore more
// allowed file extensions, not including the preceding ".". If the file does not
// exist, it does not add an error to the Validator. | [
"AcceptFileExts",
"will",
"add",
"an",
"error",
"to",
"the",
"Validator",
"if",
"the",
"extension",
"of",
"the",
"file",
"identified",
"by",
"field",
"is",
"not",
"in",
"exts",
".",
"exts",
"should",
"be",
"one",
"ore",
"more",
"allowed",
"file",
"extensions",
"not",
"including",
"the",
"preceding",
".",
".",
"If",
"the",
"file",
"does",
"not",
"exist",
"it",
"does",
"not",
"add",
"an",
"error",
"to",
"the",
"Validator",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/validator.go#L344-L356 |
12,564 | albrow/forms | data.go | CreateFromMap | func CreateFromMap(m map[string]string) *Data {
data := newData()
for key, value := range m {
data.Add(key, value)
}
return data
} | go | func CreateFromMap(m map[string]string) *Data {
data := newData()
for key, value := range m {
data.Add(key, value)
}
return data
} | [
"func",
"CreateFromMap",
"(",
"m",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"Data",
"{",
"data",
":=",
"newData",
"(",
")",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"m",
"{",
"data",
".",
"Add",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n",
"return",
"data",
"\n",
"}"
] | // CreateFromMap returns a Data object with keys and values matching
// the map. | [
"CreateFromMap",
"returns",
"a",
"Data",
"object",
"with",
"keys",
"and",
"values",
"matching",
"the",
"map",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/data.go#L107-L113 |
12,565 | albrow/forms | data.go | AddFile | func (d *Data) AddFile(key string, file *multipart.FileHeader) {
d.Files[key] = file
} | go | func (d *Data) AddFile(key string, file *multipart.FileHeader) {
d.Files[key] = file
} | [
"func",
"(",
"d",
"*",
"Data",
")",
"AddFile",
"(",
"key",
"string",
",",
"file",
"*",
"multipart",
".",
"FileHeader",
")",
"{",
"d",
".",
"Files",
"[",
"key",
"]",
"=",
"file",
"\n",
"}"
] | // AddFile adds the multipart form file to data with the given key. | [
"AddFile",
"adds",
"the",
"multipart",
"form",
"file",
"to",
"data",
"with",
"the",
"given",
"key",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/data.go#L152-L154 |
12,566 | albrow/forms | data.go | BindJSON | func (d Data) BindJSON(v interface{}) error {
if len(d.jsonBody) == 0 {
return nil
}
return json.Unmarshal(d.jsonBody, v)
} | go | func (d Data) BindJSON(v interface{}) error {
if len(d.jsonBody) == 0 {
return nil
}
return json.Unmarshal(d.jsonBody, v)
} | [
"func",
"(",
"d",
"Data",
")",
"BindJSON",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"d",
".",
"jsonBody",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"json",
".",
"Unmarshal",
"(",
"d",
".",
"jsonBody",
",",
"v",
")",
"\n",
"}"
] | // BindJSON binds v to the json data in the request body. It calls json.Unmarshal and
// sets the value of v. | [
"BindJSON",
"binds",
"v",
"to",
"the",
"json",
"data",
"in",
"the",
"request",
"body",
".",
"It",
"calls",
"json",
".",
"Unmarshal",
"and",
"sets",
"the",
"value",
"of",
"v",
"."
] | c4277021bca254bd21cae0a800ddc2ad6d370217 | https://github.com/albrow/forms/blob/c4277021bca254bd21cae0a800ddc2ad6d370217/data.go#L280-L285 |
12,567 | DavidBelicza/TextRank | rank/relation.go | AddRelation | func (relation *Relation) AddRelation(wordID int, relatedWordID int, sentenceID int) {
if relatedWordID == -1 {
return
}
if relation.updateRelation(relatedWordID, wordID, true, sentenceID) {
return
}
if relation.extendRelation(wordID, relatedWordID, true, sentenceID) {
return
}
relation.createRelation(wordID, relatedWordID, sentenceID)
} | go | func (relation *Relation) AddRelation(wordID int, relatedWordID int, sentenceID int) {
if relatedWordID == -1 {
return
}
if relation.updateRelation(relatedWordID, wordID, true, sentenceID) {
return
}
if relation.extendRelation(wordID, relatedWordID, true, sentenceID) {
return
}
relation.createRelation(wordID, relatedWordID, sentenceID)
} | [
"func",
"(",
"relation",
"*",
"Relation",
")",
"AddRelation",
"(",
"wordID",
"int",
",",
"relatedWordID",
"int",
",",
"sentenceID",
"int",
")",
"{",
"if",
"relatedWordID",
"==",
"-",
"1",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"relation",
".",
"updateRelation",
"(",
"relatedWordID",
",",
"wordID",
",",
"true",
",",
"sentenceID",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"relation",
".",
"extendRelation",
"(",
"wordID",
",",
"relatedWordID",
",",
"true",
",",
"sentenceID",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"relation",
".",
"createRelation",
"(",
"wordID",
",",
"relatedWordID",
",",
"sentenceID",
")",
"\n",
"}"
] | // AddRelation method adds a new relation to Relation object. | [
"AddRelation",
"method",
"adds",
"a",
"new",
"relation",
"to",
"Relation",
"object",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/relation.go#L31-L45 |
12,568 | DavidBelicza/TextRank | convert/builder.go | TextToRank | func TextToRank(sentence parse.ParsedSentence, lang Language, ranks *rank.Rank) {
sentenceId := addSentence(ranks, sentence)
addWord(ranks, sentence.GetWords(), lang, sentenceId)
} | go | func TextToRank(sentence parse.ParsedSentence, lang Language, ranks *rank.Rank) {
sentenceId := addSentence(ranks, sentence)
addWord(ranks, sentence.GetWords(), lang, sentenceId)
} | [
"func",
"TextToRank",
"(",
"sentence",
"parse",
".",
"ParsedSentence",
",",
"lang",
"Language",
",",
"ranks",
"*",
"rank",
".",
"Rank",
")",
"{",
"sentenceId",
":=",
"addSentence",
"(",
"ranks",
",",
"sentence",
")",
"\n",
"addWord",
"(",
"ranks",
",",
"sentence",
".",
"GetWords",
"(",
")",
",",
"lang",
",",
"sentenceId",
")",
"\n",
"}"
] | // TextToRank function converts a ParsedSentence object to Rank object, it is
// the preparing process to later text ranking. | [
"TextToRank",
"function",
"converts",
"a",
"ParsedSentence",
"object",
"to",
"Rank",
"object",
"it",
"is",
"the",
"preparing",
"process",
"to",
"later",
"text",
"ranking",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/convert/builder.go#L10-L13 |
12,569 | DavidBelicza/TextRank | rank/sorting.go | FindPhrases | func FindPhrases(ranks *Rank) []Phrase {
var phrases []Phrase
for x, xMap := range ranks.Relation.Node {
for y := range xMap {
phrases = append(phrases, Phrase{
ranks.Words[x].ID,
ranks.Words[y].ID,
ranks.Words[x].Token,
ranks.Words[y].Token,
ranks.Relation.Node[x][y].Weight,
ranks.Relation.Node[x][y].Qty,
})
}
}
sort.Slice(phrases, func(i, j int) bool {
return phrases[i].Weight > phrases[j].Weight
})
return phrases
} | go | func FindPhrases(ranks *Rank) []Phrase {
var phrases []Phrase
for x, xMap := range ranks.Relation.Node {
for y := range xMap {
phrases = append(phrases, Phrase{
ranks.Words[x].ID,
ranks.Words[y].ID,
ranks.Words[x].Token,
ranks.Words[y].Token,
ranks.Relation.Node[x][y].Weight,
ranks.Relation.Node[x][y].Qty,
})
}
}
sort.Slice(phrases, func(i, j int) bool {
return phrases[i].Weight > phrases[j].Weight
})
return phrases
} | [
"func",
"FindPhrases",
"(",
"ranks",
"*",
"Rank",
")",
"[",
"]",
"Phrase",
"{",
"var",
"phrases",
"[",
"]",
"Phrase",
"\n\n",
"for",
"x",
",",
"xMap",
":=",
"range",
"ranks",
".",
"Relation",
".",
"Node",
"{",
"for",
"y",
":=",
"range",
"xMap",
"{",
"phrases",
"=",
"append",
"(",
"phrases",
",",
"Phrase",
"{",
"ranks",
".",
"Words",
"[",
"x",
"]",
".",
"ID",
",",
"ranks",
".",
"Words",
"[",
"y",
"]",
".",
"ID",
",",
"ranks",
".",
"Words",
"[",
"x",
"]",
".",
"Token",
",",
"ranks",
".",
"Words",
"[",
"y",
"]",
".",
"Token",
",",
"ranks",
".",
"Relation",
".",
"Node",
"[",
"x",
"]",
"[",
"y",
"]",
".",
"Weight",
",",
"ranks",
".",
"Relation",
".",
"Node",
"[",
"x",
"]",
"[",
"y",
"]",
".",
"Qty",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"sort",
".",
"Slice",
"(",
"phrases",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"phrases",
"[",
"i",
"]",
".",
"Weight",
">",
"phrases",
"[",
"j",
"]",
".",
"Weight",
"\n",
"}",
")",
"\n\n",
"return",
"phrases",
"\n",
"}"
] | // FindPhrases function has wrapper textrank.FindPhrases. Use the wrapper
// instead. | [
"FindPhrases",
"function",
"has",
"wrapper",
"textrank",
".",
"FindPhrases",
".",
"Use",
"the",
"wrapper",
"instead",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/sorting.go#L31-L52 |
12,570 | DavidBelicza/TextRank | rank/sorting.go | FindSingleWords | func FindSingleWords(ranks *Rank) []SingleWord {
var singleWords []SingleWord
for _, word := range ranks.Words {
singleWords = append(singleWords, SingleWord{
word.ID,
word.Token,
word.Weight,
word.Qty,
})
}
sort.Slice(singleWords, func(i, j int) bool {
return singleWords[i].Weight > singleWords[j].Weight
})
return singleWords
} | go | func FindSingleWords(ranks *Rank) []SingleWord {
var singleWords []SingleWord
for _, word := range ranks.Words {
singleWords = append(singleWords, SingleWord{
word.ID,
word.Token,
word.Weight,
word.Qty,
})
}
sort.Slice(singleWords, func(i, j int) bool {
return singleWords[i].Weight > singleWords[j].Weight
})
return singleWords
} | [
"func",
"FindSingleWords",
"(",
"ranks",
"*",
"Rank",
")",
"[",
"]",
"SingleWord",
"{",
"var",
"singleWords",
"[",
"]",
"SingleWord",
"\n\n",
"for",
"_",
",",
"word",
":=",
"range",
"ranks",
".",
"Words",
"{",
"singleWords",
"=",
"append",
"(",
"singleWords",
",",
"SingleWord",
"{",
"word",
".",
"ID",
",",
"word",
".",
"Token",
",",
"word",
".",
"Weight",
",",
"word",
".",
"Qty",
",",
"}",
")",
"\n",
"}",
"\n\n",
"sort",
".",
"Slice",
"(",
"singleWords",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"singleWords",
"[",
"i",
"]",
".",
"Weight",
">",
"singleWords",
"[",
"j",
"]",
".",
"Weight",
"\n",
"}",
")",
"\n\n",
"return",
"singleWords",
"\n",
"}"
] | // FindSingleWords function has wrapper textrank.FindSingleWords. Use the
// wrapper instead. | [
"FindSingleWords",
"function",
"has",
"wrapper",
"textrank",
".",
"FindSingleWords",
".",
"Use",
"the",
"wrapper",
"instead",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/sorting.go#L72-L89 |
12,571 | DavidBelicza/TextRank | rank/sorting.go | FindSentences | func FindSentences(ranks *Rank, kind int, limit int) []Sentence {
var sentences []Sentence
cache := make(map[int]bool)
collect := func(sentenceIDs []int) bool {
for _, id := range sentenceIDs {
if len(sentences) >= limit {
return true
}
if !cache[id] {
sentences = append(sentences, Sentence{id, ranks.SentenceMap[id]})
cache[id] = true
}
}
return false
}
if kind == ByQty {
singleWords := FindSingleWords(ranks)
for _, singleWord := range singleWords {
sentenceIDs := ranks.Words[singleWord.ID].SentenceIDs
if collect(sentenceIDs) {
return sentences
}
}
} else if kind == ByRelation {
phrases := FindPhrases(ranks)
for _, phrase := range phrases {
sentenceIDs := ranks.Relation.Node[phrase.LeftID][phrase.RightID].SentenceIDs
if collect(sentenceIDs) {
return sentences
}
}
}
return sentences
} | go | func FindSentences(ranks *Rank, kind int, limit int) []Sentence {
var sentences []Sentence
cache := make(map[int]bool)
collect := func(sentenceIDs []int) bool {
for _, id := range sentenceIDs {
if len(sentences) >= limit {
return true
}
if !cache[id] {
sentences = append(sentences, Sentence{id, ranks.SentenceMap[id]})
cache[id] = true
}
}
return false
}
if kind == ByQty {
singleWords := FindSingleWords(ranks)
for _, singleWord := range singleWords {
sentenceIDs := ranks.Words[singleWord.ID].SentenceIDs
if collect(sentenceIDs) {
return sentences
}
}
} else if kind == ByRelation {
phrases := FindPhrases(ranks)
for _, phrase := range phrases {
sentenceIDs := ranks.Relation.Node[phrase.LeftID][phrase.RightID].SentenceIDs
if collect(sentenceIDs) {
return sentences
}
}
}
return sentences
} | [
"func",
"FindSentences",
"(",
"ranks",
"*",
"Rank",
",",
"kind",
"int",
",",
"limit",
"int",
")",
"[",
"]",
"Sentence",
"{",
"var",
"sentences",
"[",
"]",
"Sentence",
"\n\n",
"cache",
":=",
"make",
"(",
"map",
"[",
"int",
"]",
"bool",
")",
"\n\n",
"collect",
":=",
"func",
"(",
"sentenceIDs",
"[",
"]",
"int",
")",
"bool",
"{",
"for",
"_",
",",
"id",
":=",
"range",
"sentenceIDs",
"{",
"if",
"len",
"(",
"sentences",
")",
">=",
"limit",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"!",
"cache",
"[",
"id",
"]",
"{",
"sentences",
"=",
"append",
"(",
"sentences",
",",
"Sentence",
"{",
"id",
",",
"ranks",
".",
"SentenceMap",
"[",
"id",
"]",
"}",
")",
"\n",
"cache",
"[",
"id",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"kind",
"==",
"ByQty",
"{",
"singleWords",
":=",
"FindSingleWords",
"(",
"ranks",
")",
"\n\n",
"for",
"_",
",",
"singleWord",
":=",
"range",
"singleWords",
"{",
"sentenceIDs",
":=",
"ranks",
".",
"Words",
"[",
"singleWord",
".",
"ID",
"]",
".",
"SentenceIDs",
"\n\n",
"if",
"collect",
"(",
"sentenceIDs",
")",
"{",
"return",
"sentences",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"kind",
"==",
"ByRelation",
"{",
"phrases",
":=",
"FindPhrases",
"(",
"ranks",
")",
"\n\n",
"for",
"_",
",",
"phrase",
":=",
"range",
"phrases",
"{",
"sentenceIDs",
":=",
"ranks",
".",
"Relation",
".",
"Node",
"[",
"phrase",
".",
"LeftID",
"]",
"[",
"phrase",
".",
"RightID",
"]",
".",
"SentenceIDs",
"\n\n",
"if",
"collect",
"(",
"sentenceIDs",
")",
"{",
"return",
"sentences",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"sentences",
"\n",
"}"
] | // FindSentences function has wrappers textrank.FindSentencesByRelationWeight
// and textrank.FindSentencesByWordQtyWeight. Use the wrappers instead. | [
"FindSentences",
"function",
"has",
"wrappers",
"textrank",
".",
"FindSentencesByRelationWeight",
"and",
"textrank",
".",
"FindSentencesByWordQtyWeight",
".",
"Use",
"the",
"wrappers",
"instead",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/sorting.go#L105-L148 |
12,572 | DavidBelicza/TextRank | rank/sorting.go | FindSentencesByPhrases | func FindSentencesByPhrases(ranks *Rank, words []string) []Sentence {
var sentences []Sentence
reqMatch := len(words) - 1
sentenceIDs := make(map[int]int)
for _, i := range words {
for _, j := range words {
x := ranks.WordValID[i]
y := ranks.WordValID[j]
if _, ok := ranks.Relation.Node[x][y]; ok {
curSentenceIDs := ranks.Relation.Node[x][y].SentenceIDs
for _, id := range curSentenceIDs {
if _, ok := sentenceIDs[id]; ok {
sentenceIDs[id]++
} else {
sentenceIDs[id] = 1
}
}
}
}
}
for sentenceID, v := range sentenceIDs {
if v >= reqMatch {
sentences = append(sentences, Sentence{sentenceID, ranks.SentenceMap[sentenceID]})
}
}
sort.Slice(sentences, func(i, j int) bool {
return sentences[i].ID < sentences[j].ID
})
return sentences
} | go | func FindSentencesByPhrases(ranks *Rank, words []string) []Sentence {
var sentences []Sentence
reqMatch := len(words) - 1
sentenceIDs := make(map[int]int)
for _, i := range words {
for _, j := range words {
x := ranks.WordValID[i]
y := ranks.WordValID[j]
if _, ok := ranks.Relation.Node[x][y]; ok {
curSentenceIDs := ranks.Relation.Node[x][y].SentenceIDs
for _, id := range curSentenceIDs {
if _, ok := sentenceIDs[id]; ok {
sentenceIDs[id]++
} else {
sentenceIDs[id] = 1
}
}
}
}
}
for sentenceID, v := range sentenceIDs {
if v >= reqMatch {
sentences = append(sentences, Sentence{sentenceID, ranks.SentenceMap[sentenceID]})
}
}
sort.Slice(sentences, func(i, j int) bool {
return sentences[i].ID < sentences[j].ID
})
return sentences
} | [
"func",
"FindSentencesByPhrases",
"(",
"ranks",
"*",
"Rank",
",",
"words",
"[",
"]",
"string",
")",
"[",
"]",
"Sentence",
"{",
"var",
"sentences",
"[",
"]",
"Sentence",
"\n\n",
"reqMatch",
":=",
"len",
"(",
"words",
")",
"-",
"1",
"\n",
"sentenceIDs",
":=",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
"\n\n",
"for",
"_",
",",
"i",
":=",
"range",
"words",
"{",
"for",
"_",
",",
"j",
":=",
"range",
"words",
"{",
"x",
":=",
"ranks",
".",
"WordValID",
"[",
"i",
"]",
"\n",
"y",
":=",
"ranks",
".",
"WordValID",
"[",
"j",
"]",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"ranks",
".",
"Relation",
".",
"Node",
"[",
"x",
"]",
"[",
"y",
"]",
";",
"ok",
"{",
"curSentenceIDs",
":=",
"ranks",
".",
"Relation",
".",
"Node",
"[",
"x",
"]",
"[",
"y",
"]",
".",
"SentenceIDs",
"\n\n",
"for",
"_",
",",
"id",
":=",
"range",
"curSentenceIDs",
"{",
"if",
"_",
",",
"ok",
":=",
"sentenceIDs",
"[",
"id",
"]",
";",
"ok",
"{",
"sentenceIDs",
"[",
"id",
"]",
"++",
"\n",
"}",
"else",
"{",
"sentenceIDs",
"[",
"id",
"]",
"=",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"sentenceID",
",",
"v",
":=",
"range",
"sentenceIDs",
"{",
"if",
"v",
">=",
"reqMatch",
"{",
"sentences",
"=",
"append",
"(",
"sentences",
",",
"Sentence",
"{",
"sentenceID",
",",
"ranks",
".",
"SentenceMap",
"[",
"sentenceID",
"]",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"sort",
".",
"Slice",
"(",
"sentences",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"sentences",
"[",
"i",
"]",
".",
"ID",
"<",
"sentences",
"[",
"j",
"]",
".",
"ID",
"\n",
"}",
")",
"\n\n",
"return",
"sentences",
"\n",
"}"
] | // FindSentencesByPhrases function has wrapper
// textrank.FindSentencesByPhraseChain. Use the wrapper instead. | [
"FindSentencesByPhrases",
"function",
"has",
"wrapper",
"textrank",
".",
"FindSentencesByPhraseChain",
".",
"Use",
"the",
"wrapper",
"instead",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/sorting.go#L152-L188 |
12,573 | DavidBelicza/TextRank | rank/sorting.go | FindSentencesFrom | func FindSentencesFrom(ranks *Rank, id int, limit int) []Sentence {
var sentences []Sentence
limit = id + limit - 1
for i := id; i <= limit; i++ {
sentences = append(sentences, Sentence{i, ranks.SentenceMap[i]})
}
return sentences
} | go | func FindSentencesFrom(ranks *Rank, id int, limit int) []Sentence {
var sentences []Sentence
limit = id + limit - 1
for i := id; i <= limit; i++ {
sentences = append(sentences, Sentence{i, ranks.SentenceMap[i]})
}
return sentences
} | [
"func",
"FindSentencesFrom",
"(",
"ranks",
"*",
"Rank",
",",
"id",
"int",
",",
"limit",
"int",
")",
"[",
"]",
"Sentence",
"{",
"var",
"sentences",
"[",
"]",
"Sentence",
"\n\n",
"limit",
"=",
"id",
"+",
"limit",
"-",
"1",
"\n\n",
"for",
"i",
":=",
"id",
";",
"i",
"<=",
"limit",
";",
"i",
"++",
"{",
"sentences",
"=",
"append",
"(",
"sentences",
",",
"Sentence",
"{",
"i",
",",
"ranks",
".",
"SentenceMap",
"[",
"i",
"]",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"sentences",
"\n",
"}"
] | // FindSentencesFrom function has wrapper textrank.FindSentencesFrom. Use the
// wrapper instead. | [
"FindSentencesFrom",
"function",
"has",
"wrapper",
"textrank",
".",
"FindSentencesFrom",
".",
"Use",
"the",
"wrapper",
"instead",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/sorting.go#L192-L202 |
12,574 | DavidBelicza/TextRank | parse/text.go | Append | func (text *Text) Append(rawSentence string, words []string) {
if len(words) > 0 {
parsedSentence := ParsedSentence{
original: rawSentence,
words: words,
}
text.parsedSentences = append(
text.parsedSentences,
parsedSentence,
)
}
} | go | func (text *Text) Append(rawSentence string, words []string) {
if len(words) > 0 {
parsedSentence := ParsedSentence{
original: rawSentence,
words: words,
}
text.parsedSentences = append(
text.parsedSentences,
parsedSentence,
)
}
} | [
"func",
"(",
"text",
"*",
"Text",
")",
"Append",
"(",
"rawSentence",
"string",
",",
"words",
"[",
"]",
"string",
")",
"{",
"if",
"len",
"(",
"words",
")",
">",
"0",
"{",
"parsedSentence",
":=",
"ParsedSentence",
"{",
"original",
":",
"rawSentence",
",",
"words",
":",
"words",
",",
"}",
"\n\n",
"text",
".",
"parsedSentences",
"=",
"append",
"(",
"text",
".",
"parsedSentences",
",",
"parsedSentence",
",",
")",
"\n",
"}",
"\n",
"}"
] | // Append method creates a sentence and its words and append them to the Text
// object. | [
"Append",
"method",
"creates",
"a",
"sentence",
"and",
"its",
"words",
"and",
"append",
"them",
"to",
"the",
"Text",
"object",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/parse/text.go#L16-L28 |
12,575 | DavidBelicza/TextRank | rank/algorithm.go | WeightingRelation | func (a *AlgorithmDefault) WeightingRelation(
word1ID int,
word2ID int,
rank *Rank,
) float32 {
relationQty := rank.Relation.Node[word1ID][word2ID].Qty
return float32(relationQty)
} | go | func (a *AlgorithmDefault) WeightingRelation(
word1ID int,
word2ID int,
rank *Rank,
) float32 {
relationQty := rank.Relation.Node[word1ID][word2ID].Qty
return float32(relationQty)
} | [
"func",
"(",
"a",
"*",
"AlgorithmDefault",
")",
"WeightingRelation",
"(",
"word1ID",
"int",
",",
"word2ID",
"int",
",",
"rank",
"*",
"Rank",
",",
")",
"float32",
"{",
"relationQty",
":=",
"rank",
".",
"Relation",
".",
"Node",
"[",
"word1ID",
"]",
"[",
"word2ID",
"]",
".",
"Qty",
"\n\n",
"return",
"float32",
"(",
"relationQty",
")",
"\n",
"}"
] | // WeightingRelation method is the traditional algorithm of text rank to
// weighting a phrase. | [
"WeightingRelation",
"method",
"is",
"the",
"traditional",
"algorithm",
"of",
"text",
"rank",
"to",
"weighting",
"a",
"phrase",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/algorithm.go#L33-L41 |
12,576 | DavidBelicza/TextRank | rank/algorithm.go | WeightingRelation | func (a *AlgorithmChain) WeightingRelation(
word1ID int,
word2ID int,
rank *Rank,
) float32 {
relationQty := rank.Relation.Node[word1ID][word2ID].Qty
word1Qty := rank.Words[word1ID].Qty
word2Qty := rank.Words[word2ID].Qty
qDiff := float32(math.Abs(float64(word1Qty)-float64(word2Qty))) / 100
weight := float32(relationQty) + qDiff
return weight
} | go | func (a *AlgorithmChain) WeightingRelation(
word1ID int,
word2ID int,
rank *Rank,
) float32 {
relationQty := rank.Relation.Node[word1ID][word2ID].Qty
word1Qty := rank.Words[word1ID].Qty
word2Qty := rank.Words[word2ID].Qty
qDiff := float32(math.Abs(float64(word1Qty)-float64(word2Qty))) / 100
weight := float32(relationQty) + qDiff
return weight
} | [
"func",
"(",
"a",
"*",
"AlgorithmChain",
")",
"WeightingRelation",
"(",
"word1ID",
"int",
",",
"word2ID",
"int",
",",
"rank",
"*",
"Rank",
",",
")",
"float32",
"{",
"relationQty",
":=",
"rank",
".",
"Relation",
".",
"Node",
"[",
"word1ID",
"]",
"[",
"word2ID",
"]",
".",
"Qty",
"\n",
"word1Qty",
":=",
"rank",
".",
"Words",
"[",
"word1ID",
"]",
".",
"Qty",
"\n",
"word2Qty",
":=",
"rank",
".",
"Words",
"[",
"word2ID",
"]",
".",
"Qty",
"\n\n",
"qDiff",
":=",
"float32",
"(",
"math",
".",
"Abs",
"(",
"float64",
"(",
"word1Qty",
")",
"-",
"float64",
"(",
"word2Qty",
")",
")",
")",
"/",
"100",
"\n",
"weight",
":=",
"float32",
"(",
"relationQty",
")",
"+",
"qDiff",
"\n\n",
"return",
"weight",
"\n",
"}"
] | // WeightingRelation method is a combined algorithm of text rank and word
// occurrence, it weights a phrase. | [
"WeightingRelation",
"method",
"is",
"a",
"combined",
"algorithm",
"of",
"text",
"rank",
"and",
"word",
"occurrence",
"it",
"weights",
"a",
"phrase",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/algorithm.go#L65-L78 |
12,577 | DavidBelicza/TextRank | textrank.go | Populate | func (textRank *TextRank) Populate(
text string,
lang convert.Language,
rule parse.Rule,
) {
parsedText := parse.TokenizeText(text, rule)
for _, sentence := range parsedText.GetSentences() {
convert.TextToRank(sentence, lang, textRank.rank)
}
} | go | func (textRank *TextRank) Populate(
text string,
lang convert.Language,
rule parse.Rule,
) {
parsedText := parse.TokenizeText(text, rule)
for _, sentence := range parsedText.GetSentences() {
convert.TextToRank(sentence, lang, textRank.rank)
}
} | [
"func",
"(",
"textRank",
"*",
"TextRank",
")",
"Populate",
"(",
"text",
"string",
",",
"lang",
"convert",
".",
"Language",
",",
"rule",
"parse",
".",
"Rule",
",",
")",
"{",
"parsedText",
":=",
"parse",
".",
"TokenizeText",
"(",
"text",
",",
"rule",
")",
"\n\n",
"for",
"_",
",",
"sentence",
":=",
"range",
"parsedText",
".",
"GetSentences",
"(",
")",
"{",
"convert",
".",
"TextToRank",
"(",
"sentence",
",",
"lang",
",",
"textRank",
".",
"rank",
")",
"\n",
"}",
"\n",
"}"
] | // Populate method adds a raw text to the text-ranking graph. It parses,
// tokenize the raw text and prepares it to weighting and scoring. It's possible
// to append a new raw text to an existing one even if the previously text is
// already ranked. This is 5th step to use TextRank.
//
// text string must be a plain text from TXT or PDF or any document, it can
// contain new lines, break lines or any unnecessary text parts, but it should
// not contain HTML tags or codes.
//
// lang Language object can be loaded from NewDefaultLanguage function.
//
// rule Rule object can be loaded from NewDefaultRule function. | [
"Populate",
"method",
"adds",
"a",
"raw",
"text",
"to",
"the",
"text",
"-",
"ranking",
"graph",
".",
"It",
"parses",
"tokenize",
"the",
"raw",
"text",
"and",
"prepares",
"it",
"to",
"weighting",
"and",
"scoring",
".",
"It",
"s",
"possible",
"to",
"append",
"a",
"new",
"raw",
"text",
"to",
"an",
"existing",
"one",
"even",
"if",
"the",
"previously",
"text",
"is",
"already",
"ranked",
".",
"This",
"is",
"5th",
"step",
"to",
"use",
"TextRank",
".",
"text",
"string",
"must",
"be",
"a",
"plain",
"text",
"from",
"TXT",
"or",
"PDF",
"or",
"any",
"document",
"it",
"can",
"contain",
"new",
"lines",
"break",
"lines",
"or",
"any",
"unnecessary",
"text",
"parts",
"but",
"it",
"should",
"not",
"contain",
"HTML",
"tags",
"or",
"codes",
".",
"lang",
"Language",
"object",
"can",
"be",
"loaded",
"from",
"NewDefaultLanguage",
"function",
".",
"rule",
"Rule",
"object",
"can",
"be",
"loaded",
"from",
"NewDefaultRule",
"function",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/textrank.go#L73-L83 |
12,578 | DavidBelicza/TextRank | textrank.go | Ranking | func (textRank *TextRank) Ranking(algorithm rank.Algorithm) {
rank.Calculate(textRank.rank, algorithm)
} | go | func (textRank *TextRank) Ranking(algorithm rank.Algorithm) {
rank.Calculate(textRank.rank, algorithm)
} | [
"func",
"(",
"textRank",
"*",
"TextRank",
")",
"Ranking",
"(",
"algorithm",
"rank",
".",
"Algorithm",
")",
"{",
"rank",
".",
"Calculate",
"(",
"textRank",
".",
"rank",
",",
"algorithm",
")",
"\n",
"}"
] | // Ranking method counts the words and connections between the words, then it
// weights the numbers then normalize them in type float32 between 0.00 and
// 1.00. This is the 6th step to use TextRank.
//
// algorithm Algorithm is the object of the weighting and scoring methods. | [
"Ranking",
"method",
"counts",
"the",
"words",
"and",
"connections",
"between",
"the",
"words",
"then",
"it",
"weights",
"the",
"numbers",
"then",
"normalize",
"them",
"in",
"type",
"float32",
"between",
"0",
".",
"00",
"and",
"1",
".",
"00",
".",
"This",
"is",
"the",
"6th",
"step",
"to",
"use",
"TextRank",
".",
"algorithm",
"Algorithm",
"is",
"the",
"object",
"of",
"the",
"weighting",
"and",
"scoring",
"methods",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/textrank.go#L90-L92 |
12,579 | DavidBelicza/TextRank | textrank.go | FindSentencesByRelationWeight | func FindSentencesByRelationWeight(
textRank *TextRank,
limit int,
) []rank.Sentence {
return rank.FindSentences(textRank.rank, rank.ByRelation, limit)
} | go | func FindSentencesByRelationWeight(
textRank *TextRank,
limit int,
) []rank.Sentence {
return rank.FindSentences(textRank.rank, rank.ByRelation, limit)
} | [
"func",
"FindSentencesByRelationWeight",
"(",
"textRank",
"*",
"TextRank",
",",
"limit",
"int",
",",
")",
"[",
"]",
"rank",
".",
"Sentence",
"{",
"return",
"rank",
".",
"FindSentences",
"(",
"textRank",
".",
"rank",
",",
"rank",
".",
"ByRelation",
",",
"limit",
")",
"\n",
"}"
] | // FindSentencesByRelationWeight function retrieves a slice of Sentence
// structures by TextRank object. The return value contains the ID of the
// sentence and the sentence text itself. The slice is sorted by weight of
// phrases from 1 to 0. | [
"FindSentencesByRelationWeight",
"function",
"retrieves",
"a",
"slice",
"of",
"Sentence",
"structures",
"by",
"TextRank",
"object",
".",
"The",
"return",
"value",
"contains",
"the",
"ID",
"of",
"the",
"sentence",
"and",
"the",
"sentence",
"text",
"itself",
".",
"The",
"slice",
"is",
"sorted",
"by",
"weight",
"of",
"phrases",
"from",
"1",
"to",
"0",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/textrank.go#L123-L129 |
12,580 | DavidBelicza/TextRank | textrank.go | FindSentencesByWordQtyWeight | func FindSentencesByWordQtyWeight(
textRank *TextRank,
limit int,
) []rank.Sentence {
return rank.FindSentences(textRank.rank, rank.ByQty, limit)
} | go | func FindSentencesByWordQtyWeight(
textRank *TextRank,
limit int,
) []rank.Sentence {
return rank.FindSentences(textRank.rank, rank.ByQty, limit)
} | [
"func",
"FindSentencesByWordQtyWeight",
"(",
"textRank",
"*",
"TextRank",
",",
"limit",
"int",
",",
")",
"[",
"]",
"rank",
".",
"Sentence",
"{",
"return",
"rank",
".",
"FindSentences",
"(",
"textRank",
".",
"rank",
",",
"rank",
".",
"ByQty",
",",
"limit",
")",
"\n",
"}"
] | // FindSentencesByWordQtyWeight function retrieves a slice of Sentence
// structures by TextRank object. The return value contains the ID of the
// sentence and the sentence text itself. The slice is sorted by weight of word
// quantities from 1 to 0. | [
"FindSentencesByWordQtyWeight",
"function",
"retrieves",
"a",
"slice",
"of",
"Sentence",
"structures",
"by",
"TextRank",
"object",
".",
"The",
"return",
"value",
"contains",
"the",
"ID",
"of",
"the",
"sentence",
"and",
"the",
"sentence",
"text",
"itself",
".",
"The",
"slice",
"is",
"sorted",
"by",
"weight",
"of",
"word",
"quantities",
"from",
"1",
"to",
"0",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/textrank.go#L135-L141 |
12,581 | DavidBelicza/TextRank | textrank.go | FindSentencesFrom | func FindSentencesFrom(
textRank *TextRank,
sentenceID int,
limit int,
) []rank.Sentence {
return rank.FindSentencesFrom(textRank.rank, sentenceID, limit)
} | go | func FindSentencesFrom(
textRank *TextRank,
sentenceID int,
limit int,
) []rank.Sentence {
return rank.FindSentencesFrom(textRank.rank, sentenceID, limit)
} | [
"func",
"FindSentencesFrom",
"(",
"textRank",
"*",
"TextRank",
",",
"sentenceID",
"int",
",",
"limit",
"int",
",",
")",
"[",
"]",
"rank",
".",
"Sentence",
"{",
"return",
"rank",
".",
"FindSentencesFrom",
"(",
"textRank",
".",
"rank",
",",
"sentenceID",
",",
"limit",
")",
"\n",
"}"
] | // FindSentencesFrom function retrieves a slice of Sentence structures by
// TextRank object and by ID of the sentence. The return value contains the
// sentence text itself. The returned slice contains sentences sorted by their
// IDs started from the given sentence ID in ascending sort. | [
"FindSentencesFrom",
"function",
"retrieves",
"a",
"slice",
"of",
"Sentence",
"structures",
"by",
"TextRank",
"object",
"and",
"by",
"ID",
"of",
"the",
"sentence",
".",
"The",
"return",
"value",
"contains",
"the",
"sentence",
"text",
"itself",
".",
"The",
"returned",
"slice",
"contains",
"sentences",
"sorted",
"by",
"their",
"IDs",
"started",
"from",
"the",
"given",
"sentence",
"ID",
"in",
"ascending",
"sort",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/textrank.go#L187-L194 |
12,582 | DavidBelicza/TextRank | parse/rule.go | IsWordSeparator | func (r *RuleDefault) IsWordSeparator(rune rune) bool {
chr := string(rune)
for _, val := range r.wordSeparators {
if chr == val {
return true
}
}
return r.IsSentenceSeparator(rune)
} | go | func (r *RuleDefault) IsWordSeparator(rune rune) bool {
chr := string(rune)
for _, val := range r.wordSeparators {
if chr == val {
return true
}
}
return r.IsSentenceSeparator(rune)
} | [
"func",
"(",
"r",
"*",
"RuleDefault",
")",
"IsWordSeparator",
"(",
"rune",
"rune",
")",
"bool",
"{",
"chr",
":=",
"string",
"(",
"rune",
")",
"\n\n",
"for",
"_",
",",
"val",
":=",
"range",
"r",
".",
"wordSeparators",
"{",
"if",
"chr",
"==",
"val",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"IsSentenceSeparator",
"(",
"rune",
")",
"\n",
"}"
] | // IsWordSeparator method retrieves true when a character is a kind of special
// character and possibly it separates to words from each other. It also checks
// for sentence separator by IsSentenceSeparator method. | [
"IsWordSeparator",
"method",
"retrieves",
"true",
"when",
"a",
"character",
"is",
"a",
"kind",
"of",
"special",
"character",
"and",
"possibly",
"it",
"separates",
"to",
"words",
"from",
"each",
"other",
".",
"It",
"also",
"checks",
"for",
"sentence",
"separator",
"by",
"IsSentenceSeparator",
"method",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/parse/rule.go#L28-L38 |
12,583 | DavidBelicza/TextRank | parse/rule.go | IsSentenceSeparator | func (r *RuleDefault) IsSentenceSeparator(rune rune) bool {
chr := string(rune)
for _, val := range r.sentenceSeparators {
if chr == val {
return true
}
}
return false
} | go | func (r *RuleDefault) IsSentenceSeparator(rune rune) bool {
chr := string(rune)
for _, val := range r.sentenceSeparators {
if chr == val {
return true
}
}
return false
} | [
"func",
"(",
"r",
"*",
"RuleDefault",
")",
"IsSentenceSeparator",
"(",
"rune",
"rune",
")",
"bool",
"{",
"chr",
":=",
"string",
"(",
"rune",
")",
"\n\n",
"for",
"_",
",",
"val",
":=",
"range",
"r",
".",
"sentenceSeparators",
"{",
"if",
"chr",
"==",
"val",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // IsSentenceSeparator method retrieves true when a character is a kind of
// special character and possibly it separates to words from each other. | [
"IsSentenceSeparator",
"method",
"retrieves",
"true",
"when",
"a",
"character",
"is",
"a",
"kind",
"of",
"special",
"character",
"and",
"possibly",
"it",
"separates",
"to",
"words",
"from",
"each",
"other",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/parse/rule.go#L42-L52 |
12,584 | DavidBelicza/TextRank | convert/language.go | NewLanguage | func NewLanguage() *LanguageDefault {
lang := &LanguageDefault{
"en",
make(map[string][]string),
}
words := getDefaultEnglish()
lang.SetWords("en", words)
return lang
} | go | func NewLanguage() *LanguageDefault {
lang := &LanguageDefault{
"en",
make(map[string][]string),
}
words := getDefaultEnglish()
lang.SetWords("en", words)
return lang
} | [
"func",
"NewLanguage",
"(",
")",
"*",
"LanguageDefault",
"{",
"lang",
":=",
"&",
"LanguageDefault",
"{",
"\"",
"\"",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
",",
"}",
"\n\n",
"words",
":=",
"getDefaultEnglish",
"(",
")",
"\n\n",
"lang",
".",
"SetWords",
"(",
"\"",
"\"",
",",
"words",
")",
"\n\n",
"return",
"lang",
"\n",
"}"
] | // NewLanguage constructor of the LanguageDefault Retrieves a pointer
// LanguageDefault. It has setup to English by default. | [
"NewLanguage",
"constructor",
"of",
"the",
"LanguageDefault",
"Retrieves",
"a",
"pointer",
"LanguageDefault",
".",
"It",
"has",
"setup",
"to",
"English",
"by",
"default",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/convert/language.go#L23-L34 |
12,585 | DavidBelicza/TextRank | convert/language.go | IsStopWord | func (lang *LanguageDefault) IsStopWord(word string) bool {
if utf8.RuneCountInString(word) <= 2 {
return true
}
if stopWords, ok := lang.languages[lang.defaultLang]; ok {
for _, val := range stopWords {
if val == word {
return true
}
}
}
return false
} | go | func (lang *LanguageDefault) IsStopWord(word string) bool {
if utf8.RuneCountInString(word) <= 2 {
return true
}
if stopWords, ok := lang.languages[lang.defaultLang]; ok {
for _, val := range stopWords {
if val == word {
return true
}
}
}
return false
} | [
"func",
"(",
"lang",
"*",
"LanguageDefault",
")",
"IsStopWord",
"(",
"word",
"string",
")",
"bool",
"{",
"if",
"utf8",
".",
"RuneCountInString",
"(",
"word",
")",
"<=",
"2",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"stopWords",
",",
"ok",
":=",
"lang",
".",
"languages",
"[",
"lang",
".",
"defaultLang",
"]",
";",
"ok",
"{",
"for",
"_",
",",
"val",
":=",
"range",
"stopWords",
"{",
"if",
"val",
"==",
"word",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // IsStopWord method retrieves true when the given word is in the stop word
// list or when the word has less character then 2. | [
"IsStopWord",
"method",
"retrieves",
"true",
"when",
"the",
"given",
"word",
"is",
"in",
"the",
"stop",
"word",
"list",
"or",
"when",
"the",
"word",
"has",
"less",
"character",
"then",
"2",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/convert/language.go#L38-L52 |
12,586 | DavidBelicza/TextRank | convert/language.go | SetWords | func (lang *LanguageDefault) SetWords(code string, words []string) {
lang.languages[code] = words
} | go | func (lang *LanguageDefault) SetWords(code string, words []string) {
lang.languages[code] = words
} | [
"func",
"(",
"lang",
"*",
"LanguageDefault",
")",
"SetWords",
"(",
"code",
"string",
",",
"words",
"[",
"]",
"string",
")",
"{",
"lang",
".",
"languages",
"[",
"code",
"]",
"=",
"words",
"\n",
"}"
] | // SetWords method set stop words into the LanguageDefault struct by the
// language's code. | [
"SetWords",
"method",
"set",
"stop",
"words",
"into",
"the",
"LanguageDefault",
"struct",
"by",
"the",
"language",
"s",
"code",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/convert/language.go#L69-L71 |
12,587 | DavidBelicza/TextRank | rank/rank.go | NewRank | func NewRank() *Rank {
return &Rank{
0,
0,
Relation{
0,
0,
make(map[int]map[int]Score),
},
make(map[int]string),
make(map[int]*Word),
make(map[string]int),
}
} | go | func NewRank() *Rank {
return &Rank{
0,
0,
Relation{
0,
0,
make(map[int]map[int]Score),
},
make(map[int]string),
make(map[int]*Word),
make(map[string]int),
}
} | [
"func",
"NewRank",
"(",
")",
"*",
"Rank",
"{",
"return",
"&",
"Rank",
"{",
"0",
",",
"0",
",",
"Relation",
"{",
"0",
",",
"0",
",",
"make",
"(",
"map",
"[",
"int",
"]",
"map",
"[",
"int",
"]",
"Score",
")",
",",
"}",
",",
"make",
"(",
"map",
"[",
"int",
"]",
"string",
")",
",",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"Word",
")",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
",",
"}",
"\n",
"}"
] | // NewRank constructor retrieves a Rank pointer. | [
"NewRank",
"constructor",
"retrieves",
"a",
"Rank",
"pointer",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/rank.go#L59-L72 |
12,588 | DavidBelicza/TextRank | rank/rank.go | IsWordExist | func (rank *Rank) IsWordExist(word string) bool {
_, find := rank.WordValID[word]
return find
} | go | func (rank *Rank) IsWordExist(word string) bool {
_, find := rank.WordValID[word]
return find
} | [
"func",
"(",
"rank",
"*",
"Rank",
")",
"IsWordExist",
"(",
"word",
"string",
")",
"bool",
"{",
"_",
",",
"find",
":=",
"rank",
".",
"WordValID",
"[",
"word",
"]",
"\n\n",
"return",
"find",
"\n",
"}"
] | // IsWordExist method retrieves true when the given word is already in the rank. | [
"IsWordExist",
"method",
"retrieves",
"true",
"when",
"the",
"given",
"word",
"is",
"already",
"in",
"the",
"rank",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/rank.go#L75-L79 |
12,589 | DavidBelicza/TextRank | rank/rank.go | AddNewWord | func (rank *Rank) AddNewWord(word string, prevWordIdx int, sentenceID int) (wordID int) {
wordID = len(rank.Words)
connectionLeft := make(map[int]int)
if prevWordIdx >= 0 {
connectionLeft[prevWordIdx] = 1
}
newWord := &Word{
ID: wordID,
SentenceIDs: []int{sentenceID},
ConnectionLeft: connectionLeft,
ConnectionRight: make(map[int]int),
Token: word,
Qty: 1,
Weight: 0,
}
rank.Words[wordID] = newWord
rank.WordValID[word] = wordID
return
} | go | func (rank *Rank) AddNewWord(word string, prevWordIdx int, sentenceID int) (wordID int) {
wordID = len(rank.Words)
connectionLeft := make(map[int]int)
if prevWordIdx >= 0 {
connectionLeft[prevWordIdx] = 1
}
newWord := &Word{
ID: wordID,
SentenceIDs: []int{sentenceID},
ConnectionLeft: connectionLeft,
ConnectionRight: make(map[int]int),
Token: word,
Qty: 1,
Weight: 0,
}
rank.Words[wordID] = newWord
rank.WordValID[word] = wordID
return
} | [
"func",
"(",
"rank",
"*",
"Rank",
")",
"AddNewWord",
"(",
"word",
"string",
",",
"prevWordIdx",
"int",
",",
"sentenceID",
"int",
")",
"(",
"wordID",
"int",
")",
"{",
"wordID",
"=",
"len",
"(",
"rank",
".",
"Words",
")",
"\n",
"connectionLeft",
":=",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
"\n\n",
"if",
"prevWordIdx",
">=",
"0",
"{",
"connectionLeft",
"[",
"prevWordIdx",
"]",
"=",
"1",
"\n",
"}",
"\n\n",
"newWord",
":=",
"&",
"Word",
"{",
"ID",
":",
"wordID",
",",
"SentenceIDs",
":",
"[",
"]",
"int",
"{",
"sentenceID",
"}",
",",
"ConnectionLeft",
":",
"connectionLeft",
",",
"ConnectionRight",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
",",
"Token",
":",
"word",
",",
"Qty",
":",
"1",
",",
"Weight",
":",
"0",
",",
"}",
"\n\n",
"rank",
".",
"Words",
"[",
"wordID",
"]",
"=",
"newWord",
"\n",
"rank",
".",
"WordValID",
"[",
"word",
"]",
"=",
"wordID",
"\n\n",
"return",
"\n",
"}"
] | // AddNewWord method adds a new word to the rank object and it defines its ID. | [
"AddNewWord",
"method",
"adds",
"a",
"new",
"word",
"to",
"the",
"rank",
"object",
"and",
"it",
"defines",
"its",
"ID",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/rank.go#L82-L104 |
12,590 | DavidBelicza/TextRank | rank/rank.go | UpdateWord | func (rank *Rank) UpdateWord(word string, prevWordIdx int, sentenceID int) (wordID int) {
wordID = rank.WordValID[word]
found := false
for _, oldSentenceID := range rank.Words[wordID].SentenceIDs {
if sentenceID == oldSentenceID {
found = true
break
}
}
if !found {
rank.Words[wordID].SentenceIDs = append(
rank.Words[wordID].SentenceIDs,
sentenceID,
)
}
rank.Words[wordID].Qty++
if prevWordIdx >= 0 {
rank.Words[wordID].ConnectionLeft[prevWordIdx]++
}
return
} | go | func (rank *Rank) UpdateWord(word string, prevWordIdx int, sentenceID int) (wordID int) {
wordID = rank.WordValID[word]
found := false
for _, oldSentenceID := range rank.Words[wordID].SentenceIDs {
if sentenceID == oldSentenceID {
found = true
break
}
}
if !found {
rank.Words[wordID].SentenceIDs = append(
rank.Words[wordID].SentenceIDs,
sentenceID,
)
}
rank.Words[wordID].Qty++
if prevWordIdx >= 0 {
rank.Words[wordID].ConnectionLeft[prevWordIdx]++
}
return
} | [
"func",
"(",
"rank",
"*",
"Rank",
")",
"UpdateWord",
"(",
"word",
"string",
",",
"prevWordIdx",
"int",
",",
"sentenceID",
"int",
")",
"(",
"wordID",
"int",
")",
"{",
"wordID",
"=",
"rank",
".",
"WordValID",
"[",
"word",
"]",
"\n\n",
"found",
":=",
"false",
"\n\n",
"for",
"_",
",",
"oldSentenceID",
":=",
"range",
"rank",
".",
"Words",
"[",
"wordID",
"]",
".",
"SentenceIDs",
"{",
"if",
"sentenceID",
"==",
"oldSentenceID",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"found",
"{",
"rank",
".",
"Words",
"[",
"wordID",
"]",
".",
"SentenceIDs",
"=",
"append",
"(",
"rank",
".",
"Words",
"[",
"wordID",
"]",
".",
"SentenceIDs",
",",
"sentenceID",
",",
")",
"\n",
"}",
"\n\n",
"rank",
".",
"Words",
"[",
"wordID",
"]",
".",
"Qty",
"++",
"\n\n",
"if",
"prevWordIdx",
">=",
"0",
"{",
"rank",
".",
"Words",
"[",
"wordID",
"]",
".",
"ConnectionLeft",
"[",
"prevWordIdx",
"]",
"++",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // UpdateWord method update a word what already exists in the rank object. It
// retrieves its ID. | [
"UpdateWord",
"method",
"update",
"a",
"word",
"what",
"already",
"exists",
"in",
"the",
"rank",
"object",
".",
"It",
"retrieves",
"its",
"ID",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/rank.go#L108-L134 |
12,591 | DavidBelicza/TextRank | rank/rank.go | UpdateRightConnection | func (rank *Rank) UpdateRightConnection(wordID int, rightWordID int) {
if wordID >= 0 {
rank.Words[wordID].ConnectionRight[rightWordID]++
}
} | go | func (rank *Rank) UpdateRightConnection(wordID int, rightWordID int) {
if wordID >= 0 {
rank.Words[wordID].ConnectionRight[rightWordID]++
}
} | [
"func",
"(",
"rank",
"*",
"Rank",
")",
"UpdateRightConnection",
"(",
"wordID",
"int",
",",
"rightWordID",
"int",
")",
"{",
"if",
"wordID",
">=",
"0",
"{",
"rank",
".",
"Words",
"[",
"wordID",
"]",
".",
"ConnectionRight",
"[",
"rightWordID",
"]",
"++",
"\n",
"}",
"\n",
"}"
] | // UpdateRightConnection method adds the right connection to the word. It always
// can be used after a word has added and the next word is known. | [
"UpdateRightConnection",
"method",
"adds",
"the",
"right",
"connection",
"to",
"the",
"word",
".",
"It",
"always",
"can",
"be",
"used",
"after",
"a",
"word",
"has",
"added",
"and",
"the",
"next",
"word",
"is",
"known",
"."
] | 79e14bab980af3a1c9f4f5b73672ae1ef18ab732 | https://github.com/DavidBelicza/TextRank/blob/79e14bab980af3a1c9f4f5b73672ae1ef18ab732/rank/rank.go#L138-L142 |
12,592 | FDio/govpp | core/request_handler.go | watchRequests | func (c *Connection) watchRequests(ch *Channel) {
for {
select {
case req, ok := <-ch.reqChan:
// new request on the request channel
if !ok {
// after closing the request channel, release API channel and return
c.releaseAPIChannel(ch)
return
}
if err := c.processRequest(ch, req); err != nil {
sendReplyError(ch, req, err)
}
}
}
} | go | func (c *Connection) watchRequests(ch *Channel) {
for {
select {
case req, ok := <-ch.reqChan:
// new request on the request channel
if !ok {
// after closing the request channel, release API channel and return
c.releaseAPIChannel(ch)
return
}
if err := c.processRequest(ch, req); err != nil {
sendReplyError(ch, req, err)
}
}
}
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"watchRequests",
"(",
"ch",
"*",
"Channel",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"req",
",",
"ok",
":=",
"<-",
"ch",
".",
"reqChan",
":",
"// new request on the request channel",
"if",
"!",
"ok",
"{",
"// after closing the request channel, release API channel and return",
"c",
".",
"releaseAPIChannel",
"(",
"ch",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"processRequest",
"(",
"ch",
",",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"sendReplyError",
"(",
"ch",
",",
"req",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // watchRequests watches for requests on the request API channel and forwards them as messages to VPP. | [
"watchRequests",
"watches",
"for",
"requests",
"on",
"the",
"request",
"API",
"channel",
"and",
"forwards",
"them",
"as",
"messages",
"to",
"VPP",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/request_handler.go#L34-L49 |
12,593 | FDio/govpp | core/request_handler.go | processRequest | func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
// check whether we are connected to VPP
if atomic.LoadUint32(&c.vppConnected) == 0 {
err := ErrNotConnected
log.Errorf("processing request failed: %v", err)
return err
}
// retrieve message ID
msgID, err := c.GetMessageID(req.msg)
if err != nil {
log.WithFields(logger.Fields{
"msg_name": req.msg.GetMessageName(),
"msg_crc": req.msg.GetCrcString(),
"seq_num": req.seqNum,
"error": err,
}).Errorf("failed to retrieve message ID")
return fmt.Errorf("unable to retrieve message ID: %v", err)
}
// encode the message into binary
data, err := c.codec.EncodeMsg(req.msg, msgID)
if err != nil {
log.WithFields(logger.Fields{
"channel": ch.id,
"msg_id": msgID,
"msg_name": req.msg.GetMessageName(),
"seq_num": req.seqNum,
"error": err,
}).Errorf("failed to encode message: %#v", req.msg)
return fmt.Errorf("unable to encode the message: %v", err)
}
context := packRequestContext(ch.id, req.multi, req.seqNum)
if log.Level == logger.DebugLevel { // for performance reasons - logrus does some processing even if debugs are disabled
log.WithFields(logger.Fields{
"channel": ch.id,
"context": context,
"is_multi": req.multi,
"msg_id": msgID,
"msg_size": len(data),
"seq_num": req.seqNum,
"msg_crc": req.msg.GetCrcString(),
}).Debugf("--> govpp send: %s: %+v", req.msg.GetMessageName(), req.msg)
}
// send the request to VPP
err = c.vppClient.SendMsg(context, data)
if err != nil {
err = fmt.Errorf("unable to send the message: %v", err)
log.WithFields(logger.Fields{
"context": context,
"msg_id": msgID,
"seq_num": req.seqNum,
}).Error(err)
return err
}
if req.multi {
// send a control ping to determine end of the multipart response
pingData, _ := c.codec.EncodeMsg(msgControlPing, c.pingReqID)
log.WithFields(logger.Fields{
"channel": ch.id,
"context": context,
"msg_id": c.pingReqID,
"msg_size": len(pingData),
"seq_num": req.seqNum,
}).Debug(" -> sending control ping")
if err := c.vppClient.SendMsg(context, pingData); err != nil {
log.WithFields(logger.Fields{
"context": context,
"msg_id": msgID,
"seq_num": req.seqNum,
}).Warnf("unable to send control ping: %v", err)
}
}
return nil
} | go | func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
// check whether we are connected to VPP
if atomic.LoadUint32(&c.vppConnected) == 0 {
err := ErrNotConnected
log.Errorf("processing request failed: %v", err)
return err
}
// retrieve message ID
msgID, err := c.GetMessageID(req.msg)
if err != nil {
log.WithFields(logger.Fields{
"msg_name": req.msg.GetMessageName(),
"msg_crc": req.msg.GetCrcString(),
"seq_num": req.seqNum,
"error": err,
}).Errorf("failed to retrieve message ID")
return fmt.Errorf("unable to retrieve message ID: %v", err)
}
// encode the message into binary
data, err := c.codec.EncodeMsg(req.msg, msgID)
if err != nil {
log.WithFields(logger.Fields{
"channel": ch.id,
"msg_id": msgID,
"msg_name": req.msg.GetMessageName(),
"seq_num": req.seqNum,
"error": err,
}).Errorf("failed to encode message: %#v", req.msg)
return fmt.Errorf("unable to encode the message: %v", err)
}
context := packRequestContext(ch.id, req.multi, req.seqNum)
if log.Level == logger.DebugLevel { // for performance reasons - logrus does some processing even if debugs are disabled
log.WithFields(logger.Fields{
"channel": ch.id,
"context": context,
"is_multi": req.multi,
"msg_id": msgID,
"msg_size": len(data),
"seq_num": req.seqNum,
"msg_crc": req.msg.GetCrcString(),
}).Debugf("--> govpp send: %s: %+v", req.msg.GetMessageName(), req.msg)
}
// send the request to VPP
err = c.vppClient.SendMsg(context, data)
if err != nil {
err = fmt.Errorf("unable to send the message: %v", err)
log.WithFields(logger.Fields{
"context": context,
"msg_id": msgID,
"seq_num": req.seqNum,
}).Error(err)
return err
}
if req.multi {
// send a control ping to determine end of the multipart response
pingData, _ := c.codec.EncodeMsg(msgControlPing, c.pingReqID)
log.WithFields(logger.Fields{
"channel": ch.id,
"context": context,
"msg_id": c.pingReqID,
"msg_size": len(pingData),
"seq_num": req.seqNum,
}).Debug(" -> sending control ping")
if err := c.vppClient.SendMsg(context, pingData); err != nil {
log.WithFields(logger.Fields{
"context": context,
"msg_id": msgID,
"seq_num": req.seqNum,
}).Warnf("unable to send control ping: %v", err)
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"processRequest",
"(",
"ch",
"*",
"Channel",
",",
"req",
"*",
"vppRequest",
")",
"error",
"{",
"// check whether we are connected to VPP",
"if",
"atomic",
".",
"LoadUint32",
"(",
"&",
"c",
".",
"vppConnected",
")",
"==",
"0",
"{",
"err",
":=",
"ErrNotConnected",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// retrieve message ID",
"msgID",
",",
"err",
":=",
"c",
".",
"GetMessageID",
"(",
"req",
".",
"msg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"req",
".",
"msg",
".",
"GetMessageName",
"(",
")",
",",
"\"",
"\"",
":",
"req",
".",
"msg",
".",
"GetCrcString",
"(",
")",
",",
"\"",
"\"",
":",
"req",
".",
"seqNum",
",",
"\"",
"\"",
":",
"err",
",",
"}",
")",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// encode the message into binary",
"data",
",",
"err",
":=",
"c",
".",
"codec",
".",
"EncodeMsg",
"(",
"req",
".",
"msg",
",",
"msgID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"ch",
".",
"id",
",",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"req",
".",
"msg",
".",
"GetMessageName",
"(",
")",
",",
"\"",
"\"",
":",
"req",
".",
"seqNum",
",",
"\"",
"\"",
":",
"err",
",",
"}",
")",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"req",
".",
"msg",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"context",
":=",
"packRequestContext",
"(",
"ch",
".",
"id",
",",
"req",
".",
"multi",
",",
"req",
".",
"seqNum",
")",
"\n\n",
"if",
"log",
".",
"Level",
"==",
"logger",
".",
"DebugLevel",
"{",
"// for performance reasons - logrus does some processing even if debugs are disabled",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"ch",
".",
"id",
",",
"\"",
"\"",
":",
"context",
",",
"\"",
"\"",
":",
"req",
".",
"multi",
",",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"len",
"(",
"data",
")",
",",
"\"",
"\"",
":",
"req",
".",
"seqNum",
",",
"\"",
"\"",
":",
"req",
".",
"msg",
".",
"GetCrcString",
"(",
")",
",",
"}",
")",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"req",
".",
"msg",
".",
"GetMessageName",
"(",
")",
",",
"req",
".",
"msg",
")",
"\n",
"}",
"\n\n",
"// send the request to VPP",
"err",
"=",
"c",
".",
"vppClient",
".",
"SendMsg",
"(",
"context",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"context",
",",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"req",
".",
"seqNum",
",",
"}",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"req",
".",
"multi",
"{",
"// send a control ping to determine end of the multipart response",
"pingData",
",",
"_",
":=",
"c",
".",
"codec",
".",
"EncodeMsg",
"(",
"msgControlPing",
",",
"c",
".",
"pingReqID",
")",
"\n\n",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"ch",
".",
"id",
",",
"\"",
"\"",
":",
"context",
",",
"\"",
"\"",
":",
"c",
".",
"pingReqID",
",",
"\"",
"\"",
":",
"len",
"(",
"pingData",
")",
",",
"\"",
"\"",
":",
"req",
".",
"seqNum",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"vppClient",
".",
"SendMsg",
"(",
"context",
",",
"pingData",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"context",
",",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"req",
".",
"seqNum",
",",
"}",
")",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // processRequest processes a single request received on the request channel. | [
"processRequest",
"processes",
"a",
"single",
"request",
"received",
"on",
"the",
"request",
"channel",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/request_handler.go#L52-L133 |
12,594 | FDio/govpp | core/request_handler.go | msgCallback | func (c *Connection) msgCallback(msgID uint16, data []byte) {
if c == nil {
log.Warn("Already disconnected, ignoring the message.")
return
}
msg, ok := c.msgMap[msgID]
if !ok {
log.Warnf("Unknown message received, ID: %d", msgID)
return
}
// decode message context to fix for special cases of messages,
// for example:
// - replies that don't have context as first field (comes as zero)
// - events that don't have context at all (comes as non zero)
//
context, err := c.codec.DecodeMsgContext(data, msg)
if err != nil {
log.Errorf("decoding context failed: %v", err)
}
chanID, isMulti, seqNum := unpackRequestContext(context)
if log.Level == logger.DebugLevel { // for performance reasons - logrus does some processing even if debugs are disabled
log.WithFields(logger.Fields{
"context": context,
"msg_id": msgID,
"msg_size": len(data),
"channel": chanID,
"is_multi": isMulti,
"seq_num": seqNum,
"msg_crc": msg.GetCrcString(),
}).Debugf("<-- govpp recv: %s", msg.GetMessageName())
}
if context == 0 || c.isNotificationMessage(msgID) {
// process the message as a notification
c.sendNotifications(msgID, data)
return
}
// match ch according to the context
c.channelsLock.RLock()
ch, ok := c.channels[chanID]
c.channelsLock.RUnlock()
if !ok {
log.WithFields(logger.Fields{
"channel": chanID,
"msg_id": msgID,
}).Error("Channel ID not known, ignoring the message.")
return
}
// if this is a control ping reply to a multipart request,
// treat this as a last part of the reply
lastReplyReceived := isMulti && msgID == c.pingReplyID
// send the data to the channel, it needs to be copied,
// because it will be freed after this function returns
sendReply(ch, &vppReply{
msgID: msgID,
seqNum: seqNum,
data: append([]byte(nil), data...),
lastReceived: lastReplyReceived,
})
// store actual time of this reply
c.lastReplyLock.Lock()
c.lastReply = time.Now()
c.lastReplyLock.Unlock()
} | go | func (c *Connection) msgCallback(msgID uint16, data []byte) {
if c == nil {
log.Warn("Already disconnected, ignoring the message.")
return
}
msg, ok := c.msgMap[msgID]
if !ok {
log.Warnf("Unknown message received, ID: %d", msgID)
return
}
// decode message context to fix for special cases of messages,
// for example:
// - replies that don't have context as first field (comes as zero)
// - events that don't have context at all (comes as non zero)
//
context, err := c.codec.DecodeMsgContext(data, msg)
if err != nil {
log.Errorf("decoding context failed: %v", err)
}
chanID, isMulti, seqNum := unpackRequestContext(context)
if log.Level == logger.DebugLevel { // for performance reasons - logrus does some processing even if debugs are disabled
log.WithFields(logger.Fields{
"context": context,
"msg_id": msgID,
"msg_size": len(data),
"channel": chanID,
"is_multi": isMulti,
"seq_num": seqNum,
"msg_crc": msg.GetCrcString(),
}).Debugf("<-- govpp recv: %s", msg.GetMessageName())
}
if context == 0 || c.isNotificationMessage(msgID) {
// process the message as a notification
c.sendNotifications(msgID, data)
return
}
// match ch according to the context
c.channelsLock.RLock()
ch, ok := c.channels[chanID]
c.channelsLock.RUnlock()
if !ok {
log.WithFields(logger.Fields{
"channel": chanID,
"msg_id": msgID,
}).Error("Channel ID not known, ignoring the message.")
return
}
// if this is a control ping reply to a multipart request,
// treat this as a last part of the reply
lastReplyReceived := isMulti && msgID == c.pingReplyID
// send the data to the channel, it needs to be copied,
// because it will be freed after this function returns
sendReply(ch, &vppReply{
msgID: msgID,
seqNum: seqNum,
data: append([]byte(nil), data...),
lastReceived: lastReplyReceived,
})
// store actual time of this reply
c.lastReplyLock.Lock()
c.lastReply = time.Now()
c.lastReplyLock.Unlock()
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"msgCallback",
"(",
"msgID",
"uint16",
",",
"data",
"[",
"]",
"byte",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"log",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"msg",
",",
"ok",
":=",
"c",
".",
"msgMap",
"[",
"msgID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"msgID",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// decode message context to fix for special cases of messages,",
"// for example:",
"// - replies that don't have context as first field (comes as zero)",
"// - events that don't have context at all (comes as non zero)",
"//",
"context",
",",
"err",
":=",
"c",
".",
"codec",
".",
"DecodeMsgContext",
"(",
"data",
",",
"msg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"chanID",
",",
"isMulti",
",",
"seqNum",
":=",
"unpackRequestContext",
"(",
"context",
")",
"\n",
"if",
"log",
".",
"Level",
"==",
"logger",
".",
"DebugLevel",
"{",
"// for performance reasons - logrus does some processing even if debugs are disabled",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"context",
",",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"len",
"(",
"data",
")",
",",
"\"",
"\"",
":",
"chanID",
",",
"\"",
"\"",
":",
"isMulti",
",",
"\"",
"\"",
":",
"seqNum",
",",
"\"",
"\"",
":",
"msg",
".",
"GetCrcString",
"(",
")",
",",
"}",
")",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"msg",
".",
"GetMessageName",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"context",
"==",
"0",
"||",
"c",
".",
"isNotificationMessage",
"(",
"msgID",
")",
"{",
"// process the message as a notification",
"c",
".",
"sendNotifications",
"(",
"msgID",
",",
"data",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// match ch according to the context",
"c",
".",
"channelsLock",
".",
"RLock",
"(",
")",
"\n",
"ch",
",",
"ok",
":=",
"c",
".",
"channels",
"[",
"chanID",
"]",
"\n",
"c",
".",
"channelsLock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"chanID",
",",
"\"",
"\"",
":",
"msgID",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// if this is a control ping reply to a multipart request,",
"// treat this as a last part of the reply",
"lastReplyReceived",
":=",
"isMulti",
"&&",
"msgID",
"==",
"c",
".",
"pingReplyID",
"\n\n",
"// send the data to the channel, it needs to be copied,",
"// because it will be freed after this function returns",
"sendReply",
"(",
"ch",
",",
"&",
"vppReply",
"{",
"msgID",
":",
"msgID",
",",
"seqNum",
":",
"seqNum",
",",
"data",
":",
"append",
"(",
"[",
"]",
"byte",
"(",
"nil",
")",
",",
"data",
"...",
")",
",",
"lastReceived",
":",
"lastReplyReceived",
",",
"}",
")",
"\n\n",
"// store actual time of this reply",
"c",
".",
"lastReplyLock",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"lastReply",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"c",
".",
"lastReplyLock",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // msgCallback is called whenever any binary API message comes from VPP. | [
"msgCallback",
"is",
"called",
"whenever",
"any",
"binary",
"API",
"message",
"comes",
"from",
"VPP",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/request_handler.go#L136-L206 |
12,595 | FDio/govpp | core/request_handler.go | sendReply | func sendReply(ch *Channel, reply *vppReply) {
select {
case ch.replyChan <- reply:
// reply sent successfully
case <-time.After(ReplyChannelTimeout):
// receiver still not ready
log.WithFields(logger.Fields{
"channel": ch,
"msg_id": reply.msgID,
"seq_num": reply.seqNum,
}).Warn("Unable to send the reply, reciever end not ready.")
}
} | go | func sendReply(ch *Channel, reply *vppReply) {
select {
case ch.replyChan <- reply:
// reply sent successfully
case <-time.After(ReplyChannelTimeout):
// receiver still not ready
log.WithFields(logger.Fields{
"channel": ch,
"msg_id": reply.msgID,
"seq_num": reply.seqNum,
}).Warn("Unable to send the reply, reciever end not ready.")
}
} | [
"func",
"sendReply",
"(",
"ch",
"*",
"Channel",
",",
"reply",
"*",
"vppReply",
")",
"{",
"select",
"{",
"case",
"ch",
".",
"replyChan",
"<-",
"reply",
":",
"// reply sent successfully",
"case",
"<-",
"time",
".",
"After",
"(",
"ReplyChannelTimeout",
")",
":",
"// receiver still not ready",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"ch",
",",
"\"",
"\"",
":",
"reply",
".",
"msgID",
",",
"\"",
"\"",
":",
"reply",
".",
"seqNum",
",",
"}",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // sendReply sends the reply into the go channel, if it cannot be completed without blocking, otherwise
// it logs the error and do not send the message. | [
"sendReply",
"sends",
"the",
"reply",
"into",
"the",
"go",
"channel",
"if",
"it",
"cannot",
"be",
"completed",
"without",
"blocking",
"otherwise",
"it",
"logs",
"the",
"error",
"and",
"do",
"not",
"send",
"the",
"message",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/request_handler.go#L210-L222 |
12,596 | FDio/govpp | core/request_handler.go | isNotificationMessage | func (c *Connection) isNotificationMessage(msgID uint16) bool {
c.subscriptionsLock.RLock()
defer c.subscriptionsLock.RUnlock()
_, exists := c.subscriptions[msgID]
return exists
} | go | func (c *Connection) isNotificationMessage(msgID uint16) bool {
c.subscriptionsLock.RLock()
defer c.subscriptionsLock.RUnlock()
_, exists := c.subscriptions[msgID]
return exists
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"isNotificationMessage",
"(",
"msgID",
"uint16",
")",
"bool",
"{",
"c",
".",
"subscriptionsLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"subscriptionsLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"_",
",",
"exists",
":=",
"c",
".",
"subscriptions",
"[",
"msgID",
"]",
"\n",
"return",
"exists",
"\n",
"}"
] | // isNotificationMessage returns true if someone has subscribed to provided message ID. | [
"isNotificationMessage",
"returns",
"true",
"if",
"someone",
"has",
"subscribed",
"to",
"provided",
"message",
"ID",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/request_handler.go#L229-L235 |
12,597 | FDio/govpp | core/request_handler.go | sendNotifications | func (c *Connection) sendNotifications(msgID uint16, data []byte) {
c.subscriptionsLock.RLock()
defer c.subscriptionsLock.RUnlock()
matched := false
// send to notification to each subscriber
for _, sub := range c.subscriptions[msgID] {
log.WithFields(logger.Fields{
"msg_name": sub.event.GetMessageName(),
"msg_id": msgID,
"msg_size": len(data),
}).Debug("Sending a notification to the subscription channel.")
event := sub.msgFactory()
if err := c.codec.DecodeMsg(data, event); err != nil {
log.WithFields(logger.Fields{
"msg_name": sub.event.GetMessageName(),
"msg_id": msgID,
"msg_size": len(data),
}).Errorf("Unable to decode the notification message: %v", err)
continue
}
// send the message into the go channel of the subscription
select {
case sub.notifChan <- event:
// message sent successfully
default:
// unable to write into the channel without blocking
log.WithFields(logger.Fields{
"msg_name": sub.event.GetMessageName(),
"msg_id": msgID,
"msg_size": len(data),
}).Warn("Unable to deliver the notification, reciever end not ready.")
}
matched = true
}
if !matched {
log.WithFields(logger.Fields{
"msg_id": msgID,
"msg_size": len(data),
}).Info("No subscription found for the notification message.")
}
} | go | func (c *Connection) sendNotifications(msgID uint16, data []byte) {
c.subscriptionsLock.RLock()
defer c.subscriptionsLock.RUnlock()
matched := false
// send to notification to each subscriber
for _, sub := range c.subscriptions[msgID] {
log.WithFields(logger.Fields{
"msg_name": sub.event.GetMessageName(),
"msg_id": msgID,
"msg_size": len(data),
}).Debug("Sending a notification to the subscription channel.")
event := sub.msgFactory()
if err := c.codec.DecodeMsg(data, event); err != nil {
log.WithFields(logger.Fields{
"msg_name": sub.event.GetMessageName(),
"msg_id": msgID,
"msg_size": len(data),
}).Errorf("Unable to decode the notification message: %v", err)
continue
}
// send the message into the go channel of the subscription
select {
case sub.notifChan <- event:
// message sent successfully
default:
// unable to write into the channel without blocking
log.WithFields(logger.Fields{
"msg_name": sub.event.GetMessageName(),
"msg_id": msgID,
"msg_size": len(data),
}).Warn("Unable to deliver the notification, reciever end not ready.")
}
matched = true
}
if !matched {
log.WithFields(logger.Fields{
"msg_id": msgID,
"msg_size": len(data),
}).Info("No subscription found for the notification message.")
}
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"sendNotifications",
"(",
"msgID",
"uint16",
",",
"data",
"[",
"]",
"byte",
")",
"{",
"c",
".",
"subscriptionsLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"subscriptionsLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"matched",
":=",
"false",
"\n\n",
"// send to notification to each subscriber",
"for",
"_",
",",
"sub",
":=",
"range",
"c",
".",
"subscriptions",
"[",
"msgID",
"]",
"{",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"sub",
".",
"event",
".",
"GetMessageName",
"(",
")",
",",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"len",
"(",
"data",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"event",
":=",
"sub",
".",
"msgFactory",
"(",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"codec",
".",
"DecodeMsg",
"(",
"data",
",",
"event",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"sub",
".",
"event",
".",
"GetMessageName",
"(",
")",
",",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"len",
"(",
"data",
")",
",",
"}",
")",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// send the message into the go channel of the subscription",
"select",
"{",
"case",
"sub",
".",
"notifChan",
"<-",
"event",
":",
"// message sent successfully",
"default",
":",
"// unable to write into the channel without blocking",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"sub",
".",
"event",
".",
"GetMessageName",
"(",
")",
",",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"len",
"(",
"data",
")",
",",
"}",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"matched",
"=",
"true",
"\n",
"}",
"\n\n",
"if",
"!",
"matched",
"{",
"log",
".",
"WithFields",
"(",
"logger",
".",
"Fields",
"{",
"\"",
"\"",
":",
"msgID",
",",
"\"",
"\"",
":",
"len",
"(",
"data",
")",
",",
"}",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // sendNotifications send a notification message to all subscribers subscribed for that message. | [
"sendNotifications",
"send",
"a",
"notification",
"message",
"to",
"all",
"subscribers",
"subscribed",
"for",
"that",
"message",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/core/request_handler.go#L238-L284 |
12,598 | FDio/govpp | extras/libmemif/packethandle.go | NewPacketHandle | func (memif *Memif) NewPacketHandle(queueId uint8, rxCount uint16) *MemifPacketHandle {
if rxCount == 0 {
rxCount = 1
}
return &MemifPacketHandle{
memif: memif,
queueId: queueId,
rxCount: rxCount,
}
} | go | func (memif *Memif) NewPacketHandle(queueId uint8, rxCount uint16) *MemifPacketHandle {
if rxCount == 0 {
rxCount = 1
}
return &MemifPacketHandle{
memif: memif,
queueId: queueId,
rxCount: rxCount,
}
} | [
"func",
"(",
"memif",
"*",
"Memif",
")",
"NewPacketHandle",
"(",
"queueId",
"uint8",
",",
"rxCount",
"uint16",
")",
"*",
"MemifPacketHandle",
"{",
"if",
"rxCount",
"==",
"0",
"{",
"rxCount",
"=",
"1",
"\n",
"}",
"\n\n",
"return",
"&",
"MemifPacketHandle",
"{",
"memif",
":",
"memif",
",",
"queueId",
":",
"queueId",
",",
"rxCount",
":",
"rxCount",
",",
"}",
"\n",
"}"
] | // Create new GoPacket packet handle from libmemif queue. rxCount determines how many packets will be read
// at once, minimum value is 1 | [
"Create",
"new",
"GoPacket",
"packet",
"handle",
"from",
"libmemif",
"queue",
".",
"rxCount",
"determines",
"how",
"many",
"packets",
"will",
"be",
"read",
"at",
"once",
"minimum",
"value",
"is",
"1"
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/packethandle.go#L46-L56 |
12,599 | FDio/govpp | extras/libmemif/packethandle.go | ReadPacketData | func (handle *MemifPacketHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo, err error) {
handle.readMu.Lock()
defer handle.readMu.Unlock()
if handle.stop {
err = io.EOF
return
}
queueLen := len(handle.packetQueue)
if queueLen == 0 {
packets, burstErr := handle.memif.RxBurst(handle.queueId, handle.rxCount)
packetsLen := len(packets)
if burstErr != nil {
err = burstErr
return
}
if packetsLen == 0 {
err = io.EOF
return
}
handle.packetQueue = make([]*memoizedPacket, packetsLen)
for i, packet := range packets {
packetLen := len(packet)
handle.packetQueue[i] = &memoizedPacket{
data: []byte(packet),
ci: gopacket.CaptureInfo{
Timestamp: time.Now(),
CaptureLength: packetLen,
Length: packetLen,
},
}
}
}
packet := handle.packetQueue[0]
handle.packetQueue = handle.packetQueue[1:]
data = packet.data
ci = packet.ci
return
} | go | func (handle *MemifPacketHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo, err error) {
handle.readMu.Lock()
defer handle.readMu.Unlock()
if handle.stop {
err = io.EOF
return
}
queueLen := len(handle.packetQueue)
if queueLen == 0 {
packets, burstErr := handle.memif.RxBurst(handle.queueId, handle.rxCount)
packetsLen := len(packets)
if burstErr != nil {
err = burstErr
return
}
if packetsLen == 0 {
err = io.EOF
return
}
handle.packetQueue = make([]*memoizedPacket, packetsLen)
for i, packet := range packets {
packetLen := len(packet)
handle.packetQueue[i] = &memoizedPacket{
data: []byte(packet),
ci: gopacket.CaptureInfo{
Timestamp: time.Now(),
CaptureLength: packetLen,
Length: packetLen,
},
}
}
}
packet := handle.packetQueue[0]
handle.packetQueue = handle.packetQueue[1:]
data = packet.data
ci = packet.ci
return
} | [
"func",
"(",
"handle",
"*",
"MemifPacketHandle",
")",
"ReadPacketData",
"(",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"ci",
"gopacket",
".",
"CaptureInfo",
",",
"err",
"error",
")",
"{",
"handle",
".",
"readMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"handle",
".",
"readMu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"handle",
".",
"stop",
"{",
"err",
"=",
"io",
".",
"EOF",
"\n",
"return",
"\n",
"}",
"\n\n",
"queueLen",
":=",
"len",
"(",
"handle",
".",
"packetQueue",
")",
"\n\n",
"if",
"queueLen",
"==",
"0",
"{",
"packets",
",",
"burstErr",
":=",
"handle",
".",
"memif",
".",
"RxBurst",
"(",
"handle",
".",
"queueId",
",",
"handle",
".",
"rxCount",
")",
"\n",
"packetsLen",
":=",
"len",
"(",
"packets",
")",
"\n\n",
"if",
"burstErr",
"!=",
"nil",
"{",
"err",
"=",
"burstErr",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"packetsLen",
"==",
"0",
"{",
"err",
"=",
"io",
".",
"EOF",
"\n",
"return",
"\n",
"}",
"\n\n",
"handle",
".",
"packetQueue",
"=",
"make",
"(",
"[",
"]",
"*",
"memoizedPacket",
",",
"packetsLen",
")",
"\n\n",
"for",
"i",
",",
"packet",
":=",
"range",
"packets",
"{",
"packetLen",
":=",
"len",
"(",
"packet",
")",
"\n\n",
"handle",
".",
"packetQueue",
"[",
"i",
"]",
"=",
"&",
"memoizedPacket",
"{",
"data",
":",
"[",
"]",
"byte",
"(",
"packet",
")",
",",
"ci",
":",
"gopacket",
".",
"CaptureInfo",
"{",
"Timestamp",
":",
"time",
".",
"Now",
"(",
")",
",",
"CaptureLength",
":",
"packetLen",
",",
"Length",
":",
"packetLen",
",",
"}",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"packet",
":=",
"handle",
".",
"packetQueue",
"[",
"0",
"]",
"\n",
"handle",
".",
"packetQueue",
"=",
"handle",
".",
"packetQueue",
"[",
"1",
":",
"]",
"\n",
"data",
"=",
"packet",
".",
"data",
"\n",
"ci",
"=",
"packet",
".",
"ci",
"\n\n",
"return",
"\n",
"}"
] | // Reads packet data from memif in bursts, based on previously configured rxCount parameterer. Then caches the
// resulting packets and returns them 1 by 1 from this method until queue is empty then tries to call new rx burst
// to read more data. If no data is returned, io.EOF error is thrown and caller should stop reading. | [
"Reads",
"packet",
"data",
"from",
"memif",
"in",
"bursts",
"based",
"on",
"previously",
"configured",
"rxCount",
"parameterer",
".",
"Then",
"caches",
"the",
"resulting",
"packets",
"and",
"returns",
"them",
"1",
"by",
"1",
"from",
"this",
"method",
"until",
"queue",
"is",
"empty",
"then",
"tries",
"to",
"call",
"new",
"rx",
"burst",
"to",
"read",
"more",
"data",
".",
"If",
"no",
"data",
"is",
"returned",
"io",
".",
"EOF",
"error",
"is",
"thrown",
"and",
"caller",
"should",
"stop",
"reading",
"."
] | f614a0af720702c8db959b6641b4faea5f98c339 | https://github.com/FDio/govpp/blob/f614a0af720702c8db959b6641b4faea5f98c339/extras/libmemif/packethandle.go#L61-L108 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.