id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
139,600 | scottdware/go-bigip | net.go | ModifyRouteDomain | func (b *BigIP) ModifyRouteDomain(name string, config *RouteDomain) error {
return b.put(config, uriNet, uriRouteDomain, name)
} | go | func (b *BigIP) ModifyRouteDomain(name string, config *RouteDomain) error {
return b.put(config, uriNet, uriRouteDomain, name)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"ModifyRouteDomain",
"(",
"name",
"string",
",",
"config",
"*",
"RouteDomain",
")",
"error",
"{",
"return",
"b",
".",
"put",
"(",
"config",
",",
"uriNet",
",",
"uriRouteDomain",
",",
"name",
")",
"\n",
"}"
] | // ModifyRouteDomain allows you to change any attribute of a route domain. Fields that
// can be modified are referenced in the RouteDomain struct. | [
"ModifyRouteDomain",
"allows",
"you",
"to",
"change",
"any",
"attribute",
"of",
"a",
"route",
"domain",
".",
"Fields",
"that",
"can",
"be",
"modified",
"are",
"referenced",
"in",
"the",
"RouteDomain",
"struct",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L440-L442 |
139,601 | scottdware/go-bigip | net.go | BGPInstances | func (b *BigIP) BGPInstances() (*BGPInstances, error) {
var bgpInstances BGPInstances
err, _ := b.getForEntity(&bgpInstances, uriNet, uriRouting, uriBGP)
if err != nil {
return nil, err
}
return &bgpInstances, nil
} | go | func (b *BigIP) BGPInstances() (*BGPInstances, error) {
var bgpInstances BGPInstances
err, _ := b.getForEntity(&bgpInstances, uriNet, uriRouting, uriBGP)
if err != nil {
return nil, err
}
return &bgpInstances, nil
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"BGPInstances",
"(",
")",
"(",
"*",
"BGPInstances",
",",
"error",
")",
"{",
"var",
"bgpInstances",
"BGPInstances",
"\n",
"err",
",",
"_",
":=",
"b",
".",
"getForEntity",
"(",
"&",
"bgpInstances",
",",
"uriNet",
",",... | // BGPInstances returns a list of BGP instances. | [
"BGPInstances",
"returns",
"a",
"list",
"of",
"BGP",
"instances",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L445-L453 |
139,602 | scottdware/go-bigip | net.go | CreateBGPInstance | func (b *BigIP) CreateBGPInstance(name string, localAS int) error {
config := &BGPInstance{
Name: name,
LocalAS: localAS,
}
return b.post(config, uriNet, uriRouting, uriBGP)
} | go | func (b *BigIP) CreateBGPInstance(name string, localAS int) error {
config := &BGPInstance{
Name: name,
LocalAS: localAS,
}
return b.post(config, uriNet, uriRouting, uriBGP)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"CreateBGPInstance",
"(",
"name",
"string",
",",
"localAS",
"int",
")",
"error",
"{",
"config",
":=",
"&",
"BGPInstance",
"{",
"Name",
":",
"name",
",",
"LocalAS",
":",
"localAS",
",",
"}",
"\n\n",
"return",
"b",
... | // CreateBGPInstance adds a new BGP instance to the BIG-IP system. | [
"CreateBGPInstance",
"adds",
"a",
"new",
"BGP",
"instance",
"to",
"the",
"BIG",
"-",
"IP",
"system",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L456-L463 |
139,603 | scottdware/go-bigip | net.go | AddBGPInstance | func (b *BigIP) AddBGPInstance(config *BGPInstance) error {
return b.post(config, uriNet, uriRouting, uriBGP)
} | go | func (b *BigIP) AddBGPInstance(config *BGPInstance) error {
return b.post(config, uriNet, uriRouting, uriBGP)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"AddBGPInstance",
"(",
"config",
"*",
"BGPInstance",
")",
"error",
"{",
"return",
"b",
".",
"post",
"(",
"config",
",",
"uriNet",
",",
"uriRouting",
",",
"uriBGP",
")",
"\n",
"}"
] | // AddBGPInstance adds a new BGP instance to the BIG-IP system. | [
"AddBGPInstance",
"adds",
"a",
"new",
"BGP",
"instance",
"to",
"the",
"BIG",
"-",
"IP",
"system",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L466-L468 |
139,604 | scottdware/go-bigip | net.go | GetBGPInstance | func (b *BigIP) GetBGPInstance(name string) (*BGPInstance, error) {
var bgpInstance BGPInstance
err, ok := b.getForEntity(&bgpInstance, uriNet, uriRouting, uriBGP, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &bgpInstance, nil
} | go | func (b *BigIP) GetBGPInstance(name string) (*BGPInstance, error) {
var bgpInstance BGPInstance
err, ok := b.getForEntity(&bgpInstance, uriNet, uriRouting, uriBGP, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &bgpInstance, nil
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"GetBGPInstance",
"(",
"name",
"string",
")",
"(",
"*",
"BGPInstance",
",",
"error",
")",
"{",
"var",
"bgpInstance",
"BGPInstance",
"\n",
"err",
",",
"ok",
":=",
"b",
".",
"getForEntity",
"(",
"&",
"bgpInstance",
",... | // GetBGPInstance gets a BGP instance. | [
"GetBGPInstance",
"gets",
"a",
"BGP",
"instance",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L471-L482 |
139,605 | scottdware/go-bigip | net.go | DeleteBGPInstance | func (b *BigIP) DeleteBGPInstance(name string) error {
return b.delete(uriNet, uriRouting, uriBGP, name)
} | go | func (b *BigIP) DeleteBGPInstance(name string) error {
return b.delete(uriNet, uriRouting, uriBGP, name)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"DeleteBGPInstance",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"b",
".",
"delete",
"(",
"uriNet",
",",
"uriRouting",
",",
"uriBGP",
",",
"name",
")",
"\n",
"}"
] | // DeleteBGPInstance removes a BGP instance. | [
"DeleteBGPInstance",
"removes",
"a",
"BGP",
"instance",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L485-L487 |
139,606 | scottdware/go-bigip | net.go | ModifyBGPInstance | func (b *BigIP) ModifyBGPInstance(name string, config *BGPInstance) error {
return b.put(config, uriNet, uriRouting, uriBGP, name)
} | go | func (b *BigIP) ModifyBGPInstance(name string, config *BGPInstance) error {
return b.put(config, uriNet, uriRouting, uriBGP, name)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"ModifyBGPInstance",
"(",
"name",
"string",
",",
"config",
"*",
"BGPInstance",
")",
"error",
"{",
"return",
"b",
".",
"put",
"(",
"config",
",",
"uriNet",
",",
"uriRouting",
",",
"uriBGP",
",",
"name",
")",
"\n",
... | // ModifyBGPInstance allows you to change any attribute of a BGP instance. Fields that
// can be modified are referenced in the BGPInstance struct. | [
"ModifyBGPInstance",
"allows",
"you",
"to",
"change",
"any",
"attribute",
"of",
"a",
"BGP",
"instance",
".",
"Fields",
"that",
"can",
"be",
"modified",
"are",
"referenced",
"in",
"the",
"BGPInstance",
"struct",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L491-L493 |
139,607 | scottdware/go-bigip | net.go | BGPNeighbors | func (b *BigIP) BGPNeighbors(instance string) (*BGPNeighbors, error) {
var bgpNeighbors BGPNeighbors
err, _ := b.getForEntity(&bgpNeighbors, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
if err != nil {
return nil, err
}
return &bgpNeighbors, nil
} | go | func (b *BigIP) BGPNeighbors(instance string) (*BGPNeighbors, error) {
var bgpNeighbors BGPNeighbors
err, _ := b.getForEntity(&bgpNeighbors, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
if err != nil {
return nil, err
}
return &bgpNeighbors, nil
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"BGPNeighbors",
"(",
"instance",
"string",
")",
"(",
"*",
"BGPNeighbors",
",",
"error",
")",
"{",
"var",
"bgpNeighbors",
"BGPNeighbors",
"\n",
"err",
",",
"_",
":=",
"b",
".",
"getForEntity",
"(",
"&",
"bgpNeighbors",... | // BGPNeighbors returns a list of BGP neighbors of a BGP instance. | [
"BGPNeighbors",
"returns",
"a",
"list",
"of",
"BGP",
"neighbors",
"of",
"a",
"BGP",
"instance",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L496-L504 |
139,608 | scottdware/go-bigip | net.go | CreateBGPNeighbor | func (b *BigIP) CreateBGPNeighbor(instance, name string, remoteAS int) error {
config := &BGPNeighbor{
Name: name,
RemoteAS: remoteAS,
}
return b.post(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
} | go | func (b *BigIP) CreateBGPNeighbor(instance, name string, remoteAS int) error {
config := &BGPNeighbor{
Name: name,
RemoteAS: remoteAS,
}
return b.post(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"CreateBGPNeighbor",
"(",
"instance",
",",
"name",
"string",
",",
"remoteAS",
"int",
")",
"error",
"{",
"config",
":=",
"&",
"BGPNeighbor",
"{",
"Name",
":",
"name",
",",
"RemoteAS",
":",
"remoteAS",
",",
"}",
"\n\n... | // CreateBGPNeighbor adds a new BGP neigbhor to a BGP instance in the BIG-IP system. | [
"CreateBGPNeighbor",
"adds",
"a",
"new",
"BGP",
"neigbhor",
"to",
"a",
"BGP",
"instance",
"in",
"the",
"BIG",
"-",
"IP",
"system",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L507-L514 |
139,609 | scottdware/go-bigip | net.go | AddBGPNeighbor | func (b *BigIP) AddBGPNeighbor(instance string, config *BGPNeighbor) error {
return b.post(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
} | go | func (b *BigIP) AddBGPNeighbor(instance string, config *BGPNeighbor) error {
return b.post(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"AddBGPNeighbor",
"(",
"instance",
"string",
",",
"config",
"*",
"BGPNeighbor",
")",
"error",
"{",
"return",
"b",
".",
"post",
"(",
"config",
",",
"uriNet",
",",
"uriRouting",
",",
"uriBGP",
",",
"instance",
",",
"u... | // AddBGPNeighbor adds a new BGP neighbor to a BGP instance in the BIG-IP system. | [
"AddBGPNeighbor",
"adds",
"a",
"new",
"BGP",
"neighbor",
"to",
"a",
"BGP",
"instance",
"in",
"the",
"BIG",
"-",
"IP",
"system",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L517-L519 |
139,610 | scottdware/go-bigip | net.go | GetBGPNeighbor | func (b *BigIP) GetBGPNeighbor(instance, name string) (*BGPNeighbor, error) {
var bgpNeighbor BGPNeighbor
err, ok := b.getForEntity(&bgpNeighbor, uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &bgpNeighbor, nil
} | go | func (b *BigIP) GetBGPNeighbor(instance, name string) (*BGPNeighbor, error) {
var bgpNeighbor BGPNeighbor
err, ok := b.getForEntity(&bgpNeighbor, uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &bgpNeighbor, nil
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"GetBGPNeighbor",
"(",
"instance",
",",
"name",
"string",
")",
"(",
"*",
"BGPNeighbor",
",",
"error",
")",
"{",
"var",
"bgpNeighbor",
"BGPNeighbor",
"\n",
"err",
",",
"ok",
":=",
"b",
".",
"getForEntity",
"(",
"&",
... | // GetBGPNeighbor gets a BGP neighbor of a BGP instance. | [
"GetBGPNeighbor",
"gets",
"a",
"BGP",
"neighbor",
"of",
"a",
"BGP",
"instance",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L522-L533 |
139,611 | scottdware/go-bigip | net.go | DeleteBGPNeighbor | func (b *BigIP) DeleteBGPNeighbor(instance, name string) error {
return b.delete(uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
} | go | func (b *BigIP) DeleteBGPNeighbor(instance, name string) error {
return b.delete(uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"DeleteBGPNeighbor",
"(",
"instance",
",",
"name",
"string",
")",
"error",
"{",
"return",
"b",
".",
"delete",
"(",
"uriNet",
",",
"uriRouting",
",",
"uriBGP",
",",
"instance",
",",
"uriNeighbor",
",",
"name",
")",
"... | // DeleteBGPNeighbor removes a BGP neighbor from a BGP instance. | [
"DeleteBGPNeighbor",
"removes",
"a",
"BGP",
"neighbor",
"from",
"a",
"BGP",
"instance",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L536-L538 |
139,612 | scottdware/go-bigip | net.go | ModifyBGPNeighbor | func (b *BigIP) ModifyBGPNeighbor(instance, name string, config *BGPNeighbor) error {
return b.put(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
} | go | func (b *BigIP) ModifyBGPNeighbor(instance, name string, config *BGPNeighbor) error {
return b.put(config, uriNet, uriRouting, uriBGP, instance, uriNeighbor, name)
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"ModifyBGPNeighbor",
"(",
"instance",
",",
"name",
"string",
",",
"config",
"*",
"BGPNeighbor",
")",
"error",
"{",
"return",
"b",
".",
"put",
"(",
"config",
",",
"uriNet",
",",
"uriRouting",
",",
"uriBGP",
",",
"ins... | // ModifyBGPNeighbor allows you to change any attribute of a BGP neighbor of a BGP instance.
// Fields that can be modified are referenced in the BGPNeighbor struct. | [
"ModifyBGPNeighbor",
"allows",
"you",
"to",
"change",
"any",
"attribute",
"of",
"a",
"BGP",
"neighbor",
"of",
"a",
"BGP",
"instance",
".",
"Fields",
"that",
"can",
"be",
"modified",
"are",
"referenced",
"in",
"the",
"BGPNeighbor",
"struct",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/net.go#L542-L544 |
139,613 | scottdware/go-bigip | cm.go | Devices | func (b *BigIP) Devices() (*Devices, error) {
var devices Devices
err, _ := b.getForEntity(&devices, uriCm, uriDevice)
if err != nil {
return nil, err
}
return &devices, nil
} | go | func (b *BigIP) Devices() (*Devices, error) {
var devices Devices
err, _ := b.getForEntity(&devices, uriCm, uriDevice)
if err != nil {
return nil, err
}
return &devices, nil
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"Devices",
"(",
")",
"(",
"*",
"Devices",
",",
"error",
")",
"{",
"var",
"devices",
"Devices",
"\n",
"err",
",",
"_",
":=",
"b",
".",
"getForEntity",
"(",
"&",
"devices",
",",
"uriCm",
",",
"uriDevice",
")",
"... | // Devices returns a list of devices. | [
"Devices",
"returns",
"a",
"list",
"of",
"devices",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/cm.go#L41-L50 |
139,614 | scottdware/go-bigip | cm.go | GetCurrentDevice | func (b *BigIP) GetCurrentDevice() (*Device, error) {
devices, err := b.Devices()
if err != nil {
return nil, err
}
for _, d := range devices.Devices {
// f5 api is returning bool value as string
if d.SelfDevice == "true" {
return &d, nil
}
}
return nil, errors.New("could not find this device")
} | go | func (b *BigIP) GetCurrentDevice() (*Device, error) {
devices, err := b.Devices()
if err != nil {
return nil, err
}
for _, d := range devices.Devices {
// f5 api is returning bool value as string
if d.SelfDevice == "true" {
return &d, nil
}
}
return nil, errors.New("could not find this device")
} | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"GetCurrentDevice",
"(",
")",
"(",
"*",
"Device",
",",
"error",
")",
"{",
"devices",
",",
"err",
":=",
"b",
".",
"Devices",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"... | // GetCurrentDevice returns a current device. | [
"GetCurrentDevice",
"returns",
"a",
"current",
"device",
"."
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/cm.go#L53-L65 |
139,615 | scottdware/go-bigip | cm.go | UploadSoftwareImage | func (b *BigIP) UploadSoftwareImage(f *os.File) (*Upload, error) {
if !strings.HasSuffix(f.Name(), ".iso") {
err := fmt.Errorf("File must have .iso extension")
return nil, err
}
info, err := f.Stat()
if err != nil {
return nil, err
}
return b.Upload(f, info.Size(), uriCm, uriAutodeploy, uriSoftwareImageUplo... | go | func (b *BigIP) UploadSoftwareImage(f *os.File) (*Upload, error) {
if !strings.HasSuffix(f.Name(), ".iso") {
err := fmt.Errorf("File must have .iso extension")
return nil, err
}
info, err := f.Stat()
if err != nil {
return nil, err
}
return b.Upload(f, info.Size(), uriCm, uriAutodeploy, uriSoftwareImageUplo... | [
"func",
"(",
"b",
"*",
"BigIP",
")",
"UploadSoftwareImage",
"(",
"f",
"*",
"os",
".",
"File",
")",
"(",
"*",
"Upload",
",",
"error",
")",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"f",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"{",
... | // Upload a software image | [
"Upload",
"a",
"software",
"image"
] | 089ab35c13547ce4bcde55918adacdba00708753 | https://github.com/scottdware/go-bigip/blob/089ab35c13547ce4bcde55918adacdba00708753/cm.go#L78-L88 |
139,616 | sabhiram/go-wol | cmd/wol/usage.go | getAllOptions | func getAllOptions() string {
options := ""
for _, o := range validOptions {
options += fmt.Sprintf(" <yellow>-%s --%-8s</yellow> %s\n", o.short, o.long, o.description)
}
return options
} | go | func getAllOptions() string {
options := ""
for _, o := range validOptions {
options += fmt.Sprintf(" <yellow>-%s --%-8s</yellow> %s\n", o.short, o.long, o.description)
}
return options
} | [
"func",
"getAllOptions",
"(",
")",
"string",
"{",
"options",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"validOptions",
"{",
"options",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"o",
".",
"short",
",",
"o",
".",
... | // Build an option string from the above valid ones. | [
"Build",
"an",
"option",
"string",
"from",
"the",
"above",
"valid",
"ones",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/usage.go#L77-L83 |
139,617 | sabhiram/go-wol | cmd/wol/usage.go | getAppUsageString | func getAppUsageString() string {
return colorize.Colorize(fmt.Sprintf(usageString, getAllCommands(), getAllOptions(), wol.Version))
} | go | func getAppUsageString() string {
return colorize.Colorize(fmt.Sprintf(usageString, getAllCommands(), getAllOptions(), wol.Version))
} | [
"func",
"getAppUsageString",
"(",
")",
"string",
"{",
"return",
"colorize",
".",
"Colorize",
"(",
"fmt",
".",
"Sprintf",
"(",
"usageString",
",",
"getAllCommands",
"(",
")",
",",
"getAllOptions",
"(",
")",
",",
"wol",
".",
"Version",
")",
")",
"\n",
"}"
... | // Returns the Usage string for this application. | [
"Returns",
"the",
"Usage",
"string",
"for",
"this",
"application",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/usage.go#L86-L88 |
139,618 | sabhiram/go-wol | cmd/wol/wol.go | listCmd | func listCmd(args []string, aliases *Aliases) error {
mp, err := aliases.List()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get list of aliases: %v\n", err)
return err
}
if len(mp) == 0 {
fmt.Printf("No aliases found! Add one with \"wol alias <name> <mac>\"\n")
} else {
for alias, mi := range mp {
... | go | func listCmd(args []string, aliases *Aliases) error {
mp, err := aliases.List()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get list of aliases: %v\n", err)
return err
}
if len(mp) == 0 {
fmt.Printf("No aliases found! Add one with \"wol alias <name> <mac>\"\n")
} else {
for alias, mi := range mp {
... | [
"func",
"listCmd",
"(",
"args",
"[",
"]",
"string",
",",
"aliases",
"*",
"Aliases",
")",
"error",
"{",
"mp",
",",
"err",
":=",
"aliases",
".",
"List",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",... | // Run the list command. | [
"Run",
"the",
"list",
"command",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/wol.go#L85-L99 |
139,619 | sabhiram/go-wol | cmd/wol/wol.go | removeCmd | func removeCmd(args []string, aliases *Aliases) error {
if len(args) > 0 {
alias := args[0]
return aliases.Del(alias)
}
return errors.New("remove command requires a <name> of an alias")
} | go | func removeCmd(args []string, aliases *Aliases) error {
if len(args) > 0 {
alias := args[0]
return aliases.Del(alias)
}
return errors.New("remove command requires a <name> of an alias")
} | [
"func",
"removeCmd",
"(",
"args",
"[",
"]",
"string",
",",
"aliases",
"*",
"Aliases",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"alias",
":=",
"args",
"[",
"0",
"]",
"\n",
"return",
"aliases",
".",
"Del",
"(",
"alias",
")",... | // Run the remove command. | [
"Run",
"the",
"remove",
"command",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/wol.go#L102-L108 |
139,620 | sabhiram/go-wol | cmd/wol/wol.go | wakeCmd | func wakeCmd(args []string, aliases *Aliases) error {
if len(args) <= 0 {
return errors.New("No mac address specified to wake command")
}
// bcastInterface can be "eth0", "eth1", etc.. An empty string implies
// that we use the default interface when sending the UDP packet (nil).
bcastInterface := ""
macAddr :... | go | func wakeCmd(args []string, aliases *Aliases) error {
if len(args) <= 0 {
return errors.New("No mac address specified to wake command")
}
// bcastInterface can be "eth0", "eth1", etc.. An empty string implies
// that we use the default interface when sending the UDP packet (nil).
bcastInterface := ""
macAddr :... | [
"func",
"wakeCmd",
"(",
"args",
"[",
"]",
"string",
",",
"aliases",
"*",
"Aliases",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
"<=",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// bcastInterface can be \... | // Run the wake command. | [
"Run",
"the",
"wake",
"command",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/wol.go#L111-L184 |
139,621 | sabhiram/go-wol | cmd/wol/wol.go | main | func main() {
var args []string
// Detect the current user to figure out what their ~ is.
usr, err := user.Current()
fatalOnError(err)
// Load the list of aliases from the file at dbPath.
aliases, err := LoadAliases(path.Join(usr.HomeDir, dbPath))
fatalOnError(err)
defer aliases.Close()
// Parse arguments w... | go | func main() {
var args []string
// Detect the current user to figure out what their ~ is.
usr, err := user.Current()
fatalOnError(err)
// Load the list of aliases from the file at dbPath.
aliases, err := LoadAliases(path.Join(usr.HomeDir, dbPath))
fatalOnError(err)
defer aliases.Close()
// Parse arguments w... | [
"func",
"main",
"(",
")",
"{",
"var",
"args",
"[",
"]",
"string",
"\n\n",
"// Detect the current user to figure out what their ~ is.",
"usr",
",",
"err",
":=",
"user",
".",
"Current",
"(",
")",
"\n",
"fatalOnError",
"(",
"err",
")",
"\n\n",
"// Load the list of ... | // Main entry point for binary. | [
"Main",
"entry",
"point",
"for",
"binary",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/wol.go#L217-L263 |
139,622 | sabhiram/go-wol | cmd/wol/alias.go | DecodeToMacIface | func DecodeToMacIface(buf *bytes.Buffer) (MacIface, error) {
var entry MacIface
decoder := gob.NewDecoder(buf)
err := decoder.Decode(&entry)
return entry, err
} | go | func DecodeToMacIface(buf *bytes.Buffer) (MacIface, error) {
var entry MacIface
decoder := gob.NewDecoder(buf)
err := decoder.Decode(&entry)
return entry, err
} | [
"func",
"DecodeToMacIface",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"(",
"MacIface",
",",
"error",
")",
"{",
"var",
"entry",
"MacIface",
"\n",
"decoder",
":=",
"gob",
".",
"NewDecoder",
"(",
"buf",
")",
"\n",
"err",
":=",
"decoder",
".",
"Decode"... | // DecodeToMacIface takes a byte buffer and converts decodes it using the gob
// package to a MacIface entry. | [
"DecodeToMacIface",
"takes",
"a",
"byte",
"buffer",
"and",
"converts",
"decodes",
"it",
"using",
"the",
"gob",
"package",
"to",
"a",
"MacIface",
"entry",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/alias.go#L33-L38 |
139,623 | sabhiram/go-wol | cmd/wol/alias.go | EncodeFromMacIface | func EncodeFromMacIface(mac, iface string) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)
entry := MacIface{mac, iface}
err := gob.NewEncoder(buf).Encode(entry)
return buf, err
} | go | func EncodeFromMacIface(mac, iface string) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)
entry := MacIface{mac, iface}
err := gob.NewEncoder(buf).Encode(entry)
return buf, err
} | [
"func",
"EncodeFromMacIface",
"(",
"mac",
",",
"iface",
"string",
")",
"(",
"*",
"bytes",
".",
"Buffer",
",",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"entry",
":=",
"MacIface",
"{",
"mac",
",",
"iface",
"}",
... | // EncodeFromMacIface takes a MAC and an Iface and encodes a gob with a MacIface
// entry. | [
"EncodeFromMacIface",
"takes",
"a",
"MAC",
"and",
"an",
"Iface",
"and",
"encodes",
"a",
"gob",
"with",
"a",
"MacIface",
"entry",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/alias.go#L42-L47 |
139,624 | sabhiram/go-wol | cmd/wol/alias.go | LoadAliases | func LoadAliases(dbpath string) (*Aliases, error) {
err := os.MkdirAll(path.Dir(dbpath), os.ModePerm)
if os.IsNotExist(err) {
return nil, err
}
db, err := bolt.Open(dbpath, 0660, nil)
if err != nil {
return nil, err
}
if err := db.Update(func(tx *bolt.Tx) error {
if _, lerr := tx.CreateBucketIfNotExists(... | go | func LoadAliases(dbpath string) (*Aliases, error) {
err := os.MkdirAll(path.Dir(dbpath), os.ModePerm)
if os.IsNotExist(err) {
return nil, err
}
db, err := bolt.Open(dbpath, 0660, nil)
if err != nil {
return nil, err
}
if err := db.Update(func(tx *bolt.Tx) error {
if _, lerr := tx.CreateBucketIfNotExists(... | [
"func",
"LoadAliases",
"(",
"dbpath",
"string",
")",
"(",
"*",
"Aliases",
",",
"error",
")",
"{",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"path",
".",
"Dir",
"(",
"dbpath",
")",
",",
"os",
".",
"ModePerm",
")",
"\n",
"if",
"os",
".",
"IsNotExist",... | // LoadAliases fetches a boltDb entity at a given `dbpath`. The db just contains
// a default bucket called `Aliases` which is where the alias entries are
// stored. | [
"LoadAliases",
"fetches",
"a",
"boltDb",
"entity",
"at",
"a",
"given",
"dbpath",
".",
"The",
"db",
"just",
"contains",
"a",
"default",
"bucket",
"called",
"Aliases",
"which",
"is",
"where",
"the",
"alias",
"entries",
"are",
"stored",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/alias.go#L61-L85 |
139,625 | sabhiram/go-wol | cmd/wol/alias.go | Add | func (a *Aliases) Add(alias, mac, iface string) error {
a.mtx.Lock()
defer a.mtx.Unlock()
// Create a buffer to store the encoded MAC, interface pair.
buf, err := EncodeFromMacIface(mac, iface)
if err != nil {
return err
}
// We don't have to worry about the key existing, as we will update it
// provided it... | go | func (a *Aliases) Add(alias, mac, iface string) error {
a.mtx.Lock()
defer a.mtx.Unlock()
// Create a buffer to store the encoded MAC, interface pair.
buf, err := EncodeFromMacIface(mac, iface)
if err != nil {
return err
}
// We don't have to worry about the key existing, as we will update it
// provided it... | [
"func",
"(",
"a",
"*",
"Aliases",
")",
"Add",
"(",
"alias",
",",
"mac",
",",
"iface",
"string",
")",
"error",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"// Create a buffer to store... | // Add updates an alias entry or adds a new alias entry. If the alias already
// exists it is just overwritten. | [
"Add",
"updates",
"an",
"alias",
"entry",
"or",
"adds",
"a",
"new",
"alias",
"entry",
".",
"If",
"the",
"alias",
"already",
"exists",
"it",
"is",
"just",
"overwritten",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/alias.go#L89-L105 |
139,626 | sabhiram/go-wol | cmd/wol/alias.go | Del | func (a *Aliases) Del(alias string) error {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.db.Update(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(bucketName))
return bucket.Delete([]byte(alias))
})
} | go | func (a *Aliases) Del(alias string) error {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.db.Update(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(bucketName))
return bucket.Delete([]byte(alias))
})
} | [
"func",
"(",
"a",
"*",
"Aliases",
")",
"Del",
"(",
"alias",
"string",
")",
"error",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"a",
".",
"db",
".",
"Update",
"(",
"f... | // Del removes an alias from the store based on the alias string. | [
"Del",
"removes",
"an",
"alias",
"from",
"the",
"store",
"based",
"on",
"the",
"alias",
"string",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/alias.go#L108-L116 |
139,627 | sabhiram/go-wol | cmd/wol/alias.go | Get | func (a *Aliases) Get(alias string) (MacIface, error) {
a.mtx.Lock()
defer a.mtx.Unlock()
var entry MacIface
err := a.db.View(func(tx *bolt.Tx) error {
var err error
bucket := tx.Bucket([]byte(bucketName))
value := bucket.Get([]byte(alias))
if value == nil {
return fmt.Errorf("alias (%s) not found in d... | go | func (a *Aliases) Get(alias string) (MacIface, error) {
a.mtx.Lock()
defer a.mtx.Unlock()
var entry MacIface
err := a.db.View(func(tx *bolt.Tx) error {
var err error
bucket := tx.Bucket([]byte(bucketName))
value := bucket.Get([]byte(alias))
if value == nil {
return fmt.Errorf("alias (%s) not found in d... | [
"func",
"(",
"a",
"*",
"Aliases",
")",
"Get",
"(",
"alias",
"string",
")",
"(",
"MacIface",
",",
"error",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"entry",
"MacIfa... | // Get retrieves a MacIface from the store based on an alias string. | [
"Get",
"retrieves",
"a",
"MacIface",
"from",
"the",
"store",
"based",
"on",
"an",
"alias",
"string",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/alias.go#L119-L137 |
139,628 | sabhiram/go-wol | cmd/wol/alias.go | List | func (a *Aliases) List() (map[string]MacIface, error) {
a.mtx.Lock()
defer a.mtx.Unlock()
aliasMap := make(map[string]MacIface, 1)
err := a.db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(bucketName))
cursor := bucket.Cursor()
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
if en... | go | func (a *Aliases) List() (map[string]MacIface, error) {
a.mtx.Lock()
defer a.mtx.Unlock()
aliasMap := make(map[string]MacIface, 1)
err := a.db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(bucketName))
cursor := bucket.Cursor()
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
if en... | [
"func",
"(",
"a",
"*",
"Aliases",
")",
"List",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"MacIface",
",",
"error",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"aliasMap",
... | // List returns a map containing all alias MacIface pairs. | [
"List",
"returns",
"a",
"map",
"containing",
"all",
"alias",
"MacIface",
"pairs",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/alias.go#L140-L158 |
139,629 | sabhiram/go-wol | cmd/wol/alias.go | Close | func (a *Aliases) Close() error {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.db.Close()
} | go | func (a *Aliases) Close() error {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.db.Close()
} | [
"func",
"(",
"a",
"*",
"Aliases",
")",
"Close",
"(",
")",
"error",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"a",
".",
"db",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close closes the alias store. | [
"Close",
"closes",
"the",
"alias",
"store",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/cmd/wol/alias.go#L161-L166 |
139,630 | sabhiram/go-wol | magic_packet.go | New | func New(mac string) (*MagicPacket, error) {
var packet MagicPacket
var macAddr MACAddress
hwAddr, err := net.ParseMAC(mac)
if err != nil {
return nil, err
}
// We only support 6 byte MAC addresses since it is much harder to use the
// binary.Write(...) interface when the size of the MagicPacket is dynamic.
... | go | func New(mac string) (*MagicPacket, error) {
var packet MagicPacket
var macAddr MACAddress
hwAddr, err := net.ParseMAC(mac)
if err != nil {
return nil, err
}
// We only support 6 byte MAC addresses since it is much harder to use the
// binary.Write(...) interface when the size of the MagicPacket is dynamic.
... | [
"func",
"New",
"(",
"mac",
"string",
")",
"(",
"*",
"MagicPacket",
",",
"error",
")",
"{",
"var",
"packet",
"MagicPacket",
"\n",
"var",
"macAddr",
"MACAddress",
"\n\n",
"hwAddr",
",",
"err",
":=",
"net",
".",
"ParseMAC",
"(",
"mac",
")",
"\n",
"if",
... | // New returns a magic packet based on a mac address string. | [
"New",
"returns",
"a",
"magic",
"packet",
"based",
"on",
"a",
"mac",
"address",
"string",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/magic_packet.go#L33-L64 |
139,631 | sabhiram/go-wol | magic_packet.go | Marshal | func (mp *MagicPacket) Marshal() ([]byte, error) {
var buf bytes.Buffer
if err := binary.Write(&buf, binary.BigEndian, mp); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func (mp *MagicPacket) Marshal() ([]byte, error) {
var buf bytes.Buffer
if err := binary.Write(&buf, binary.BigEndian, mp); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"(",
"mp",
"*",
"MagicPacket",
")",
"Marshal",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"binary",
".",
"Write",
"(",
"&",
"buf",
",",
"binary",
".",
"BigEndian... | // Marshal serializes the magic packet structure into a 102 byte slice. | [
"Marshal",
"serializes",
"the",
"magic",
"packet",
"structure",
"into",
"a",
"102",
"byte",
"slice",
"."
] | 5d8c3d0e40c5501b39f110ee4dec02a8db671913 | https://github.com/sabhiram/go-wol/blob/5d8c3d0e40c5501b39f110ee4dec02a8db671913/magic_packet.go#L67-L74 |
139,632 | xyproto/permissionbolt | permissionbolt.go | New | func New() (*Permissions, error) {
state, err := NewUserStateSimple()
if err != nil {
return nil, err
}
return NewPermissions(state), nil
} | go | func New() (*Permissions, error) {
state, err := NewUserStateSimple()
if err != nil {
return nil, err
}
return NewPermissions(state), nil
} | [
"func",
"New",
"(",
")",
"(",
"*",
"Permissions",
",",
"error",
")",
"{",
"state",
",",
"err",
":=",
"NewUserStateSimple",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NewPermissions",
"(",
... | // New initializes a Permissions struct with all the default settings. | [
"New",
"initializes",
"a",
"Permissions",
"struct",
"with",
"all",
"the",
"default",
"settings",
"."
] | fa6f8f62b01d8724f393ef19cd128850c16fb7dc | https://github.com/xyproto/permissionbolt/blob/fa6f8f62b01d8724f393ef19cd128850c16fb7dc/permissionbolt.go#L26-L32 |
139,633 | xyproto/permissionbolt | examples/http/main.go | ServeHTTP | func (ph *permissionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// Check if the user has the right admin/user rights
if ph.perm.Rejected(w, req) {
// Let the user know, by calling the custom "permission denied" function
ph.perm.DenyFunction()(w, req)
// Reject the request by not calling the n... | go | func (ph *permissionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// Check if the user has the right admin/user rights
if ph.perm.Rejected(w, req) {
// Let the user know, by calling the custom "permission denied" function
ph.perm.DenyFunction()(w, req)
// Reject the request by not calling the n... | [
"func",
"(",
"ph",
"*",
"permissionHandler",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"// Check if the user has the right admin/user rights",
"if",
"ph",
".",
"perm",
".",
"Rejected",
"(",
"w... | // Implement the ServeHTTP method to make a permissionHandler a http.Handler | [
"Implement",
"the",
"ServeHTTP",
"method",
"to",
"make",
"a",
"permissionHandler",
"a",
"http",
".",
"Handler"
] | fa6f8f62b01d8724f393ef19cd128850c16fb7dc | https://github.com/xyproto/permissionbolt/blob/fa6f8f62b01d8724f393ef19cd128850c16fb7dc/examples/http/main.go#L27-L37 |
139,634 | gholt/ring | buildernode.go | Capacity | func (n *BuilderNode) Capacity() int {
return n.builder.ring.NodeToCapacity[n.index]
} | go | func (n *BuilderNode) Capacity() int {
return n.builder.ring.NodeToCapacity[n.index]
} | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"Capacity",
"(",
")",
"int",
"{",
"return",
"n",
".",
"builder",
".",
"ring",
".",
"NodeToCapacity",
"[",
"n",
".",
"index",
"]",
"\n",
"}"
] | // Capacity specifies, relative to other nodes, how many assignments the node
// should have. | [
"Capacity",
"specifies",
"relative",
"to",
"other",
"nodes",
"how",
"many",
"assignments",
"the",
"node",
"should",
"have",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L28-L30 |
139,635 | gholt/ring | buildernode.go | SetCapacity | func (n *BuilderNode) SetCapacity(v int) {
n.builder.ring.NodeToCapacity[n.index] = v
} | go | func (n *BuilderNode) SetCapacity(v int) {
n.builder.ring.NodeToCapacity[n.index] = v
} | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"SetCapacity",
"(",
"v",
"int",
")",
"{",
"n",
".",
"builder",
".",
"ring",
".",
"NodeToCapacity",
"[",
"n",
".",
"index",
"]",
"=",
"v",
"\n",
"}"
] | // SetCapacity specifies, relative to other nodes, how many assignments the
// node should have. | [
"SetCapacity",
"specifies",
"relative",
"to",
"other",
"nodes",
"how",
"many",
"assignments",
"the",
"node",
"should",
"have",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L34-L36 |
139,636 | gholt/ring | buildernode.go | Group | func (n *BuilderNode) Group() *BuilderGroup {
return n.builder.groups[n.builder.ring.NodeToGroup[n.index]]
} | go | func (n *BuilderNode) Group() *BuilderGroup {
return n.builder.groups[n.builder.ring.NodeToGroup[n.index]]
} | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"Group",
"(",
")",
"*",
"BuilderGroup",
"{",
"return",
"n",
".",
"builder",
".",
"groups",
"[",
"n",
".",
"builder",
".",
"ring",
".",
"NodeToGroup",
"[",
"n",
".",
"index",
"]",
"]",
"\n",
"}"
] | // Group returns the parent group of the node; it may return nil if there is no
// parent group. | [
"Group",
"returns",
"the",
"parent",
"group",
"of",
"the",
"node",
";",
"it",
"may",
"return",
"nil",
"if",
"there",
"is",
"no",
"parent",
"group",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L40-L42 |
139,637 | gholt/ring | buildernode.go | SetGroup | func (n *BuilderNode) SetGroup(group *BuilderGroup) {
n.builder.ring.NodeToGroup[n.index] = group.index
} | go | func (n *BuilderNode) SetGroup(group *BuilderGroup) {
n.builder.ring.NodeToGroup[n.index] = group.index
} | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"SetGroup",
"(",
"group",
"*",
"BuilderGroup",
")",
"{",
"n",
".",
"builder",
".",
"ring",
".",
"NodeToGroup",
"[",
"n",
".",
"index",
"]",
"=",
"group",
".",
"index",
"\n",
"}"
] | // SetGroup sets the parent group of the node; it may be set to nil to have no
// parent group. | [
"SetGroup",
"sets",
"the",
"parent",
"group",
"of",
"the",
"node",
";",
"it",
"may",
"be",
"set",
"to",
"nil",
"to",
"have",
"no",
"parent",
"group",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L46-L48 |
139,638 | gholt/ring | buildernode.go | Partitions | func (n *BuilderNode) Partitions() []int {
n.builder.ring.FillReplicaToNodeToPartitions()
var partitions holdme.OrderedIntsNoDups
for _, nodeToPartitions := range n.builder.ring.ReplicaToNodeToPartitions {
for _, partition := range nodeToPartitions[n.index] {
partitions.Add(int(partition))
}
}
return partit... | go | func (n *BuilderNode) Partitions() []int {
n.builder.ring.FillReplicaToNodeToPartitions()
var partitions holdme.OrderedIntsNoDups
for _, nodeToPartitions := range n.builder.ring.ReplicaToNodeToPartitions {
for _, partition := range nodeToPartitions[n.index] {
partitions.Add(int(partition))
}
}
return partit... | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"Partitions",
"(",
")",
"[",
"]",
"int",
"{",
"n",
".",
"builder",
".",
"ring",
".",
"FillReplicaToNodeToPartitions",
"(",
")",
"\n",
"var",
"partitions",
"holdme",
".",
"OrderedIntsNoDups",
"\n",
"for",
"_",
",... | // Partitions returns the list of partitions assigned to this node; the list
// will be in ascending order with no duplicates. | [
"Partitions",
"returns",
"the",
"list",
"of",
"partitions",
"assigned",
"to",
"this",
"node",
";",
"the",
"list",
"will",
"be",
"in",
"ascending",
"order",
"with",
"no",
"duplicates",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L52-L61 |
139,639 | gholt/ring | buildernode.go | ReplicaPartitions | func (n *BuilderNode) ReplicaPartitions(replica int) []int {
n.builder.ring.FillReplicaToNodeToPartitions()
partitions := make([]int, len(n.builder.ring.ReplicaToNodeToPartitions[replica][n.index]))
for i, partition := range n.builder.ring.ReplicaToNodeToPartitions[replica][n.index] {
partitions[i] = int(partition... | go | func (n *BuilderNode) ReplicaPartitions(replica int) []int {
n.builder.ring.FillReplicaToNodeToPartitions()
partitions := make([]int, len(n.builder.ring.ReplicaToNodeToPartitions[replica][n.index]))
for i, partition := range n.builder.ring.ReplicaToNodeToPartitions[replica][n.index] {
partitions[i] = int(partition... | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"ReplicaPartitions",
"(",
"replica",
"int",
")",
"[",
"]",
"int",
"{",
"n",
".",
"builder",
".",
"ring",
".",
"FillReplicaToNodeToPartitions",
"(",
")",
"\n",
"partitions",
":=",
"make",
"(",
"[",
"]",
"int",
... | // ReplicaPartitions returns the list of partitions assigned to this node for
// the given replica; the list will be in ascending order with no duplicates. | [
"ReplicaPartitions",
"returns",
"the",
"list",
"of",
"partitions",
"assigned",
"to",
"this",
"node",
"for",
"the",
"given",
"replica",
";",
"the",
"list",
"will",
"be",
"in",
"ascending",
"order",
"with",
"no",
"duplicates",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L65-L72 |
139,640 | gholt/ring | buildernode.go | Responsible | func (n *BuilderNode) Responsible(key int) int {
partition := key % len(n.builder.ring.ReplicaToPartitionToNode[0])
for replica, partitionToNode := range n.builder.ring.ReplicaToPartitionToNode {
if int(partitionToNode[partition]) == n.index {
return replica
}
}
return -1
} | go | func (n *BuilderNode) Responsible(key int) int {
partition := key % len(n.builder.ring.ReplicaToPartitionToNode[0])
for replica, partitionToNode := range n.builder.ring.ReplicaToPartitionToNode {
if int(partitionToNode[partition]) == n.index {
return replica
}
}
return -1
} | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"Responsible",
"(",
"key",
"int",
")",
"int",
"{",
"partition",
":=",
"key",
"%",
"len",
"(",
"n",
".",
"builder",
".",
"ring",
".",
"ReplicaToPartitionToNode",
"[",
"0",
"]",
")",
"\n",
"for",
"replica",
",... | // Responsible returns the replica number this node is responsible for with
// respect to the key given; will return -1 if this node is not responsible for
// any replica for the key. | [
"Responsible",
"returns",
"the",
"replica",
"number",
"this",
"node",
"is",
"responsible",
"for",
"with",
"respect",
"to",
"the",
"key",
"given",
";",
"will",
"return",
"-",
"1",
"if",
"this",
"node",
"is",
"not",
"responsible",
"for",
"any",
"replica",
"f... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L77-L85 |
139,641 | gholt/ring | buildernode.go | ResponsibleForReplicaPartition | func (n *BuilderNode) ResponsibleForReplicaPartition(replica, partition int) bool {
for _, partitionToNode := range n.builder.ring.ReplicaToPartitionToNode {
if int(partitionToNode[partition]) == n.index {
return true
}
}
return false
} | go | func (n *BuilderNode) ResponsibleForReplicaPartition(replica, partition int) bool {
for _, partitionToNode := range n.builder.ring.ReplicaToPartitionToNode {
if int(partitionToNode[partition]) == n.index {
return true
}
}
return false
} | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"ResponsibleForReplicaPartition",
"(",
"replica",
",",
"partition",
"int",
")",
"bool",
"{",
"for",
"_",
",",
"partitionToNode",
":=",
"range",
"n",
".",
"builder",
".",
"ring",
".",
"ReplicaToPartitionToNode",
"{",
... | // ResponsibleForReplicaPartition returns true if this node is reponsible for
// the specific replica and partition given. | [
"ResponsibleForReplicaPartition",
"returns",
"true",
"if",
"this",
"node",
"is",
"reponsible",
"for",
"the",
"specific",
"replica",
"and",
"partition",
"given",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L89-L96 |
139,642 | gholt/ring | buildernode.go | Assign | func (n *BuilderNode) Assign(replica, partition int) {
n.builder.Assign(replica, partition, n)
} | go | func (n *BuilderNode) Assign(replica, partition int) {
n.builder.Assign(replica, partition, n)
} | [
"func",
"(",
"n",
"*",
"BuilderNode",
")",
"Assign",
"(",
"replica",
",",
"partition",
"int",
")",
"{",
"n",
".",
"builder",
".",
"Assign",
"(",
"replica",
",",
"partition",
",",
"n",
")",
"\n",
"}"
] | // Assign will override the current builder's assignment and set a specific
// replica of a partition to this specific node. This is mostly just useful for
// testing, as future calls to Rebalance may move this assignment. | [
"Assign",
"will",
"override",
"the",
"current",
"builder",
"s",
"assignment",
"and",
"set",
"a",
"specific",
"replica",
"of",
"a",
"partition",
"to",
"this",
"specific",
"node",
".",
"This",
"is",
"mostly",
"just",
"useful",
"for",
"testing",
"as",
"future",... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildernode.go#L101-L103 |
139,643 | gholt/ring | builder.go | NewBuilder | func NewBuilder(replicaCount int) *Builder {
if replicaCount < 1 {
replicaCount = 1
}
if replicaCount > 127 {
replicaCount = 127
}
b := &Builder{ring: lowring.New(replicaCount), randIntn: rand.New(rand.NewSource(0)).Intn}
b.groups = []*BuilderGroup{{builder: b}}
return b
} | go | func NewBuilder(replicaCount int) *Builder {
if replicaCount < 1 {
replicaCount = 1
}
if replicaCount > 127 {
replicaCount = 127
}
b := &Builder{ring: lowring.New(replicaCount), randIntn: rand.New(rand.NewSource(0)).Intn}
b.groups = []*BuilderGroup{{builder: b}}
return b
} | [
"func",
"NewBuilder",
"(",
"replicaCount",
"int",
")",
"*",
"Builder",
"{",
"if",
"replicaCount",
"<",
"1",
"{",
"replicaCount",
"=",
"1",
"\n",
"}",
"\n",
"if",
"replicaCount",
">",
"127",
"{",
"replicaCount",
"=",
"127",
"\n",
"}",
"\n",
"b",
":=",
... | // NewBuilder creates a new builder with the initial replica count given. | [
"NewBuilder",
"creates",
"a",
"new",
"builder",
"with",
"the",
"initial",
"replica",
"count",
"given",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L25-L35 |
139,644 | gholt/ring | builder.go | Ring | func (b *Builder) Ring() *Ring {
ring := &Ring{
nodes: make([]*Node, len(b.nodes)),
groups: make([]*Group, len(b.groups)),
nodeToGroup: make([]int, len(b.nodes)),
groupToGroup: make([]int, len(b.groups)),
replicaToPartitionToNode: make([][]lowring... | go | func (b *Builder) Ring() *Ring {
ring := &Ring{
nodes: make([]*Node, len(b.nodes)),
groups: make([]*Group, len(b.groups)),
nodeToGroup: make([]int, len(b.nodes)),
groupToGroup: make([]int, len(b.groups)),
replicaToPartitionToNode: make([][]lowring... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Ring",
"(",
")",
"*",
"Ring",
"{",
"ring",
":=",
"&",
"Ring",
"{",
"nodes",
":",
"make",
"(",
"[",
"]",
"*",
"Node",
",",
"len",
"(",
"b",
".",
"nodes",
")",
")",
",",
"groups",
":",
"make",
"(",
"[",... | // Ring returns an immutable copy of the assignment information contained in
// the builder. | [
"Ring",
"returns",
"an",
"immutable",
"copy",
"of",
"the",
"assignment",
"information",
"contained",
"in",
"the",
"builder",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L39-L72 |
139,645 | gholt/ring | builder.go | Nodes | func (b *Builder) Nodes() []*BuilderNode {
nodes := make([]*BuilderNode, len(b.nodes))
copy(nodes, b.nodes)
return nodes
} | go | func (b *Builder) Nodes() []*BuilderNode {
nodes := make([]*BuilderNode, len(b.nodes))
copy(nodes, b.nodes)
return nodes
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Nodes",
"(",
")",
"[",
"]",
"*",
"BuilderNode",
"{",
"nodes",
":=",
"make",
"(",
"[",
"]",
"*",
"BuilderNode",
",",
"len",
"(",
"b",
".",
"nodes",
")",
")",
"\n",
"copy",
"(",
"nodes",
",",
"b",
".",
"n... | // Nodes returns a slice of all the nodes in the builder. | [
"Nodes",
"returns",
"a",
"slice",
"of",
"all",
"the",
"nodes",
"in",
"the",
"builder",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L75-L79 |
139,646 | gholt/ring | builder.go | AddNode | func (b *Builder) AddNode(info string, capacity int, group *BuilderGroup) *BuilderNode {
groupIndex := 0
if group != nil {
groupIndex = group.index
}
node := &BuilderNode{builder: b, index: int(b.ring.AddNode(capacity, groupIndex)), info: info}
b.nodes = append(b.nodes, node)
return node
} | go | func (b *Builder) AddNode(info string, capacity int, group *BuilderGroup) *BuilderNode {
groupIndex := 0
if group != nil {
groupIndex = group.index
}
node := &BuilderNode{builder: b, index: int(b.ring.AddNode(capacity, groupIndex)), info: info}
b.nodes = append(b.nodes, node)
return node
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"AddNode",
"(",
"info",
"string",
",",
"capacity",
"int",
",",
"group",
"*",
"BuilderGroup",
")",
"*",
"BuilderNode",
"{",
"groupIndex",
":=",
"0",
"\n",
"if",
"group",
"!=",
"nil",
"{",
"groupIndex",
"=",
"group"... | // AddNode adds another node to the builder. Info is a user-defined string and
// is not used directly by the builder. Capacity specifies, relative to other
// nodes, how many assignments the node should have. The group indicates which
// group the node is in; the builder will do its best to keep similar
// assignments... | [
"AddNode",
"adds",
"another",
"node",
"to",
"the",
"builder",
".",
"Info",
"is",
"a",
"user",
"-",
"defined",
"string",
"and",
"is",
"not",
"used",
"directly",
"by",
"the",
"builder",
".",
"Capacity",
"specifies",
"relative",
"to",
"other",
"nodes",
"how",... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L86-L94 |
139,647 | gholt/ring | builder.go | Groups | func (b *Builder) Groups() []*BuilderGroup {
groups := make([]*BuilderGroup, len(b.groups))
copy(groups, b.groups)
return groups
} | go | func (b *Builder) Groups() []*BuilderGroup {
groups := make([]*BuilderGroup, len(b.groups))
copy(groups, b.groups)
return groups
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Groups",
"(",
")",
"[",
"]",
"*",
"BuilderGroup",
"{",
"groups",
":=",
"make",
"(",
"[",
"]",
"*",
"BuilderGroup",
",",
"len",
"(",
"b",
".",
"groups",
")",
")",
"\n",
"copy",
"(",
"groups",
",",
"b",
"."... | // Groups returns a slice of all the groups in use by the builder. | [
"Groups",
"returns",
"a",
"slice",
"of",
"all",
"the",
"groups",
"in",
"use",
"by",
"the",
"builder",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L97-L101 |
139,648 | gholt/ring | builder.go | AddGroup | func (b *Builder) AddGroup(info string, parent *BuilderGroup) *BuilderGroup {
parentIndex := 0
if parent != nil {
parentIndex = parent.index
}
index := len(b.ring.GroupToGroup)
b.ring.GroupToGroup = append(b.ring.GroupToGroup, parentIndex)
group := &BuilderGroup{builder: b, index: index, info: info}
b.groups =... | go | func (b *Builder) AddGroup(info string, parent *BuilderGroup) *BuilderGroup {
parentIndex := 0
if parent != nil {
parentIndex = parent.index
}
index := len(b.ring.GroupToGroup)
b.ring.GroupToGroup = append(b.ring.GroupToGroup, parentIndex)
group := &BuilderGroup{builder: b, index: index, info: info}
b.groups =... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"AddGroup",
"(",
"info",
"string",
",",
"parent",
"*",
"BuilderGroup",
")",
"*",
"BuilderGroup",
"{",
"parentIndex",
":=",
"0",
"\n",
"if",
"parent",
"!=",
"nil",
"{",
"parentIndex",
"=",
"parent",
".",
"index",
"... | // AddGroup adds another group to the builder. Info is a user-defined string
// and is not used directly by the builder. The parent group offers a way to
// tier groups; the builder will do its best to keep similar assignments in
// dissimilar groups at each tier level. The parent may be nil. Cycles are not
// allowed,... | [
"AddGroup",
"adds",
"another",
"group",
"to",
"the",
"builder",
".",
"Info",
"is",
"a",
"user",
"-",
"defined",
"string",
"and",
"is",
"not",
"used",
"directly",
"by",
"the",
"builder",
".",
"The",
"parent",
"group",
"offers",
"a",
"way",
"to",
"tier",
... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L109-L119 |
139,649 | gholt/ring | builder.go | SetReplicaCount | func (b *Builder) SetReplicaCount(v int) {
if v < 1 {
v = 1
}
if v > 127 {
v = 127
}
b.ring.SetReplicaCount(v)
} | go | func (b *Builder) SetReplicaCount(v int) {
if v < 1 {
v = 1
}
if v > 127 {
v = 127
}
b.ring.SetReplicaCount(v)
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"SetReplicaCount",
"(",
"v",
"int",
")",
"{",
"if",
"v",
"<",
"1",
"{",
"v",
"=",
"1",
"\n",
"}",
"\n",
"if",
"v",
">",
"127",
"{",
"v",
"=",
"127",
"\n",
"}",
"\n",
"b",
".",
"ring",
".",
"SetReplicaC... | // SetReplicaCount changes the replica count of the builder. Lowering the
// replica count will simply discard the higher replicas. Raising the replica
// count will create new higher replicas that will be completely unassigned and
// will require a call to Rebalance to become assigned. | [
"SetReplicaCount",
"changes",
"the",
"replica",
"count",
"of",
"the",
"builder",
".",
"Lowering",
"the",
"replica",
"count",
"will",
"simply",
"discard",
"the",
"higher",
"replicas",
".",
"Raising",
"the",
"replica",
"count",
"will",
"create",
"new",
"higher",
... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L130-L138 |
139,650 | gholt/ring | builder.go | SetMaxPartitionCount | func (b *Builder) SetMaxPartitionCount(v int) {
if v < 1 {
v = 1
}
b.ring.MaxPartitionCount = v
} | go | func (b *Builder) SetMaxPartitionCount(v int) {
if v < 1 {
v = 1
}
b.ring.MaxPartitionCount = v
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"SetMaxPartitionCount",
"(",
"v",
"int",
")",
"{",
"if",
"v",
"<",
"1",
"{",
"v",
"=",
"1",
"\n",
"}",
"\n",
"b",
".",
"ring",
".",
"MaxPartitionCount",
"=",
"v",
"\n",
"}"
] | // SetMaxPartitionCount sets the maximum partition count the builder will
// auto-grow to. | [
"SetMaxPartitionCount",
"sets",
"the",
"maximum",
"partition",
"count",
"the",
"builder",
"will",
"auto",
"-",
"grow",
"to",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L153-L158 |
139,651 | gholt/ring | builder.go | PretendElapsed | func (b *Builder) PretendElapsed(d time.Duration) {
minutesElapsed := int64(d / time.Minute)
replicaCount := len(b.ring.ReplicaToPartitionToNode)
partitionCount := len(b.ring.ReplicaToPartitionToNode[0])
if minutesElapsed >= int64(b.ring.ReassignmentWait) || minutesElapsed >= int64(math.MaxUint16) {
for replica :... | go | func (b *Builder) PretendElapsed(d time.Duration) {
minutesElapsed := int64(d / time.Minute)
replicaCount := len(b.ring.ReplicaToPartitionToNode)
partitionCount := len(b.ring.ReplicaToPartitionToNode[0])
if minutesElapsed >= int64(b.ring.ReassignmentWait) || minutesElapsed >= int64(math.MaxUint16) {
for replica :... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"PretendElapsed",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"minutesElapsed",
":=",
"int64",
"(",
"d",
"/",
"time",
".",
"Minute",
")",
"\n",
"replicaCount",
":=",
"len",
"(",
"b",
".",
"ring",
".",
"ReplicaT... | // PretendElapsed is mostly used for testing and will make the builder pretend
// the time duration has elapsed, usually freeing up time based reassignment
// restrictions. | [
"PretendElapsed",
"is",
"mostly",
"used",
"for",
"testing",
"and",
"will",
"make",
"the",
"builder",
"pretend",
"the",
"time",
"duration",
"has",
"elapsed",
"usually",
"freeing",
"up",
"time",
"based",
"reassignment",
"restrictions",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L180-L203 |
139,652 | gholt/ring | builder.go | ReplicaPartitionNode | func (b *Builder) ReplicaPartitionNode(replica, partition int) *BuilderNode {
return b.nodes[b.ring.ReplicaToPartitionToNode[replica][partition]]
} | go | func (b *Builder) ReplicaPartitionNode(replica, partition int) *BuilderNode {
return b.nodes[b.ring.ReplicaToPartitionToNode[replica][partition]]
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"ReplicaPartitionNode",
"(",
"replica",
",",
"partition",
"int",
")",
"*",
"BuilderNode",
"{",
"return",
"b",
".",
"nodes",
"[",
"b",
".",
"ring",
".",
"ReplicaToPartitionToNode",
"[",
"replica",
"]",
"[",
"partition"... | // ReplicaPartitionNode returns the node responsible for a specific replica of
// a partition. | [
"ReplicaPartitionNode",
"returns",
"the",
"node",
"responsible",
"for",
"a",
"specific",
"replica",
"of",
"a",
"partition",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L219-L221 |
139,653 | gholt/ring | builder.go | IsMoving | func (b *Builder) IsMoving(replica, partition int) bool {
return b.ring.ReplicaToPartitionToWait[replica][partition] > 0
} | go | func (b *Builder) IsMoving(replica, partition int) bool {
return b.ring.ReplicaToPartitionToWait[replica][partition] > 0
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"IsMoving",
"(",
"replica",
",",
"partition",
"int",
")",
"bool",
"{",
"return",
"b",
".",
"ring",
".",
"ReplicaToPartitionToWait",
"[",
"replica",
"]",
"[",
"partition",
"]",
">",
"0",
"\n",
"}"
] | // IsMoving returns true if the specific replica of the partition is currently
// in "reassignment wait", where a recent rebalance had reassigned the replica
// to a different node and so is giving time for the data to be moved. | [
"IsMoving",
"returns",
"true",
"if",
"the",
"specific",
"replica",
"of",
"the",
"partition",
"is",
"currently",
"in",
"reassignment",
"wait",
"where",
"a",
"recent",
"rebalance",
"had",
"reassigned",
"the",
"replica",
"to",
"a",
"different",
"node",
"and",
"so... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L226-L228 |
139,654 | gholt/ring | builder.go | MovingAssignmentCount | func (b *Builder) MovingAssignmentCount() int {
replicaCount := len(b.ring.ReplicaToPartitionToNode)
partitionCount := len(b.ring.ReplicaToPartitionToNode[0])
moving := 0
for replica := 0; replica < replicaCount; replica++ {
partitionToWait := b.ring.ReplicaToPartitionToWait[replica]
for partition := 0; partiti... | go | func (b *Builder) MovingAssignmentCount() int {
replicaCount := len(b.ring.ReplicaToPartitionToNode)
partitionCount := len(b.ring.ReplicaToPartitionToNode[0])
moving := 0
for replica := 0; replica < replicaCount; replica++ {
partitionToWait := b.ring.ReplicaToPartitionToWait[replica]
for partition := 0; partiti... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"MovingAssignmentCount",
"(",
")",
"int",
"{",
"replicaCount",
":=",
"len",
"(",
"b",
".",
"ring",
".",
"ReplicaToPartitionToNode",
")",
"\n",
"partitionCount",
":=",
"len",
"(",
"b",
".",
"ring",
".",
"ReplicaToParti... | // MovingAssignmentCount returns the number of assignments that are currently
// "in motion". If you were to call IsMoving for every replica of every
// partition and count the true responses, that would equal the
// MovingAssignmentCount. | [
"MovingAssignmentCount",
"returns",
"the",
"number",
"of",
"assignments",
"that",
"are",
"currently",
"in",
"motion",
".",
"If",
"you",
"were",
"to",
"call",
"IsMoving",
"for",
"every",
"replica",
"of",
"every",
"partition",
"and",
"count",
"the",
"true",
"res... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L234-L247 |
139,655 | gholt/ring | builder.go | ReassignmentWait | func (b *Builder) ReassignmentWait() time.Duration {
return time.Duration(b.ring.ReassignmentWait) * time.Minute
} | go | func (b *Builder) ReassignmentWait() time.Duration {
return time.Duration(b.ring.ReassignmentWait) * time.Minute
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"ReassignmentWait",
"(",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Duration",
"(",
"b",
".",
"ring",
".",
"ReassignmentWait",
")",
"*",
"time",
".",
"Minute",
"\n",
"}"
] | // ReassignmentWait is the time duration the builder will wait after making an
// assignment before considering reassigning that same data. | [
"ReassignmentWait",
"is",
"the",
"time",
"duration",
"the",
"builder",
"will",
"wait",
"after",
"making",
"an",
"assignment",
"before",
"considering",
"reassigning",
"that",
"same",
"data",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L251-L253 |
139,656 | gholt/ring | builder.go | SetReassignmentWait | func (b *Builder) SetReassignmentWait(v time.Duration) {
i := int(v / time.Minute)
if i < 1 {
i = 1
}
if i > math.MaxUint16 {
i = math.MaxUint16
}
b.ring.ReassignmentWait = uint16(i)
} | go | func (b *Builder) SetReassignmentWait(v time.Duration) {
i := int(v / time.Minute)
if i < 1 {
i = 1
}
if i > math.MaxUint16 {
i = math.MaxUint16
}
b.ring.ReassignmentWait = uint16(i)
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"SetReassignmentWait",
"(",
"v",
"time",
".",
"Duration",
")",
"{",
"i",
":=",
"int",
"(",
"v",
"/",
"time",
".",
"Minute",
")",
"\n",
"if",
"i",
"<",
"1",
"{",
"i",
"=",
"1",
"\n",
"}",
"\n",
"if",
"i",... | // SetReassignmentWait sets the time duration the builder will wait after
// making an assignment before considering reassigning that same data. | [
"SetReassignmentWait",
"sets",
"the",
"time",
"duration",
"the",
"builder",
"will",
"wait",
"after",
"making",
"an",
"assignment",
"before",
"considering",
"reassigning",
"that",
"same",
"data",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L257-L266 |
139,657 | gholt/ring | builder.go | SetMaxReplicaReassignableCount | func (b *Builder) SetMaxReplicaReassignableCount(v int) {
if v < 1 {
v = 1
}
if v > 127 {
v = 127
}
b.ring.MaxReplicaReassignableCount = int8(v)
} | go | func (b *Builder) SetMaxReplicaReassignableCount(v int) {
if v < 1 {
v = 1
}
if v > 127 {
v = 127
}
b.ring.MaxReplicaReassignableCount = int8(v)
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"SetMaxReplicaReassignableCount",
"(",
"v",
"int",
")",
"{",
"if",
"v",
"<",
"1",
"{",
"v",
"=",
"1",
"\n",
"}",
"\n",
"if",
"v",
">",
"127",
"{",
"v",
"=",
"127",
"\n",
"}",
"\n",
"b",
".",
"ring",
".",... | // SetMaxReplicaReassignableCount sets the maximum number of replicas of a
// partition the builder will set "in motion" during the reassignment wait
// period.
//
// For a full replica use case, you probably want to set this to no more than
// one less of the majority of replicas so that a majority are always in place... | [
"SetMaxReplicaReassignableCount",
"sets",
"the",
"maximum",
"number",
"of",
"replicas",
"of",
"a",
"partition",
"the",
"builder",
"will",
"set",
"in",
"motion",
"during",
"the",
"reassignment",
"wait",
"period",
".",
"For",
"a",
"full",
"replica",
"use",
"case",... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L286-L294 |
139,658 | gholt/ring | builder.go | Assign | func (b *Builder) Assign(replica, partition int, node *BuilderNode) {
b.ring.ReplicaToPartitionToNode[replica][partition] = lowring.Node(node.index)
b.ring.ReplicaToPartitionToWait[replica][partition] = 0
} | go | func (b *Builder) Assign(replica, partition int, node *BuilderNode) {
b.ring.ReplicaToPartitionToNode[replica][partition] = lowring.Node(node.index)
b.ring.ReplicaToPartitionToWait[replica][partition] = 0
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Assign",
"(",
"replica",
",",
"partition",
"int",
",",
"node",
"*",
"BuilderNode",
")",
"{",
"b",
".",
"ring",
".",
"ReplicaToPartitionToNode",
"[",
"replica",
"]",
"[",
"partition",
"]",
"=",
"lowring",
".",
"No... | // Assign will override the current builder's assignment and set a specific
// replica of a partition to a specific node. This is mostly just useful for
// testing, as future calls to Rebalance may move this assignment. | [
"Assign",
"will",
"override",
"the",
"current",
"builder",
"s",
"assignment",
"and",
"set",
"a",
"specific",
"replica",
"of",
"a",
"partition",
"to",
"a",
"specific",
"node",
".",
"This",
"is",
"mostly",
"just",
"useful",
"for",
"testing",
"as",
"future",
... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L299-L302 |
139,659 | gholt/ring | builder.go | Marshal | func (b *Builder) Marshal(w io.Writer) error {
var nodeType lowring.Node
j := &builderJSON{
MarshalVersion: 0,
NodeType: int(unsafe.Sizeof(nodeType)) * 8,
ReplicaCount: len(b.ring.ReplicaToPartitionToNode),
PartitionCount: len(b.ring.ReplicaToPartiti... | go | func (b *Builder) Marshal(w io.Writer) error {
var nodeType lowring.Node
j := &builderJSON{
MarshalVersion: 0,
NodeType: int(unsafe.Sizeof(nodeType)) * 8,
ReplicaCount: len(b.ring.ReplicaToPartitionToNode),
PartitionCount: len(b.ring.ReplicaToPartiti... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Marshal",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"var",
"nodeType",
"lowring",
".",
"Node",
"\n",
"j",
":=",
"&",
"builderJSON",
"{",
"MarshalVersion",
":",
"0",
",",
"NodeType",
":",
"int",
"(",
"... | // Marshal will write a JSON+binary encoded version of its contents to the
// io.Writer. You can use UnmarshalBuilder to read it back later. | [
"Marshal",
"will",
"write",
"a",
"JSON",
"+",
"binary",
"encoded",
"version",
"of",
"its",
"contents",
"to",
"the",
"io",
".",
"Writer",
".",
"You",
"can",
"use",
"UnmarshalBuilder",
"to",
"read",
"it",
"back",
"later",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/builder.go#L330-L377 |
139,660 | gholt/ring | buildergroup.go | Parent | func (g *BuilderGroup) Parent() *BuilderGroup {
parent := g.builder.ring.GroupToGroup[g.index]
if parent == 0 {
return nil
}
return g.builder.groups[parent]
} | go | func (g *BuilderGroup) Parent() *BuilderGroup {
parent := g.builder.ring.GroupToGroup[g.index]
if parent == 0 {
return nil
}
return g.builder.groups[parent]
} | [
"func",
"(",
"g",
"*",
"BuilderGroup",
")",
"Parent",
"(",
")",
"*",
"BuilderGroup",
"{",
"parent",
":=",
"g",
".",
"builder",
".",
"ring",
".",
"GroupToGroup",
"[",
"g",
".",
"index",
"]",
"\n",
"if",
"parent",
"==",
"0",
"{",
"return",
"nil",
"\n... | // Parent returns the parent group, or nil if there is no parent, of the group. | [
"Parent",
"returns",
"the",
"parent",
"group",
"or",
"nil",
"if",
"there",
"is",
"no",
"parent",
"of",
"the",
"group",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildergroup.go#L24-L30 |
139,661 | gholt/ring | buildergroup.go | SetParent | func (g *BuilderGroup) SetParent(v *BuilderGroup) {
g.builder.ring.GroupToGroup[g.index] = v.index
} | go | func (g *BuilderGroup) SetParent(v *BuilderGroup) {
g.builder.ring.GroupToGroup[g.index] = v.index
} | [
"func",
"(",
"g",
"*",
"BuilderGroup",
")",
"SetParent",
"(",
"v",
"*",
"BuilderGroup",
")",
"{",
"g",
".",
"builder",
".",
"ring",
".",
"GroupToGroup",
"[",
"g",
".",
"index",
"]",
"=",
"v",
".",
"index",
"\n",
"}"
] | // SetParent sets the parent group of this group; it may be nil to indicate
// this group is a top-level group. | [
"SetParent",
"sets",
"the",
"parent",
"group",
"of",
"this",
"group",
";",
"it",
"may",
"be",
"nil",
"to",
"indicate",
"this",
"group",
"is",
"a",
"top",
"-",
"level",
"group",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildergroup.go#L34-L36 |
139,662 | gholt/ring | buildergroup.go | Nodes | func (g *BuilderGroup) Nodes() []*BuilderNode {
nodes := []*BuilderNode{}
for node, group := range g.builder.ring.NodeToGroup {
if group == g.index {
nodes = append(nodes, g.builder.nodes[node])
}
}
return nodes
} | go | func (g *BuilderGroup) Nodes() []*BuilderNode {
nodes := []*BuilderNode{}
for node, group := range g.builder.ring.NodeToGroup {
if group == g.index {
nodes = append(nodes, g.builder.nodes[node])
}
}
return nodes
} | [
"func",
"(",
"g",
"*",
"BuilderGroup",
")",
"Nodes",
"(",
")",
"[",
"]",
"*",
"BuilderNode",
"{",
"nodes",
":=",
"[",
"]",
"*",
"BuilderNode",
"{",
"}",
"\n",
"for",
"node",
",",
"group",
":=",
"range",
"g",
".",
"builder",
".",
"ring",
".",
"Nod... | // Nodes returns the slice of nodes within this group and all its child groups. | [
"Nodes",
"returns",
"the",
"slice",
"of",
"nodes",
"within",
"this",
"group",
"and",
"all",
"its",
"child",
"groups",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildergroup.go#L39-L47 |
139,663 | gholt/ring | buildergroup.go | AddNode | func (g *BuilderGroup) AddNode(info string, capacity int) *BuilderNode {
return g.builder.AddNode(info, capacity, g)
} | go | func (g *BuilderGroup) AddNode(info string, capacity int) *BuilderNode {
return g.builder.AddNode(info, capacity, g)
} | [
"func",
"(",
"g",
"*",
"BuilderGroup",
")",
"AddNode",
"(",
"info",
"string",
",",
"capacity",
"int",
")",
"*",
"BuilderNode",
"{",
"return",
"g",
".",
"builder",
".",
"AddNode",
"(",
"info",
",",
"capacity",
",",
"g",
")",
"\n",
"}"
] | // AddNode will create a new node in the associated builder with this group set
// as the node's parent. Info is a user-defined string and is not used directly
// by the builder. Capacity specifies, relative to other nodes, how many
// assignments the node should have. | [
"AddNode",
"will",
"create",
"a",
"new",
"node",
"in",
"the",
"associated",
"builder",
"with",
"this",
"group",
"set",
"as",
"the",
"node",
"s",
"parent",
".",
"Info",
"is",
"a",
"user",
"-",
"defined",
"string",
"and",
"is",
"not",
"used",
"directly",
... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildergroup.go#L53-L55 |
139,664 | gholt/ring | buildergroup.go | Groups | func (g *BuilderGroup) Groups() []*BuilderGroup {
groups := []*BuilderGroup{}
for child, parent := range g.builder.ring.GroupToGroup {
if parent == g.index {
groups = append(groups, g.builder.groups[child])
}
}
return groups
} | go | func (g *BuilderGroup) Groups() []*BuilderGroup {
groups := []*BuilderGroup{}
for child, parent := range g.builder.ring.GroupToGroup {
if parent == g.index {
groups = append(groups, g.builder.groups[child])
}
}
return groups
} | [
"func",
"(",
"g",
"*",
"BuilderGroup",
")",
"Groups",
"(",
")",
"[",
"]",
"*",
"BuilderGroup",
"{",
"groups",
":=",
"[",
"]",
"*",
"BuilderGroup",
"{",
"}",
"\n",
"for",
"child",
",",
"parent",
":=",
"range",
"g",
".",
"builder",
".",
"ring",
".",
... | // Groups returns the slice of groups that are the direct children of this
// group. | [
"Groups",
"returns",
"the",
"slice",
"of",
"groups",
"that",
"are",
"the",
"direct",
"children",
"of",
"this",
"group",
"."
] | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildergroup.go#L59-L67 |
139,665 | gholt/ring | buildergroup.go | AddGroup | func (g *BuilderGroup) AddGroup(info string) *BuilderGroup {
return g.builder.AddGroup(info, g)
} | go | func (g *BuilderGroup) AddGroup(info string) *BuilderGroup {
return g.builder.AddGroup(info, g)
} | [
"func",
"(",
"g",
"*",
"BuilderGroup",
")",
"AddGroup",
"(",
"info",
"string",
")",
"*",
"BuilderGroup",
"{",
"return",
"g",
".",
"builder",
".",
"AddGroup",
"(",
"info",
",",
"g",
")",
"\n",
"}"
] | // AddGroup adds a new group to the associated builder with this group set as
// the new group's parent. Info is a user-defined string and is not used
// directly by the builder. | [
"AddGroup",
"adds",
"a",
"new",
"group",
"to",
"the",
"associated",
"builder",
"with",
"this",
"group",
"set",
"as",
"the",
"new",
"group",
"s",
"parent",
".",
"Info",
"is",
"a",
"user",
"-",
"defined",
"string",
"and",
"is",
"not",
"used",
"directly",
... | 76a793e37f4c30e4c8c4e58d54db72dfe49c0edc | https://github.com/gholt/ring/blob/76a793e37f4c30e4c8c4e58d54db72dfe49c0edc/buildergroup.go#L72-L74 |
139,666 | bitrise-io/envman | envman/configs.go | saveConfigs | func saveConfigs(configModel ConfigsModel) error {
if err := ensureEnvmanConfigDirExists(); err != nil {
return err
}
bytes, err := json.Marshal(configModel)
if err != nil {
return err
}
configsPth := getEnvmanConfigsFilePath()
return fileutil.WriteBytesToFile(configsPth, bytes)
} | go | func saveConfigs(configModel ConfigsModel) error {
if err := ensureEnvmanConfigDirExists(); err != nil {
return err
}
bytes, err := json.Marshal(configModel)
if err != nil {
return err
}
configsPth := getEnvmanConfigsFilePath()
return fileutil.WriteBytesToFile(configsPth, bytes)
} | [
"func",
"saveConfigs",
"(",
"configModel",
"ConfigsModel",
")",
"error",
"{",
"if",
"err",
":=",
"ensureEnvmanConfigDirExists",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"bytes",
",",
"err",
":=",
"json",
".",
"Marshal",
... | // saveConfigs ...
// only used for unit testing at the moment | [
"saveConfigs",
"...",
"only",
"used",
"for",
"unit",
"testing",
"at",
"the",
"moment"
] | dce389aa0508c35e26577e66970433e9e6750c14 | https://github.com/bitrise-io/envman/blob/dce389aa0508c35e26577e66970433e9e6750c14/envman/configs.go#L88-L99 |
139,667 | bitrise-io/envman | cli/cli.go | Run | func Run() {
cli.HelpFlag = cli.BoolFlag{Name: HelpKey + ", " + helpKeyShort, Usage: "Show help."}
cli.AppHelpTemplate = helpTemplate
cli.VersionFlag = cli.BoolFlag{Name: VersionKey + ", " + versionKeyShort, Usage: "Print the version."}
cli.VersionPrinter = func(c *cli.Context) { fmt.Println(c.App.Version) }
app... | go | func Run() {
cli.HelpFlag = cli.BoolFlag{Name: HelpKey + ", " + helpKeyShort, Usage: "Show help."}
cli.AppHelpTemplate = helpTemplate
cli.VersionFlag = cli.BoolFlag{Name: VersionKey + ", " + versionKeyShort, Usage: "Print the version."}
cli.VersionPrinter = func(c *cli.Context) { fmt.Println(c.App.Version) }
app... | [
"func",
"Run",
"(",
")",
"{",
"cli",
".",
"HelpFlag",
"=",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"HelpKey",
"+",
"\"",
"\"",
"+",
"helpKeyShort",
",",
"Usage",
":",
"\"",
"\"",
"}",
"\n",
"cli",
".",
"AppHelpTemplate",
"=",
"helpTemplate",
"\n\n"... | // Run the Envman CLI. | [
"Run",
"the",
"Envman",
"CLI",
"."
] | dce389aa0508c35e26577e66970433e9e6750c14 | https://github.com/bitrise-io/envman/blob/dce389aa0508c35e26577e66970433e9e6750c14/cli/cli.go#L73-L96 |
139,668 | xyproto/permissionsql | permissionsql.go | NewWithConf | func NewWithConf(connectionString string) (*Permissions, error) {
state, err := NewUserState(connectionString, true)
if err != nil {
return nil, err
}
return NewPermissions(state), nil
} | go | func NewWithConf(connectionString string) (*Permissions, error) {
state, err := NewUserState(connectionString, true)
if err != nil {
return nil, err
}
return NewPermissions(state), nil
} | [
"func",
"NewWithConf",
"(",
"connectionString",
"string",
")",
"(",
"*",
"Permissions",
",",
"error",
")",
"{",
"state",
",",
"err",
":=",
"NewUserState",
"(",
"connectionString",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",... | // Initialize a Permissions struct with a database connection string | [
"Initialize",
"a",
"Permissions",
"struct",
"with",
"a",
"database",
"connection",
"string"
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/permissionsql.go#L36-L42 |
139,669 | xyproto/permissionsql | permissionsql.go | NewWithDSN | func NewWithDSN(connectionString string, database_name string) (*Permissions, error) {
state, err := NewUserStateWithDSN(connectionString, database_name, true)
if err != nil {
return nil, err
}
return NewPermissions(state), nil
} | go | func NewWithDSN(connectionString string, database_name string) (*Permissions, error) {
state, err := NewUserStateWithDSN(connectionString, database_name, true)
if err != nil {
return nil, err
}
return NewPermissions(state), nil
} | [
"func",
"NewWithDSN",
"(",
"connectionString",
"string",
",",
"database_name",
"string",
")",
"(",
"*",
"Permissions",
",",
"error",
")",
"{",
"state",
",",
"err",
":=",
"NewUserStateWithDSN",
"(",
"connectionString",
",",
"database_name",
",",
"true",
")",
"\... | // Initialize a Permissions struct with a dsn | [
"Initialize",
"a",
"Permissions",
"struct",
"with",
"a",
"dsn"
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/permissionsql.go#L45-L51 |
139,670 | xyproto/permissionsql | permissionsql.go | Rejected | func (perm *Permissions) Rejected(w http.ResponseWriter, req *http.Request) bool {
reject := false
path := req.URL.Path // the path of the url that the user wish to visit
// If it's not "/" and set to be public regardless of permissions
if !(perm.rootIsPublic && path == "/") {
// Reject if it is an admin page a... | go | func (perm *Permissions) Rejected(w http.ResponseWriter, req *http.Request) bool {
reject := false
path := req.URL.Path // the path of the url that the user wish to visit
// If it's not "/" and set to be public regardless of permissions
if !(perm.rootIsPublic && path == "/") {
// Reject if it is an admin page a... | [
"func",
"(",
"perm",
"*",
"Permissions",
")",
"Rejected",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"reject",
":=",
"false",
"\n",
"path",
":=",
"req",
".",
"URL",
".",
"Path",
"// the path of t... | // Check if a given request should be rejected. | [
"Check",
"if",
"a",
"given",
"request",
"should",
"be",
"rejected",
"."
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/permissionsql.go#L123-L169 |
139,671 | xyproto/permissionsql | userstate.go | UsernameCookie | func (state *UserState) UsernameCookie(req *http.Request) (string, error) {
username, ok := cookie.SecureCookie(req, "user", state.cookieSecret)
if ok && (username != "") {
return username, nil
}
return "", ErrCookieGetUsername
} | go | func (state *UserState) UsernameCookie(req *http.Request) (string, error) {
username, ok := cookie.SecureCookie(req, "user", state.cookieSecret)
if ok && (username != "") {
return username, nil
}
return "", ErrCookieGetUsername
} | [
"func",
"(",
"state",
"*",
"UserState",
")",
"UsernameCookie",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"string",
",",
"error",
")",
"{",
"username",
",",
"ok",
":=",
"cookie",
".",
"SecureCookie",
"(",
"req",
",",
"\"",
"\"",
",",
"state",... | // Retrieve the username that is stored in a cookie in the browser, if available. | [
"Retrieve",
"the",
"username",
"that",
"is",
"stored",
"in",
"a",
"cookie",
"in",
"the",
"browser",
"if",
"available",
"."
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/userstate.go#L254-L261 |
139,672 | xyproto/permissionsql | userstate.go | SetUsernameCookie | func (state *UserState) SetUsernameCookie(w http.ResponseWriter, username string) error {
if username == "" {
return ErrCookieEmptyUsername
}
if !state.HasUser(username) {
return ErrCookieUserMissing
}
// Create a cookie that lasts for a while ("timeout" seconds),
// this is the equivivalent of a session for ... | go | func (state *UserState) SetUsernameCookie(w http.ResponseWriter, username string) error {
if username == "" {
return ErrCookieEmptyUsername
}
if !state.HasUser(username) {
return ErrCookieUserMissing
}
// Create a cookie that lasts for a while ("timeout" seconds),
// this is the equivivalent of a session for ... | [
"func",
"(",
"state",
"*",
"UserState",
")",
"SetUsernameCookie",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"username",
"string",
")",
"error",
"{",
"if",
"username",
"==",
"\"",
"\"",
"{",
"return",
"ErrCookieEmptyUsername",
"\n",
"}",
"\n",
"if",
"!"... | // Store the given username in a cookie in the browser, if possible.
// The user must exist. | [
"Store",
"the",
"given",
"username",
"in",
"a",
"cookie",
"in",
"the",
"browser",
"if",
"possible",
".",
"The",
"user",
"must",
"exist",
"."
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/userstate.go#L265-L276 |
139,673 | xyproto/permissionsql | userstate.go | addUserUnchecked | func (state *UserState) addUserUnchecked(username, passwordHash, email string) {
// Add the user
state.usernames.Add(username)
// Add password and email
state.users.Set(username, "password", passwordHash)
state.users.Set(username, "email", email)
// Addditional fields
additionalfields := []string{"loggedin", "... | go | func (state *UserState) addUserUnchecked(username, passwordHash, email string) {
// Add the user
state.usernames.Add(username)
// Add password and email
state.users.Set(username, "password", passwordHash)
state.users.Set(username, "email", email)
// Addditional fields
additionalfields := []string{"loggedin", "... | [
"func",
"(",
"state",
"*",
"UserState",
")",
"addUserUnchecked",
"(",
"username",
",",
"passwordHash",
",",
"email",
"string",
")",
"{",
"// Add the user",
"state",
".",
"usernames",
".",
"Add",
"(",
"username",
")",
"\n\n",
"// Add password and email",
"state",... | // Creates a user from the username and password hash, does not check for rights. | [
"Creates",
"a",
"user",
"from",
"the",
"username",
"and",
"password",
"hash",
"does",
"not",
"check",
"for",
"rights",
"."
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/userstate.go#L344-L357 |
139,674 | xyproto/permissionsql | userstate.go | stored_hash | func (state *UserState) stored_hash(username string) []byte {
hashString, err := state.PasswordHash(username)
if err != nil {
return []byte{}
}
return []byte(hashString)
} | go | func (state *UserState) stored_hash(username string) []byte {
hashString, err := state.PasswordHash(username)
if err != nil {
return []byte{}
}
return []byte(hashString)
} | [
"func",
"(",
"state",
"*",
"UserState",
")",
"stored_hash",
"(",
"username",
"string",
")",
"[",
"]",
"byte",
"{",
"hashString",
",",
"err",
":=",
"state",
".",
"PasswordHash",
"(",
"username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
... | // Return the stored hash, or an empty byte slice. | [
"Return",
"the",
"stored",
"hash",
"or",
"an",
"empty",
"byte",
"slice",
"."
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/userstate.go#L465-L471 |
139,675 | xyproto/permissionsql | userstate.go | CorrectPassword | func (state *UserState) CorrectPassword(username, password string) bool {
if !state.HasUser(username) {
return false
}
// Retrieve the stored password hash
hash := state.stored_hash(username)
if len(hash) == 0 {
return false
}
// Check the password with the right password algorithm
switch state.passwordA... | go | func (state *UserState) CorrectPassword(username, password string) bool {
if !state.HasUser(username) {
return false
}
// Retrieve the stored password hash
hash := state.stored_hash(username)
if len(hash) == 0 {
return false
}
// Check the password with the right password algorithm
switch state.passwordA... | [
"func",
"(",
"state",
"*",
"UserState",
")",
"CorrectPassword",
"(",
"username",
",",
"password",
"string",
")",
"bool",
"{",
"if",
"!",
"state",
".",
"HasUser",
"(",
"username",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Retrieve the stored passwor... | // Check if a password is correct. username is needed because it is part of the hash. | [
"Check",
"if",
"a",
"password",
"is",
"correct",
".",
"username",
"is",
"needed",
"because",
"it",
"is",
"part",
"of",
"the",
"hash",
"."
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/userstate.go#L474-L499 |
139,676 | xyproto/permissionsql | userstate.go | ConfirmUserByConfirmationCode | func (state *UserState) ConfirmUserByConfirmationCode(confirmationcode string) error {
username, err := state.FindUserByConfirmationCode(confirmationcode)
if err != nil {
return err
}
state.Confirm(username)
return nil
} | go | func (state *UserState) ConfirmUserByConfirmationCode(confirmationcode string) error {
username, err := state.FindUserByConfirmationCode(confirmationcode)
if err != nil {
return err
}
state.Confirm(username)
return nil
} | [
"func",
"(",
"state",
"*",
"UserState",
")",
"ConfirmUserByConfirmationCode",
"(",
"confirmationcode",
"string",
")",
"error",
"{",
"username",
",",
"err",
":=",
"state",
".",
"FindUserByConfirmationCode",
"(",
"confirmationcode",
")",
"\n",
"if",
"err",
"!=",
"... | // Take a confirmation code and mark the corresponding unconfirmed user as confirmed. | [
"Take",
"a",
"confirmation",
"code",
"and",
"mark",
"the",
"corresponding",
"unconfirmed",
"user",
"as",
"confirmed",
"."
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/userstate.go#L565-L572 |
139,677 | xyproto/permissionsql | userstate.go | GenerateUniqueConfirmationCode | func (state *UserState) GenerateUniqueConfirmationCode() (string, error) {
const maxConfirmationCodeLength = 100 // when are the generated confirmation codes unreasonably long
length := minConfirmationCodeLength
confirmationCode := cookie.RandomHumanFriendlyString(length)
for state.AlreadyHasConfirmationCode(confir... | go | func (state *UserState) GenerateUniqueConfirmationCode() (string, error) {
const maxConfirmationCodeLength = 100 // when are the generated confirmation codes unreasonably long
length := minConfirmationCodeLength
confirmationCode := cookie.RandomHumanFriendlyString(length)
for state.AlreadyHasConfirmationCode(confir... | [
"func",
"(",
"state",
"*",
"UserState",
")",
"GenerateUniqueConfirmationCode",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"const",
"maxConfirmationCodeLength",
"=",
"100",
"// when are the generated confirmation codes unreasonably long",
"\n",
"length",
":=",
"min... | // Generate a unique confirmation code that can be used for confirming users. | [
"Generate",
"a",
"unique",
"confirmation",
"code",
"that",
"can",
"be",
"used",
"for",
"confirming",
"users",
"."
] | d55e4b7cdf90a57c965c4ca2a3eb2abba4116533 | https://github.com/xyproto/permissionsql/blob/d55e4b7cdf90a57c965c4ca2a3eb2abba4116533/userstate.go#L580-L594 |
139,678 | albrow/zoom | model.go | ModelID | func (r *RandomID) ModelID() string {
if r.ID == "" {
r.ID = generateRandomID()
}
return r.ID
} | go | func (r *RandomID) ModelID() string {
if r.ID == "" {
r.ID = generateRandomID()
}
return r.ID
} | [
"func",
"(",
"r",
"*",
"RandomID",
")",
"ModelID",
"(",
")",
"string",
"{",
"if",
"r",
".",
"ID",
"==",
"\"",
"\"",
"{",
"r",
".",
"ID",
"=",
"generateRandomID",
"(",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"ID",
"\n",
"}"
] | // ModelID returns the id of the model, satisfying the Model interface.
// If r.ID is an empty string, it will generate a pseudo-random id which
// is highly likely to be unique. | [
"ModelID",
"returns",
"the",
"id",
"of",
"the",
"model",
"satisfying",
"the",
"Model",
"interface",
".",
"If",
"r",
".",
"ID",
"is",
"an",
"empty",
"string",
"it",
"will",
"generate",
"a",
"pseudo",
"-",
"random",
"id",
"which",
"is",
"highly",
"likely",... | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L38-L43 |
139,679 | albrow/zoom | model.go | compileModelSpec | func compileModelSpec(typ reflect.Type) (*modelSpec, error) {
ms := &modelSpec{
name: getDefaultModelSpecName(typ),
fieldsByName: map[string]*fieldSpec{},
typ: typ,
}
// Iterate through fields
elem := typ.Elem()
numFields := elem.NumField()
for i := 0; i < numFields; i++ {
field := elem.... | go | func compileModelSpec(typ reflect.Type) (*modelSpec, error) {
ms := &modelSpec{
name: getDefaultModelSpecName(typ),
fieldsByName: map[string]*fieldSpec{},
typ: typ,
}
// Iterate through fields
elem := typ.Elem()
numFields := elem.NumField()
for i := 0; i < numFields; i++ {
field := elem.... | [
"func",
"compileModelSpec",
"(",
"typ",
"reflect",
".",
"Type",
")",
"(",
"*",
"modelSpec",
",",
"error",
")",
"{",
"ms",
":=",
"&",
"modelSpec",
"{",
"name",
":",
"getDefaultModelSpecName",
"(",
"typ",
")",
",",
"fieldsByName",
":",
"map",
"[",
"string"... | // compilesModelSpec examines typ using reflection, parses its fields,
// and returns a modelSpec. | [
"compilesModelSpec",
"examines",
"typ",
"using",
"reflection",
"parses",
"its",
"fields",
"and",
"returns",
"a",
"modelSpec",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L91-L173 |
139,680 | albrow/zoom | model.go | getDefaultModelSpecName | func getDefaultModelSpecName(typ reflect.Type) string {
// Strip any dereference operators
for typ.Kind() == reflect.Ptr {
typ = typ.Elem()
}
nameWithPackage := typ.String()
// Strip the package name
return strings.Join(strings.Split(nameWithPackage, ".")[1:], "")
} | go | func getDefaultModelSpecName(typ reflect.Type) string {
// Strip any dereference operators
for typ.Kind() == reflect.Ptr {
typ = typ.Elem()
}
nameWithPackage := typ.String()
// Strip the package name
return strings.Join(strings.Split(nameWithPackage, ".")[1:], "")
} | [
"func",
"getDefaultModelSpecName",
"(",
"typ",
"reflect",
".",
"Type",
")",
"string",
"{",
"// Strip any dereference operators",
"for",
"typ",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"typ",
"=",
"typ",
".",
"Elem",
"(",
")",
"\n",
"}",
"... | // getDefaultModelSpecName returns the default name for the given type, which is
// simply the name of the type without the package prefix or dereference
// operators. | [
"getDefaultModelSpecName",
"returns",
"the",
"default",
"name",
"for",
"the",
"given",
"type",
"which",
"is",
"simply",
"the",
"name",
"of",
"the",
"type",
"without",
"the",
"package",
"prefix",
"or",
"dereference",
"operators",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L178-L186 |
139,681 | albrow/zoom | model.go | setIndexKind | func setIndexKind(fs *fieldSpec, fieldType reflect.Type) error {
switch {
case typeIsNumeric(fieldType):
fs.indexKind = numericIndex
case typeIsString(fieldType):
fs.indexKind = stringIndex
case typeIsBool(fieldType):
fs.indexKind = booleanIndex
default:
return fmt.Errorf("zoom: Requested index on unsuppor... | go | func setIndexKind(fs *fieldSpec, fieldType reflect.Type) error {
switch {
case typeIsNumeric(fieldType):
fs.indexKind = numericIndex
case typeIsString(fieldType):
fs.indexKind = stringIndex
case typeIsBool(fieldType):
fs.indexKind = booleanIndex
default:
return fmt.Errorf("zoom: Requested index on unsuppor... | [
"func",
"setIndexKind",
"(",
"fs",
"*",
"fieldSpec",
",",
"fieldType",
"reflect",
".",
"Type",
")",
"error",
"{",
"switch",
"{",
"case",
"typeIsNumeric",
"(",
"fieldType",
")",
":",
"fs",
".",
"indexKind",
"=",
"numericIndex",
"\n",
"case",
"typeIsString",
... | // setIndexKind sets the indexKind field of fs based on fieldType. | [
"setIndexKind",
"sets",
"the",
"indexKind",
"field",
"of",
"fs",
"based",
"on",
"fieldType",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L189-L201 |
139,682 | albrow/zoom | model.go | modelKey | func (ms *modelSpec) modelKey(id string) (string, error) {
if id == "" {
return "", fmt.Errorf("zoom: Error in modelKey: id was empty")
}
return ms.name + ":" + id, nil
} | go | func (ms *modelSpec) modelKey(id string) (string, error) {
if id == "" {
return "", fmt.Errorf("zoom: Error in modelKey: id was empty")
}
return ms.name + ":" + id, nil
} | [
"func",
"(",
"ms",
"*",
"modelSpec",
")",
"modelKey",
"(",
"id",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
... | // modelKey returns the key that identifies a hash in the database
// which contains all the fields of the model corresponding to the given
// id. It returns an error iff id is empty. | [
"modelKey",
"returns",
"the",
"key",
"that",
"identifies",
"a",
"hash",
"in",
"the",
"database",
"which",
"contains",
"all",
"the",
"fields",
"of",
"the",
"model",
"corresponding",
"to",
"the",
"given",
"id",
".",
"It",
"returns",
"an",
"error",
"iff",
"id... | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L212-L217 |
139,683 | albrow/zoom | model.go | fieldNames | func (ms modelSpec) fieldNames() []string {
names := make([]string, len(ms.fields))
count := 0
for _, field := range ms.fields {
names[count] = field.name
count++
}
return names
} | go | func (ms modelSpec) fieldNames() []string {
names := make([]string, len(ms.fields))
count := 0
for _, field := range ms.fields {
names[count] = field.name
count++
}
return names
} | [
"func",
"(",
"ms",
"modelSpec",
")",
"fieldNames",
"(",
")",
"[",
"]",
"string",
"{",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"ms",
".",
"fields",
")",
")",
"\n",
"count",
":=",
"0",
"\n",
"for",
"_",
",",
"field",
":="... | // fieldNames returns all the field names for the given modelSpec | [
"fieldNames",
"returns",
"all",
"the",
"field",
"names",
"for",
"the",
"given",
"modelSpec"
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L220-L228 |
139,684 | albrow/zoom | model.go | fieldIndexKey | func (ms *modelSpec) fieldIndexKey(fieldName string) (string, error) {
fs, found := ms.fieldsByName[fieldName]
if !found {
return "", fmt.Errorf("Type %s has no field named %s", ms.typ.Name(), fieldName)
} else if fs.indexKind == noIndex {
return "", fmt.Errorf("%s.%s is not an indexed field", ms.typ.Name(), fie... | go | func (ms *modelSpec) fieldIndexKey(fieldName string) (string, error) {
fs, found := ms.fieldsByName[fieldName]
if !found {
return "", fmt.Errorf("Type %s has no field named %s", ms.typ.Name(), fieldName)
} else if fs.indexKind == noIndex {
return "", fmt.Errorf("%s.%s is not an indexed field", ms.typ.Name(), fie... | [
"func",
"(",
"ms",
"*",
"modelSpec",
")",
"fieldIndexKey",
"(",
"fieldName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"fs",
",",
"found",
":=",
"ms",
".",
"fieldsByName",
"[",
"fieldName",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"\... | // fieldIndexKey returns the key for the sorted set used to index the field identified
// by fieldName. It returns an error if fieldName does not identify a field in the spec
// or if the field it identifies is not an indexed field. | [
"fieldIndexKey",
"returns",
"the",
"key",
"for",
"the",
"sorted",
"set",
"used",
"to",
"index",
"the",
"field",
"identified",
"by",
"fieldName",
".",
"It",
"returns",
"an",
"error",
"if",
"fieldName",
"does",
"not",
"identify",
"a",
"field",
"in",
"the",
"... | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L257-L265 |
139,685 | albrow/zoom | model.go | sortArgs | func (ms *modelSpec) sortArgs(idsKey string, redisFieldNames []string, limit int, offset uint, reverse bool) redis.Args {
args := redis.Args{idsKey, "BY", "nosort"}
for _, fieldName := range redisFieldNames {
args = append(args, "GET", ms.name+":*->"+fieldName)
}
// We always want to get the id
args = append(arg... | go | func (ms *modelSpec) sortArgs(idsKey string, redisFieldNames []string, limit int, offset uint, reverse bool) redis.Args {
args := redis.Args{idsKey, "BY", "nosort"}
for _, fieldName := range redisFieldNames {
args = append(args, "GET", ms.name+":*->"+fieldName)
}
// We always want to get the id
args = append(arg... | [
"func",
"(",
"ms",
"*",
"modelSpec",
")",
"sortArgs",
"(",
"idsKey",
"string",
",",
"redisFieldNames",
"[",
"]",
"string",
",",
"limit",
"int",
",",
"offset",
"uint",
",",
"reverse",
"bool",
")",
"redis",
".",
"Args",
"{",
"args",
":=",
"redis",
".",
... | // sortArgs returns arguments that can be used to get all the fields in includeFields
// for all the models which have corresponding ids in setKey. Any fields not in
// includeFields will not be included in the arguments and will not be retrieved from
// redis when the command is eventually run. If limit or offset are ... | [
"sortArgs",
"returns",
"arguments",
"that",
"can",
"be",
"used",
"to",
"get",
"all",
"the",
"fields",
"in",
"includeFields",
"for",
"all",
"the",
"models",
"which",
"have",
"corresponding",
"ids",
"in",
"setKey",
".",
"Any",
"fields",
"not",
"in",
"includeFi... | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L275-L291 |
139,686 | albrow/zoom | model.go | checkModelType | func (ms *modelSpec) checkModelType(model Model) error {
if reflect.TypeOf(model) != ms.typ {
return fmt.Errorf("model was the wrong type. Expected %s but got %T", ms.typ.String(), model)
}
return nil
} | go | func (ms *modelSpec) checkModelType(model Model) error {
if reflect.TypeOf(model) != ms.typ {
return fmt.Errorf("model was the wrong type. Expected %s but got %T", ms.typ.String(), model)
}
return nil
} | [
"func",
"(",
"ms",
"*",
"modelSpec",
")",
"checkModelType",
"(",
"model",
"Model",
")",
"error",
"{",
"if",
"reflect",
".",
"TypeOf",
"(",
"model",
")",
"!=",
"ms",
".",
"typ",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ms",
".",
... | // checkModelType returns an error iff model is not of the registered type that
// corresponds to modelSpec. | [
"checkModelType",
"returns",
"an",
"error",
"iff",
"model",
"is",
"not",
"of",
"the",
"registered",
"type",
"that",
"corresponds",
"to",
"modelSpec",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L295-L300 |
139,687 | albrow/zoom | model.go | checkModelsType | func (ms *modelSpec) checkModelsType(models interface{}) error {
if reflect.TypeOf(models).Kind() != reflect.Ptr {
return fmt.Errorf("models should be a pointer to a slice or array of models")
}
modelsVal := reflect.ValueOf(models).Elem()
elemType := modelsVal.Type().Elem()
switch {
case !typeIsSliceOrArray(mod... | go | func (ms *modelSpec) checkModelsType(models interface{}) error {
if reflect.TypeOf(models).Kind() != reflect.Ptr {
return fmt.Errorf("models should be a pointer to a slice or array of models")
}
modelsVal := reflect.ValueOf(models).Elem()
elemType := modelsVal.Type().Elem()
switch {
case !typeIsSliceOrArray(mod... | [
"func",
"(",
"ms",
"*",
"modelSpec",
")",
"checkModelsType",
"(",
"models",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"reflect",
".",
"TypeOf",
"(",
"models",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"return",
"fmt",
".",
... | // checkModelsType returns an error iff models is not a pointer to a slice of models of the
// registered type that corresponds to modelSpec. | [
"checkModelsType",
"returns",
"an",
"error",
"iff",
"models",
"is",
"not",
"a",
"pointer",
"to",
"a",
"slice",
"of",
"models",
"of",
"the",
"registered",
"type",
"that",
"corresponds",
"to",
"modelSpec",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L304-L319 |
139,688 | albrow/zoom | model.go | elemValue | func (mr *modelRef) elemValue() reflect.Value {
if mr.value().IsNil() {
msg := fmt.Sprintf("zoom: panic in elemValue(). Model of type %T was nil", mr.model)
panic(msg)
}
return mr.value().Elem()
} | go | func (mr *modelRef) elemValue() reflect.Value {
if mr.value().IsNil() {
msg := fmt.Sprintf("zoom: panic in elemValue(). Model of type %T was nil", mr.model)
panic(msg)
}
return mr.value().Elem()
} | [
"func",
"(",
"mr",
"*",
"modelRef",
")",
"elemValue",
"(",
")",
"reflect",
".",
"Value",
"{",
"if",
"mr",
".",
"value",
"(",
")",
".",
"IsNil",
"(",
")",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"mr",
".",
"model",
")",
... | // elemValue dereferences the model and returns the
// underlying struct. If the model is a nil pointer,
// it will panic if the model is a nil pointer | [
"elemValue",
"dereferences",
"the",
"model",
"and",
"returns",
"the",
"underlying",
"struct",
".",
"If",
"the",
"model",
"is",
"a",
"nil",
"pointer",
"it",
"will",
"panic",
"if",
"the",
"model",
"is",
"a",
"nil",
"pointer"
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L338-L344 |
139,689 | albrow/zoom | model.go | key | func (mr *modelRef) key() string {
return mr.spec.name + ":" + mr.model.ModelID()
} | go | func (mr *modelRef) key() string {
return mr.spec.name + ":" + mr.model.ModelID()
} | [
"func",
"(",
"mr",
"*",
"modelRef",
")",
"key",
"(",
")",
"string",
"{",
"return",
"mr",
".",
"spec",
".",
"name",
"+",
"\"",
"\"",
"+",
"mr",
".",
"model",
".",
"ModelID",
"(",
")",
"\n",
"}"
] | // key returns a key which is used in redis to store the model | [
"key",
"returns",
"a",
"key",
"which",
"is",
"used",
"in",
"redis",
"to",
"store",
"the",
"model"
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L354-L356 |
139,690 | albrow/zoom | model.go | mainHashArgs | func (mr *modelRef) mainHashArgs() (redis.Args, error) {
return mr.mainHashArgsForFields(mr.spec.fieldNames())
} | go | func (mr *modelRef) mainHashArgs() (redis.Args, error) {
return mr.mainHashArgsForFields(mr.spec.fieldNames())
} | [
"func",
"(",
"mr",
"*",
"modelRef",
")",
"mainHashArgs",
"(",
")",
"(",
"redis",
".",
"Args",
",",
"error",
")",
"{",
"return",
"mr",
".",
"mainHashArgsForFields",
"(",
"mr",
".",
"spec",
".",
"fieldNames",
"(",
")",
")",
"\n",
"}"
] | // mainHashArgs returns the args for the main hash for this model. Typically
// these args should part of an HMSET command. | [
"mainHashArgs",
"returns",
"the",
"args",
"for",
"the",
"main",
"hash",
"for",
"this",
"model",
".",
"Typically",
"these",
"args",
"should",
"part",
"of",
"an",
"HMSET",
"command",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L360-L362 |
139,691 | albrow/zoom | model.go | mainHashArgsForFields | func (mr *modelRef) mainHashArgsForFields(fieldNames []string) (redis.Args, error) {
args := redis.Args{mr.key()}
ms := mr.spec
for _, fs := range ms.fields {
// Skip fields whose names do not appear in fieldNames.
if !stringSliceContains(fieldNames, fs.name) {
continue
}
fieldVal := mr.fieldValue(fs.name... | go | func (mr *modelRef) mainHashArgsForFields(fieldNames []string) (redis.Args, error) {
args := redis.Args{mr.key()}
ms := mr.spec
for _, fs := range ms.fields {
// Skip fields whose names do not appear in fieldNames.
if !stringSliceContains(fieldNames, fs.name) {
continue
}
fieldVal := mr.fieldValue(fs.name... | [
"func",
"(",
"mr",
"*",
"modelRef",
")",
"mainHashArgsForFields",
"(",
"fieldNames",
"[",
"]",
"string",
")",
"(",
"redis",
".",
"Args",
",",
"error",
")",
"{",
"args",
":=",
"redis",
".",
"Args",
"{",
"mr",
".",
"key",
"(",
")",
"}",
"\n",
"ms",
... | // mainHashArgsForFields is like mainHashArgs but only returns the hash
// fields which match the given fieldNames. | [
"mainHashArgsForFields",
"is",
"like",
"mainHashArgs",
"but",
"only",
"returns",
"the",
"hash",
"fields",
"which",
"match",
"the",
"given",
"fieldNames",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/model.go#L366-L410 |
139,692 | albrow/zoom | collection.go | WithFallbackMarshalerUnmarshaler | func (options CollectionOptions) WithFallbackMarshalerUnmarshaler(fallback MarshalerUnmarshaler) CollectionOptions {
options.FallbackMarshalerUnmarshaler = fallback
return options
} | go | func (options CollectionOptions) WithFallbackMarshalerUnmarshaler(fallback MarshalerUnmarshaler) CollectionOptions {
options.FallbackMarshalerUnmarshaler = fallback
return options
} | [
"func",
"(",
"options",
"CollectionOptions",
")",
"WithFallbackMarshalerUnmarshaler",
"(",
"fallback",
"MarshalerUnmarshaler",
")",
"CollectionOptions",
"{",
"options",
".",
"FallbackMarshalerUnmarshaler",
"=",
"fallback",
"\n",
"return",
"options",
"\n",
"}"
] | // WithFallbackMarshalerUnmarshaler returns a new copy of the options with the
// FallbackMarshalerUnmarshaler property set to the given value. It does not
// mutate the original options. | [
"WithFallbackMarshalerUnmarshaler",
"returns",
"a",
"new",
"copy",
"of",
"the",
"options",
"with",
"the",
"FallbackMarshalerUnmarshaler",
"property",
"set",
"to",
"the",
"given",
"value",
".",
"It",
"does",
"not",
"mutate",
"the",
"original",
"options",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/collection.go#L66-L69 |
139,693 | albrow/zoom | collection.go | WithIndex | func (options CollectionOptions) WithIndex(index bool) CollectionOptions {
options.Index = index
return options
} | go | func (options CollectionOptions) WithIndex(index bool) CollectionOptions {
options.Index = index
return options
} | [
"func",
"(",
"options",
"CollectionOptions",
")",
"WithIndex",
"(",
"index",
"bool",
")",
"CollectionOptions",
"{",
"options",
".",
"Index",
"=",
"index",
"\n",
"return",
"options",
"\n",
"}"
] | // WithIndex returns a new copy of the options with the Index property set to
// the given value. It does not mutate the original options. | [
"WithIndex",
"returns",
"a",
"new",
"copy",
"of",
"the",
"options",
"with",
"the",
"Index",
"property",
"set",
"to",
"the",
"given",
"value",
".",
"It",
"does",
"not",
"mutate",
"the",
"original",
"options",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/collection.go#L73-L76 |
139,694 | albrow/zoom | collection.go | WithName | func (options CollectionOptions) WithName(name string) CollectionOptions {
options.Name = name
return options
} | go | func (options CollectionOptions) WithName(name string) CollectionOptions {
options.Name = name
return options
} | [
"func",
"(",
"options",
"CollectionOptions",
")",
"WithName",
"(",
"name",
"string",
")",
"CollectionOptions",
"{",
"options",
".",
"Name",
"=",
"name",
"\n",
"return",
"options",
"\n",
"}"
] | // WithName returns a new copy of the options with the Name property set to the
// given value. It does not mutate the original options. | [
"WithName",
"returns",
"a",
"new",
"copy",
"of",
"the",
"options",
"with",
"the",
"Name",
"property",
"set",
"to",
"the",
"given",
"value",
".",
"It",
"does",
"not",
"mutate",
"the",
"original",
"options",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/collection.go#L80-L83 |
139,695 | albrow/zoom | collection.go | NewCollection | func (p *Pool) NewCollection(model Model) (*Collection, error) {
return p.NewCollectionWithOptions(model, DefaultCollectionOptions)
} | go | func (p *Pool) NewCollection(model Model) (*Collection, error) {
return p.NewCollectionWithOptions(model, DefaultCollectionOptions)
} | [
"func",
"(",
"p",
"*",
"Pool",
")",
"NewCollection",
"(",
"model",
"Model",
")",
"(",
"*",
"Collection",
",",
"error",
")",
"{",
"return",
"p",
".",
"NewCollectionWithOptions",
"(",
"model",
",",
"DefaultCollectionOptions",
")",
"\n",
"}"
] | // NewCollection registers and returns a new collection of the given model type.
// You must create a collection for each model type you want to save. The type
// of model must be unique, i.e., not already registered, and must be a pointer
// to a struct. NewCollection will use all the default options for the
// collec... | [
"NewCollection",
"registers",
"and",
"returns",
"a",
"new",
"collection",
"of",
"the",
"given",
"model",
"type",
".",
"You",
"must",
"create",
"a",
"collection",
"for",
"each",
"model",
"type",
"you",
"want",
"to",
"save",
".",
"The",
"type",
"of",
"model"... | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/collection.go#L91-L93 |
139,696 | albrow/zoom | collection.go | NewCollectionWithOptions | func (p *Pool) NewCollectionWithOptions(model Model, options CollectionOptions) (*Collection, error) {
typ := reflect.TypeOf(model)
// If options.Name is empty use the name of the concrete model type (without
// the package prefix).
if options.Name == "" {
options.Name = getDefaultModelSpecName(typ)
} else if st... | go | func (p *Pool) NewCollectionWithOptions(model Model, options CollectionOptions) (*Collection, error) {
typ := reflect.TypeOf(model)
// If options.Name is empty use the name of the concrete model type (without
// the package prefix).
if options.Name == "" {
options.Name = getDefaultModelSpecName(typ)
} else if st... | [
"func",
"(",
"p",
"*",
"Pool",
")",
"NewCollectionWithOptions",
"(",
"model",
"Model",
",",
"options",
"CollectionOptions",
")",
"(",
"*",
"Collection",
",",
"error",
")",
"{",
"typ",
":=",
"reflect",
".",
"TypeOf",
"(",
"model",
")",
"\n",
"// If options.... | // NewCollectionWithOptions registers and returns a new collection of the given
// model type and with the provided options. | [
"NewCollectionWithOptions",
"registers",
"and",
"returns",
"a",
"new",
"collection",
"of",
"the",
"given",
"model",
"type",
"and",
"with",
"the",
"provided",
"options",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/collection.go#L97-L134 |
139,697 | albrow/zoom | collection.go | addCollection | func addCollection(collection *Collection) {
for e := collections.Front(); e != nil; e = e.Next() {
otherCollection := e.Value.(*Collection)
if collection.spec.typ == otherCollection.spec.typ {
// The Collection was already added to the list. No need to do
// anything.
return
}
}
collections.PushFront... | go | func addCollection(collection *Collection) {
for e := collections.Front(); e != nil; e = e.Next() {
otherCollection := e.Value.(*Collection)
if collection.spec.typ == otherCollection.spec.typ {
// The Collection was already added to the list. No need to do
// anything.
return
}
}
collections.PushFront... | [
"func",
"addCollection",
"(",
"collection",
"*",
"Collection",
")",
"{",
"for",
"e",
":=",
"collections",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"otherCollection",
":=",
"e",
".",
"Value",
"."... | // addCollection adds the given spec to the list of collections iff it has not
// already been added. | [
"addCollection",
"adds",
"the",
"given",
"spec",
"to",
"the",
"list",
"of",
"collections",
"iff",
"it",
"has",
"not",
"already",
"been",
"added",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/collection.go#L145-L155 |
139,698 | albrow/zoom | collection.go | getCollectionForModel | func getCollectionForModel(model Model) (*Collection, error) {
typ := reflect.TypeOf(model)
for e := collections.Front(); e != nil; e = e.Next() {
col := e.Value.(*Collection)
if col.spec.typ == typ {
return col, nil
}
}
return nil, fmt.Errorf("Could not find Collection for type %T", model)
} | go | func getCollectionForModel(model Model) (*Collection, error) {
typ := reflect.TypeOf(model)
for e := collections.Front(); e != nil; e = e.Next() {
col := e.Value.(*Collection)
if col.spec.typ == typ {
return col, nil
}
}
return nil, fmt.Errorf("Could not find Collection for type %T", model)
} | [
"func",
"getCollectionForModel",
"(",
"model",
"Model",
")",
"(",
"*",
"Collection",
",",
"error",
")",
"{",
"typ",
":=",
"reflect",
".",
"TypeOf",
"(",
"model",
")",
"\n",
"for",
"e",
":=",
"collections",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil... | // getCollectionForModel returns the Collection corresponding to the type of
// model. | [
"getCollectionForModel",
"returns",
"the",
"Collection",
"corresponding",
"to",
"the",
"type",
"of",
"model",
"."
] | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/collection.go#L159-L168 |
139,699 | albrow/zoom | collection.go | ModelKey | func (c *Collection) ModelKey(id string) string {
if id == "" {
return ""
}
// c.spec.modelKey(id) will only return an error if id was an empty string.
// Since we already ruled that out with the check above, we can safely ignore
// the error return value here.
key, _ := c.spec.modelKey(id)
return key
} | go | func (c *Collection) ModelKey(id string) string {
if id == "" {
return ""
}
// c.spec.modelKey(id) will only return an error if id was an empty string.
// Since we already ruled that out with the check above, we can safely ignore
// the error return value here.
key, _ := c.spec.modelKey(id)
return key
} | [
"func",
"(",
"c",
"*",
"Collection",
")",
"ModelKey",
"(",
"id",
"string",
")",
"string",
"{",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"// c.spec.modelKey(id) will only return an error if id was an empty string.",
"// Since we alr... | // ModelKey returns the key that identifies a hash in the database
// which contains all the fields of the model corresponding to the given
// id. If id is an empty string, it will return an empty string. | [
"ModelKey",
"returns",
"the",
"key",
"that",
"identifies",
"a",
"hash",
"in",
"the",
"database",
"which",
"contains",
"all",
"the",
"fields",
"of",
"the",
"model",
"corresponding",
"to",
"the",
"given",
"id",
".",
"If",
"id",
"is",
"an",
"empty",
"string",... | 4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952 | https://github.com/albrow/zoom/blob/4cc9cdbf65ce1b2f60b11b765d3e6b3a5e7e8952/collection.go#L183-L192 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.