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
|
---|---|---|---|---|---|---|---|---|---|---|---|
146,400 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/activations.go | NewActivation | func NewActivation(parent *Activations) *Activation {
activation := &Activation{parent: parent}
activation.Init()
return activation
} | go | func NewActivation(parent *Activations) *Activation {
activation := &Activation{parent: parent}
activation.Init()
return activation
} | [
"func",
"NewActivation",
"(",
"parent",
"*",
"Activations",
")",
"*",
"Activation",
"{",
"activation",
":=",
"&",
"Activation",
"{",
"parent",
":",
"parent",
"}",
"\n",
"activation",
".",
"Init",
"(",
")",
"\n\n",
"return",
"activation",
"\n",
"}"
]
| // NewActivation creates a new Activation | [
"NewActivation",
"creates",
"a",
"new",
"Activation"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/activations.go#L138-L143 |
146,401 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/hostnames.go | NewHostname | func (hostnames *Hostnames) NewHostname() *Hostname {
hostname := NewHostname(hostnames)
hostnames.Hostnames.Items = append(hostnames.Hostnames.Items, hostname)
return hostname
} | go | func (hostnames *Hostnames) NewHostname() *Hostname {
hostname := NewHostname(hostnames)
hostnames.Hostnames.Items = append(hostnames.Hostnames.Items, hostname)
return hostname
} | [
"func",
"(",
"hostnames",
"*",
"Hostnames",
")",
"NewHostname",
"(",
")",
"*",
"Hostname",
"{",
"hostname",
":=",
"NewHostname",
"(",
"hostnames",
")",
"\n",
"hostnames",
".",
"Hostnames",
".",
"Items",
"=",
"append",
"(",
"hostnames",
".",
"Hostnames",
".",
"Items",
",",
"hostname",
")",
"\n",
"return",
"hostname",
"\n",
"}"
]
| // NewHostname creates a new Hostname within a given Hostnames | [
"NewHostname",
"creates",
"a",
"new",
"Hostname",
"within",
"a",
"given",
"Hostnames"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/hostnames.go#L104-L108 |
146,402 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/hostnames.go | Save | func (hostnames *Hostnames) Save() error {
req, err := client.NewJSONRequest(
Config,
"PUT",
fmt.Sprintf(
"/papi/v1/properties/%s/versions/%d/hostnames?contractId=%s&groupId=%s",
hostnames.PropertyID,
hostnames.PropertyVersion,
hostnames.ContractID,
hostnames.GroupID,
),
hostnames.Hostnames.Items,
)
if err != nil {
return err
}
res, err := client.Do(Config, req)
if err != nil {
return err
}
if client.IsError(res) {
return client.NewAPIError(res)
}
if err = client.BodyJSON(res, hostnames); err != nil {
return err
}
return nil
} | go | func (hostnames *Hostnames) Save() error {
req, err := client.NewJSONRequest(
Config,
"PUT",
fmt.Sprintf(
"/papi/v1/properties/%s/versions/%d/hostnames?contractId=%s&groupId=%s",
hostnames.PropertyID,
hostnames.PropertyVersion,
hostnames.ContractID,
hostnames.GroupID,
),
hostnames.Hostnames.Items,
)
if err != nil {
return err
}
res, err := client.Do(Config, req)
if err != nil {
return err
}
if client.IsError(res) {
return client.NewAPIError(res)
}
if err = client.BodyJSON(res, hostnames); err != nil {
return err
}
return nil
} | [
"func",
"(",
"hostnames",
"*",
"Hostnames",
")",
"Save",
"(",
")",
"error",
"{",
"req",
",",
"err",
":=",
"client",
".",
"NewJSONRequest",
"(",
"Config",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hostnames",
".",
"PropertyID",
",",
"hostnames",
".",
"PropertyVersion",
",",
"hostnames",
".",
"ContractID",
",",
"hostnames",
".",
"GroupID",
",",
")",
",",
"hostnames",
".",
"Hostnames",
".",
"Items",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"Config",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"client",
".",
"IsError",
"(",
"res",
")",
"{",
"return",
"client",
".",
"NewAPIError",
"(",
"res",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"client",
".",
"BodyJSON",
"(",
"res",
",",
"hostnames",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Save updates a properties hostnames | [
"Save",
"updates",
"a",
"properties",
"hostnames"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/hostnames.go#L111-L142 |
146,403 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/hostnames.go | NewHostname | func NewHostname(parent *Hostnames) *Hostname {
hostname := &Hostname{parent: parent, CnameType: CnameTypeEdgeHostname}
hostname.Init()
return hostname
} | go | func NewHostname(parent *Hostnames) *Hostname {
hostname := &Hostname{parent: parent, CnameType: CnameTypeEdgeHostname}
hostname.Init()
return hostname
} | [
"func",
"NewHostname",
"(",
"parent",
"*",
"Hostnames",
")",
"*",
"Hostname",
"{",
"hostname",
":=",
"&",
"Hostname",
"{",
"parent",
":",
"parent",
",",
"CnameType",
":",
"CnameTypeEdgeHostname",
"}",
"\n",
"hostname",
".",
"Init",
"(",
")",
"\n\n",
"return",
"hostname",
"\n",
"}"
]
| // NewHostname creates a new Hostname | [
"NewHostname",
"creates",
"a",
"new",
"Hostname"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/hostnames.go#L155-L160 |
146,404 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/versions.go | AddVersion | func (versions *Versions) AddVersion(version *Version) {
if version.PropertyVersion != 0 {
for key, v := range versions.Versions.Items {
if v.PropertyVersion == version.PropertyVersion {
versions.Versions.Items[key] = version
return
}
}
}
versions.Versions.Items = append(versions.Versions.Items, version)
} | go | func (versions *Versions) AddVersion(version *Version) {
if version.PropertyVersion != 0 {
for key, v := range versions.Versions.Items {
if v.PropertyVersion == version.PropertyVersion {
versions.Versions.Items[key] = version
return
}
}
}
versions.Versions.Items = append(versions.Versions.Items, version)
} | [
"func",
"(",
"versions",
"*",
"Versions",
")",
"AddVersion",
"(",
"version",
"*",
"Version",
")",
"{",
"if",
"version",
".",
"PropertyVersion",
"!=",
"0",
"{",
"for",
"key",
",",
"v",
":=",
"range",
"versions",
".",
"Versions",
".",
"Items",
"{",
"if",
"v",
".",
"PropertyVersion",
"==",
"version",
".",
"PropertyVersion",
"{",
"versions",
".",
"Versions",
".",
"Items",
"[",
"key",
"]",
"=",
"version",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"versions",
".",
"Versions",
".",
"Items",
"=",
"append",
"(",
"versions",
".",
"Versions",
".",
"Items",
",",
"version",
")",
"\n",
"}"
]
| // AddVersion adds or replaces a version within the collection | [
"AddVersion",
"adds",
"or",
"replaces",
"a",
"version",
"within",
"the",
"collection"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/versions.go#L47-L58 |
146,405 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/versions.go | NewVersion | func (versions *Versions) NewVersion(createFromVersion *Version, useEtagStrict bool) *Version {
if createFromVersion == nil {
var err error
createFromVersion, err = versions.GetLatestVersion("")
if err != nil {
return nil
}
}
version := NewVersion(versions)
version.CreateFromVersion = createFromVersion.PropertyVersion
versions.Versions.Items = append(versions.Versions.Items, version)
if useEtagStrict {
version.CreateFromVersionEtag = createFromVersion.Etag
}
return version
} | go | func (versions *Versions) NewVersion(createFromVersion *Version, useEtagStrict bool) *Version {
if createFromVersion == nil {
var err error
createFromVersion, err = versions.GetLatestVersion("")
if err != nil {
return nil
}
}
version := NewVersion(versions)
version.CreateFromVersion = createFromVersion.PropertyVersion
versions.Versions.Items = append(versions.Versions.Items, version)
if useEtagStrict {
version.CreateFromVersionEtag = createFromVersion.Etag
}
return version
} | [
"func",
"(",
"versions",
"*",
"Versions",
")",
"NewVersion",
"(",
"createFromVersion",
"*",
"Version",
",",
"useEtagStrict",
"bool",
")",
"*",
"Version",
"{",
"if",
"createFromVersion",
"==",
"nil",
"{",
"var",
"err",
"error",
"\n",
"createFromVersion",
",",
"err",
"=",
"versions",
".",
"GetLatestVersion",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"version",
":=",
"NewVersion",
"(",
"versions",
")",
"\n",
"version",
".",
"CreateFromVersion",
"=",
"createFromVersion",
".",
"PropertyVersion",
"\n\n",
"versions",
".",
"Versions",
".",
"Items",
"=",
"append",
"(",
"versions",
".",
"Versions",
".",
"Items",
",",
"version",
")",
"\n\n",
"if",
"useEtagStrict",
"{",
"version",
".",
"CreateFromVersionEtag",
"=",
"createFromVersion",
".",
"Etag",
"\n",
"}",
"\n\n",
"return",
"version",
"\n",
"}"
]
| // NewVersion creates a new version associated with the Versions collection | [
"NewVersion",
"creates",
"a",
"new",
"version",
"associated",
"with",
"the",
"Versions",
"collection"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/versions.go#L137-L156 |
146,406 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/versions.go | NewVersion | func NewVersion(parent *Versions) *Version {
version := &Version{parent: parent}
version.Init()
return version
} | go | func NewVersion(parent *Versions) *Version {
version := &Version{parent: parent}
version.Init()
return version
} | [
"func",
"NewVersion",
"(",
"parent",
"*",
"Versions",
")",
"*",
"Version",
"{",
"version",
":=",
"&",
"Version",
"{",
"parent",
":",
"parent",
"}",
"\n",
"version",
".",
"Init",
"(",
")",
"\n\n",
"return",
"version",
"\n",
"}"
]
| // NewVersion creates a new Version | [
"NewVersion",
"creates",
"a",
"new",
"Version"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/versions.go#L176-L181 |
146,407 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/versions.go | HasBeenActivated | func (version *Version) HasBeenActivated(activatedOn NetworkValue) (bool, error) {
properties := NewProperties()
property := NewProperty(properties)
property.PropertyID = version.parent.PropertyID
property.Group = NewGroup(NewGroups())
property.Group.GroupID = version.parent.GroupID
property.Contract = NewContract(NewContracts())
property.Contract.ContractID = version.parent.ContractID
activations, err := property.GetActivations()
if err != nil {
return false, err
}
for _, activation := range activations.Activations.Items {
if activation.PropertyVersion == version.PropertyVersion && (activatedOn == "" || activation.Network == activatedOn) {
return true, nil
}
}
return false, nil
} | go | func (version *Version) HasBeenActivated(activatedOn NetworkValue) (bool, error) {
properties := NewProperties()
property := NewProperty(properties)
property.PropertyID = version.parent.PropertyID
property.Group = NewGroup(NewGroups())
property.Group.GroupID = version.parent.GroupID
property.Contract = NewContract(NewContracts())
property.Contract.ContractID = version.parent.ContractID
activations, err := property.GetActivations()
if err != nil {
return false, err
}
for _, activation := range activations.Activations.Items {
if activation.PropertyVersion == version.PropertyVersion && (activatedOn == "" || activation.Network == activatedOn) {
return true, nil
}
}
return false, nil
} | [
"func",
"(",
"version",
"*",
"Version",
")",
"HasBeenActivated",
"(",
"activatedOn",
"NetworkValue",
")",
"(",
"bool",
",",
"error",
")",
"{",
"properties",
":=",
"NewProperties",
"(",
")",
"\n",
"property",
":=",
"NewProperty",
"(",
"properties",
")",
"\n",
"property",
".",
"PropertyID",
"=",
"version",
".",
"parent",
".",
"PropertyID",
"\n\n",
"property",
".",
"Group",
"=",
"NewGroup",
"(",
"NewGroups",
"(",
")",
")",
"\n",
"property",
".",
"Group",
".",
"GroupID",
"=",
"version",
".",
"parent",
".",
"GroupID",
"\n\n",
"property",
".",
"Contract",
"=",
"NewContract",
"(",
"NewContracts",
"(",
")",
")",
"\n",
"property",
".",
"Contract",
".",
"ContractID",
"=",
"version",
".",
"parent",
".",
"ContractID",
"\n\n",
"activations",
",",
"err",
":=",
"property",
".",
"GetActivations",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"activation",
":=",
"range",
"activations",
".",
"Activations",
".",
"Items",
"{",
"if",
"activation",
".",
"PropertyVersion",
"==",
"version",
".",
"PropertyVersion",
"&&",
"(",
"activatedOn",
"==",
"\"",
"\"",
"||",
"activation",
".",
"Network",
"==",
"activatedOn",
")",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
",",
"nil",
"\n",
"}"
]
| // HasBeenActivated determines if a given version has been activated, optionally on a specific network | [
"HasBeenActivated",
"determines",
"if",
"a",
"given",
"version",
"has",
"been",
"activated",
"optionally",
"on",
"a",
"specific",
"network"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/versions.go#L235-L258 |
146,408 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/edgehostnames.go | NewEdgeHostname | func (edgeHostnames *EdgeHostnames) NewEdgeHostname() *EdgeHostname {
edgeHostname := NewEdgeHostname(edgeHostnames)
edgeHostnames.EdgeHostnames.Items = append(edgeHostnames.EdgeHostnames.Items, edgeHostname)
return edgeHostname
} | go | func (edgeHostnames *EdgeHostnames) NewEdgeHostname() *EdgeHostname {
edgeHostname := NewEdgeHostname(edgeHostnames)
edgeHostnames.EdgeHostnames.Items = append(edgeHostnames.EdgeHostnames.Items, edgeHostname)
return edgeHostname
} | [
"func",
"(",
"edgeHostnames",
"*",
"EdgeHostnames",
")",
"NewEdgeHostname",
"(",
")",
"*",
"EdgeHostname",
"{",
"edgeHostname",
":=",
"NewEdgeHostname",
"(",
"edgeHostnames",
")",
"\n",
"edgeHostnames",
".",
"EdgeHostnames",
".",
"Items",
"=",
"append",
"(",
"edgeHostnames",
".",
"EdgeHostnames",
".",
"Items",
",",
"edgeHostname",
")",
"\n",
"return",
"edgeHostname",
"\n",
"}"
]
| // NewEdgeHostname creates a new EdgeHostname within a given EdgeHostnames | [
"NewEdgeHostname",
"creates",
"a",
"new",
"EdgeHostname",
"within",
"a",
"given",
"EdgeHostnames"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/edgehostnames.go#L51-L55 |
146,409 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/edgehostnames.go | NewEdgeHostname | func NewEdgeHostname(edgeHostnames *EdgeHostnames) *EdgeHostname {
edgeHostname := &EdgeHostname{parent: edgeHostnames}
edgeHostname.Init()
return edgeHostname
} | go | func NewEdgeHostname(edgeHostnames *EdgeHostnames) *EdgeHostname {
edgeHostname := &EdgeHostname{parent: edgeHostnames}
edgeHostname.Init()
return edgeHostname
} | [
"func",
"NewEdgeHostname",
"(",
"edgeHostnames",
"*",
"EdgeHostnames",
")",
"*",
"EdgeHostname",
"{",
"edgeHostname",
":=",
"&",
"EdgeHostname",
"{",
"parent",
":",
"edgeHostnames",
"}",
"\n",
"edgeHostname",
".",
"Init",
"(",
")",
"\n",
"return",
"edgeHostname",
"\n",
"}"
]
| // NewEdgeHostname creates a new EdgeHostname | [
"NewEdgeHostname",
"creates",
"a",
"new",
"EdgeHostname"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/edgehostnames.go#L161-L165 |
146,410 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/properties.go | AddProperty | func (properties *Properties) AddProperty(newProperty *Property) {
if newProperty.PropertyID != "" {
for key, property := range properties.Properties.Items {
if property.PropertyID == newProperty.PropertyID {
properties.Properties.Items[key] = newProperty
return
}
}
}
newProperty.parent = properties
properties.Properties.Items = append(properties.Properties.Items, newProperty)
} | go | func (properties *Properties) AddProperty(newProperty *Property) {
if newProperty.PropertyID != "" {
for key, property := range properties.Properties.Items {
if property.PropertyID == newProperty.PropertyID {
properties.Properties.Items[key] = newProperty
return
}
}
}
newProperty.parent = properties
properties.Properties.Items = append(properties.Properties.Items, newProperty)
} | [
"func",
"(",
"properties",
"*",
"Properties",
")",
"AddProperty",
"(",
"newProperty",
"*",
"Property",
")",
"{",
"if",
"newProperty",
".",
"PropertyID",
"!=",
"\"",
"\"",
"{",
"for",
"key",
",",
"property",
":=",
"range",
"properties",
".",
"Properties",
".",
"Items",
"{",
"if",
"property",
".",
"PropertyID",
"==",
"newProperty",
".",
"PropertyID",
"{",
"properties",
".",
"Properties",
".",
"Items",
"[",
"key",
"]",
"=",
"newProperty",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"newProperty",
".",
"parent",
"=",
"properties",
"\n\n",
"properties",
".",
"Properties",
".",
"Items",
"=",
"append",
"(",
"properties",
".",
"Properties",
".",
"Items",
",",
"newProperty",
")",
"\n",
"}"
]
| // AddProperty adds a property to the collection, if the property already exists
// in the collection it will be replaced. | [
"AddProperty",
"adds",
"a",
"property",
"to",
"the",
"collection",
"if",
"the",
"property",
"already",
"exists",
"in",
"the",
"collection",
"it",
"will",
"be",
"replaced",
"."
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/properties.go#L83-L96 |
146,411 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/properties.go | FindProperty | func (properties *Properties) FindProperty(id string) (*Property, error) {
var property *Property
var propertyFound bool
for _, property = range properties.Properties.Items {
if property.PropertyID == id {
propertyFound = true
break
}
}
if !propertyFound {
return nil, fmt.Errorf("Unable to find property: \"%s\"", id)
}
return property, nil
} | go | func (properties *Properties) FindProperty(id string) (*Property, error) {
var property *Property
var propertyFound bool
for _, property = range properties.Properties.Items {
if property.PropertyID == id {
propertyFound = true
break
}
}
if !propertyFound {
return nil, fmt.Errorf("Unable to find property: \"%s\"", id)
}
return property, nil
} | [
"func",
"(",
"properties",
"*",
"Properties",
")",
"FindProperty",
"(",
"id",
"string",
")",
"(",
"*",
"Property",
",",
"error",
")",
"{",
"var",
"property",
"*",
"Property",
"\n",
"var",
"propertyFound",
"bool",
"\n",
"for",
"_",
",",
"property",
"=",
"range",
"properties",
".",
"Properties",
".",
"Items",
"{",
"if",
"property",
".",
"PropertyID",
"==",
"id",
"{",
"propertyFound",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"propertyFound",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n\n",
"return",
"property",
",",
"nil",
"\n",
"}"
]
| // FindProperty finds a property by ID within the collection | [
"FindProperty",
"finds",
"a",
"property",
"by",
"ID",
"within",
"the",
"collection"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/properties.go#L99-L114 |
146,412 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/properties.go | NewProperty | func (properties *Properties) NewProperty(contract *Contract, group *Group) *Property {
property := NewProperty(properties)
properties.AddProperty(property)
property.Contract = contract
property.Group = group
go property.Contract.GetContract()
go property.Group.GetGroup()
go (func(property *Property) {
groupCompleted := <-property.Group.Complete
contractCompleted := <-property.Contract.Complete
property.Complete <- (groupCompleted && contractCompleted)
})(property)
return property
} | go | func (properties *Properties) NewProperty(contract *Contract, group *Group) *Property {
property := NewProperty(properties)
properties.AddProperty(property)
property.Contract = contract
property.Group = group
go property.Contract.GetContract()
go property.Group.GetGroup()
go (func(property *Property) {
groupCompleted := <-property.Group.Complete
contractCompleted := <-property.Contract.Complete
property.Complete <- (groupCompleted && contractCompleted)
})(property)
return property
} | [
"func",
"(",
"properties",
"*",
"Properties",
")",
"NewProperty",
"(",
"contract",
"*",
"Contract",
",",
"group",
"*",
"Group",
")",
"*",
"Property",
"{",
"property",
":=",
"NewProperty",
"(",
"properties",
")",
"\n\n",
"properties",
".",
"AddProperty",
"(",
"property",
")",
"\n\n",
"property",
".",
"Contract",
"=",
"contract",
"\n",
"property",
".",
"Group",
"=",
"group",
"\n",
"go",
"property",
".",
"Contract",
".",
"GetContract",
"(",
")",
"\n",
"go",
"property",
".",
"Group",
".",
"GetGroup",
"(",
")",
"\n",
"go",
"(",
"func",
"(",
"property",
"*",
"Property",
")",
"{",
"groupCompleted",
":=",
"<-",
"property",
".",
"Group",
".",
"Complete",
"\n",
"contractCompleted",
":=",
"<-",
"property",
".",
"Contract",
".",
"Complete",
"\n",
"property",
".",
"Complete",
"<-",
"(",
"groupCompleted",
"&&",
"contractCompleted",
")",
"\n",
"}",
")",
"(",
"property",
")",
"\n\n",
"return",
"property",
"\n",
"}"
]
| // NewProperty creates a new property associated with the collection | [
"NewProperty",
"creates",
"a",
"new",
"property",
"associated",
"with",
"the",
"collection"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/properties.go#L117-L133 |
146,413 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/properties.go | NewProperty | func NewProperty(parent *Properties) *Property {
property := &Property{parent: parent, Group: &Group{}, Contract: &Contract{}}
property.Init()
return property
} | go | func NewProperty(parent *Properties) *Property {
property := &Property{parent: parent, Group: &Group{}, Contract: &Contract{}}
property.Init()
return property
} | [
"func",
"NewProperty",
"(",
"parent",
"*",
"Properties",
")",
"*",
"Property",
"{",
"property",
":=",
"&",
"Property",
"{",
"parent",
":",
"parent",
",",
"Group",
":",
"&",
"Group",
"{",
"}",
",",
"Contract",
":",
"&",
"Contract",
"{",
"}",
"}",
"\n",
"property",
".",
"Init",
"(",
")",
"\n",
"return",
"property",
"\n",
"}"
]
| // NewProperty creates a new Property | [
"NewProperty",
"creates",
"a",
"new",
"Property"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/properties.go#L156-L160 |
146,414 | akamai/AkamaiOPEN-edgegrid-golang | client-v1/errors.go | NewAPIError | func NewAPIError(response *http.Response) APIError {
// TODO: handle this error
body, _ := ioutil.ReadAll(response.Body)
return NewAPIErrorFromBody(response, body)
} | go | func NewAPIError(response *http.Response) APIError {
// TODO: handle this error
body, _ := ioutil.ReadAll(response.Body)
return NewAPIErrorFromBody(response, body)
} | [
"func",
"NewAPIError",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"APIError",
"{",
"// TODO: handle this error",
"body",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n\n",
"return",
"NewAPIErrorFromBody",
"(",
"response",
",",
"body",
")",
"\n",
"}"
]
| // NewAPIError creates a new API error based on a Response,
// or http.Response-like. | [
"NewAPIError",
"creates",
"a",
"new",
"API",
"error",
"based",
"on",
"a",
"Response",
"or",
"http",
".",
"Response",
"-",
"like",
"."
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/client-v1/errors.go#L55-L60 |
146,415 | akamai/AkamaiOPEN-edgegrid-golang | client-v1/errors.go | NewAPIErrorFromBody | func NewAPIErrorFromBody(response *http.Response, body []byte) APIError {
error := APIError{}
if err := jsonhooks.Unmarshal(body, &error); err == nil {
error.Status = response.StatusCode
error.Title = response.Status
}
error.Response = response
error.RawBody = string(body)
return error
} | go | func NewAPIErrorFromBody(response *http.Response, body []byte) APIError {
error := APIError{}
if err := jsonhooks.Unmarshal(body, &error); err == nil {
error.Status = response.StatusCode
error.Title = response.Status
}
error.Response = response
error.RawBody = string(body)
return error
} | [
"func",
"NewAPIErrorFromBody",
"(",
"response",
"*",
"http",
".",
"Response",
",",
"body",
"[",
"]",
"byte",
")",
"APIError",
"{",
"error",
":=",
"APIError",
"{",
"}",
"\n",
"if",
"err",
":=",
"jsonhooks",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"error",
")",
";",
"err",
"==",
"nil",
"{",
"error",
".",
"Status",
"=",
"response",
".",
"StatusCode",
"\n",
"error",
".",
"Title",
"=",
"response",
".",
"Status",
"\n",
"}",
"\n\n",
"error",
".",
"Response",
"=",
"response",
"\n",
"error",
".",
"RawBody",
"=",
"string",
"(",
"body",
")",
"\n\n",
"return",
"error",
"\n",
"}"
]
| // NewAPIErrorFromBody creates a new API error, allowing you to pass in a body
//
// This function is intended to be used after the body has already been read for
// other purposes. | [
"NewAPIErrorFromBody",
"creates",
"a",
"new",
"API",
"error",
"allowing",
"you",
"to",
"pass",
"in",
"a",
"body",
"This",
"function",
"is",
"intended",
"to",
"be",
"used",
"after",
"the",
"body",
"has",
"already",
"been",
"read",
"for",
"other",
"purposes",
"."
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/client-v1/errors.go#L66-L77 |
146,416 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/customoverrides.go | PostUnmarshalJSON | func (overrides *CustomOverrides) PostUnmarshalJSON() error {
overrides.Init()
for key, override := range overrides.CustomOverrides.Items {
overrides.CustomOverrides.Items[key].parent = overrides
if err := override.PostUnmarshalJSON(); err != nil {
return err
}
}
overrides.Complete <- true
return nil
} | go | func (overrides *CustomOverrides) PostUnmarshalJSON() error {
overrides.Init()
for key, override := range overrides.CustomOverrides.Items {
overrides.CustomOverrides.Items[key].parent = overrides
if err := override.PostUnmarshalJSON(); err != nil {
return err
}
}
overrides.Complete <- true
return nil
} | [
"func",
"(",
"overrides",
"*",
"CustomOverrides",
")",
"PostUnmarshalJSON",
"(",
")",
"error",
"{",
"overrides",
".",
"Init",
"(",
")",
"\n\n",
"for",
"key",
",",
"override",
":=",
"range",
"overrides",
".",
"CustomOverrides",
".",
"Items",
"{",
"overrides",
".",
"CustomOverrides",
".",
"Items",
"[",
"key",
"]",
".",
"parent",
"=",
"overrides",
"\n\n",
"if",
"err",
":=",
"override",
".",
"PostUnmarshalJSON",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"overrides",
".",
"Complete",
"<-",
"true",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // PostUnmarshalJSON is called after UnmarshalJSON to setup the
// structs internal state. The CustomOverrides.Complete channel is utilized
// to communicate full completion. | [
"PostUnmarshalJSON",
"is",
"called",
"after",
"UnmarshalJSON",
"to",
"setup",
"the",
"structs",
"internal",
"state",
".",
"The",
"CustomOverrides",
".",
"Complete",
"channel",
"is",
"utilized",
"to",
"communicate",
"full",
"completion",
"."
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/customoverrides.go#L30-L44 |
146,417 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/products.go | FindProduct | func (products *Products) FindProduct(id string) (*Product, error) {
var product *Product
var productFound bool
for _, product = range products.Products.Items {
if product.ProductID == id {
productFound = true
break
}
}
if !productFound {
return nil, fmt.Errorf("Unable to find product: \"%s\"", id)
}
return product, nil
} | go | func (products *Products) FindProduct(id string) (*Product, error) {
var product *Product
var productFound bool
for _, product = range products.Products.Items {
if product.ProductID == id {
productFound = true
break
}
}
if !productFound {
return nil, fmt.Errorf("Unable to find product: \"%s\"", id)
}
return product, nil
} | [
"func",
"(",
"products",
"*",
"Products",
")",
"FindProduct",
"(",
"id",
"string",
")",
"(",
"*",
"Product",
",",
"error",
")",
"{",
"var",
"product",
"*",
"Product",
"\n",
"var",
"productFound",
"bool",
"\n",
"for",
"_",
",",
"product",
"=",
"range",
"products",
".",
"Products",
".",
"Items",
"{",
"if",
"product",
".",
"ProductID",
"==",
"id",
"{",
"productFound",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"productFound",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n\n",
"return",
"product",
",",
"nil",
"\n",
"}"
]
| // FindProduct finds a specific product by ID | [
"FindProduct",
"finds",
"a",
"specific",
"product",
"by",
"ID"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/products.go#L78-L93 |
146,418 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/products.go | NewProduct | func NewProduct(parent *Products) *Product {
product := &Product{parent: parent}
product.Init()
return product
} | go | func NewProduct(parent *Products) *Product {
product := &Product{parent: parent}
product.Init()
return product
} | [
"func",
"NewProduct",
"(",
"parent",
"*",
"Products",
")",
"*",
"Product",
"{",
"product",
":=",
"&",
"Product",
"{",
"parent",
":",
"parent",
"}",
"\n",
"product",
".",
"Init",
"(",
")",
"\n\n",
"return",
"product",
"\n",
"}"
]
| // NewProduct creates a new Product | [
"NewProduct",
"creates",
"a",
"new",
"Product"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/products.go#L104-L109 |
146,419 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/service.go | GetContracts | func GetContracts() (*Contracts, error) {
contracts := NewContracts()
if err := contracts.GetContracts(); err != nil {
return nil, err
}
return contracts, nil
} | go | func GetContracts() (*Contracts, error) {
contracts := NewContracts()
if err := contracts.GetContracts(); err != nil {
return nil, err
}
return contracts, nil
} | [
"func",
"GetContracts",
"(",
")",
"(",
"*",
"Contracts",
",",
"error",
")",
"{",
"contracts",
":=",
"NewContracts",
"(",
")",
"\n",
"if",
"err",
":=",
"contracts",
".",
"GetContracts",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"contracts",
",",
"nil",
"\n",
"}"
]
| // GetContracts retrieves all contracts | [
"GetContracts",
"retrieves",
"all",
"contracts"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/service.go#L22-L29 |
146,420 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/service.go | GetProducts | func GetProducts(contract *Contract) (*Products, error) {
products := NewProducts()
if err := products.GetProducts(contract); err != nil {
return nil, err
}
return products, nil
} | go | func GetProducts(contract *Contract) (*Products, error) {
products := NewProducts()
if err := products.GetProducts(contract); err != nil {
return nil, err
}
return products, nil
} | [
"func",
"GetProducts",
"(",
"contract",
"*",
"Contract",
")",
"(",
"*",
"Products",
",",
"error",
")",
"{",
"products",
":=",
"NewProducts",
"(",
")",
"\n",
"if",
"err",
":=",
"products",
".",
"GetProducts",
"(",
"contract",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"products",
",",
"nil",
"\n",
"}"
]
| // GetProducts retrieves all products | [
"GetProducts",
"retrieves",
"all",
"products"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/service.go#L32-L39 |
146,421 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/service.go | GetEdgeHostnames | func GetEdgeHostnames(contract *Contract, group *Group, options string) (*EdgeHostnames, error) {
edgeHostnames := NewEdgeHostnames()
if err := edgeHostnames.GetEdgeHostnames(contract, group, options); err != nil {
return nil, err
}
return edgeHostnames, nil
} | go | func GetEdgeHostnames(contract *Contract, group *Group, options string) (*EdgeHostnames, error) {
edgeHostnames := NewEdgeHostnames()
if err := edgeHostnames.GetEdgeHostnames(contract, group, options); err != nil {
return nil, err
}
return edgeHostnames, nil
} | [
"func",
"GetEdgeHostnames",
"(",
"contract",
"*",
"Contract",
",",
"group",
"*",
"Group",
",",
"options",
"string",
")",
"(",
"*",
"EdgeHostnames",
",",
"error",
")",
"{",
"edgeHostnames",
":=",
"NewEdgeHostnames",
"(",
")",
"\n",
"if",
"err",
":=",
"edgeHostnames",
".",
"GetEdgeHostnames",
"(",
"contract",
",",
"group",
",",
"options",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"edgeHostnames",
",",
"nil",
"\n",
"}"
]
| // GetEdgeHostnames retrieves all edge hostnames | [
"GetEdgeHostnames",
"retrieves",
"all",
"edge",
"hostnames"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/service.go#L42-L49 |
146,422 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/service.go | GetVersions | func GetVersions(property *Property) (*Versions, error) {
versions := NewVersions()
if err := versions.GetVersions(property); err != nil {
return nil, err
}
return versions, nil
} | go | func GetVersions(property *Property) (*Versions, error) {
versions := NewVersions()
if err := versions.GetVersions(property); err != nil {
return nil, err
}
return versions, nil
} | [
"func",
"GetVersions",
"(",
"property",
"*",
"Property",
")",
"(",
"*",
"Versions",
",",
"error",
")",
"{",
"versions",
":=",
"NewVersions",
"(",
")",
"\n",
"if",
"err",
":=",
"versions",
".",
"GetVersions",
"(",
"property",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"versions",
",",
"nil",
"\n",
"}"
]
| // GetVersions retrieves all versions for a given property | [
"GetVersions",
"retrieves",
"all",
"versions",
"for",
"a",
"given",
"property"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/service.go#L74-L81 |
146,423 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/service.go | GetAvailableCriteria | func GetAvailableCriteria(property *Property) (*AvailableCriteria, error) {
availableCriteria := NewAvailableCriteria()
if err := availableCriteria.GetAvailableCriteria(property); err != nil {
return nil, err
}
return availableCriteria, nil
} | go | func GetAvailableCriteria(property *Property) (*AvailableCriteria, error) {
availableCriteria := NewAvailableCriteria()
if err := availableCriteria.GetAvailableCriteria(property); err != nil {
return nil, err
}
return availableCriteria, nil
} | [
"func",
"GetAvailableCriteria",
"(",
"property",
"*",
"Property",
")",
"(",
"*",
"AvailableCriteria",
",",
"error",
")",
"{",
"availableCriteria",
":=",
"NewAvailableCriteria",
"(",
")",
"\n",
"if",
"err",
":=",
"availableCriteria",
".",
"GetAvailableCriteria",
"(",
"property",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"availableCriteria",
",",
"nil",
"\n",
"}"
]
| // GetAvailableCriteria retrieves all available criteria for a property | [
"GetAvailableCriteria",
"retrieves",
"all",
"available",
"criteria",
"for",
"a",
"property"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/service.go#L94-L101 |
146,424 | akamai/AkamaiOPEN-edgegrid-golang | configdns-v1/zone.go | NewZone | func NewZone(hostname string) *Zone {
zone := &Zone{Token: "new"}
zone.Zone.Soa = NewSoaRecord()
zone.Zone.Name = hostname
return zone
} | go | func NewZone(hostname string) *Zone {
zone := &Zone{Token: "new"}
zone.Zone.Soa = NewSoaRecord()
zone.Zone.Name = hostname
return zone
} | [
"func",
"NewZone",
"(",
"hostname",
"string",
")",
"*",
"Zone",
"{",
"zone",
":=",
"&",
"Zone",
"{",
"Token",
":",
"\"",
"\"",
"}",
"\n",
"zone",
".",
"Zone",
".",
"Soa",
"=",
"NewSoaRecord",
"(",
")",
"\n",
"zone",
".",
"Zone",
".",
"Name",
"=",
"hostname",
"\n",
"return",
"zone",
"\n",
"}"
]
| // NewZone creates a new Zone | [
"NewZone",
"creates",
"a",
"new",
"Zone"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/configdns-v1/zone.go#L55-L60 |
146,425 | akamai/AkamaiOPEN-edgegrid-golang | configdns-v1/zone.go | GetZone | func GetZone(hostname string) (*Zone, error) {
zone := NewZone(hostname)
req, err := client.NewRequest(
Config,
"GET",
"/config-dns/v1/zones/"+hostname,
nil,
)
if err != nil {
return nil, err
}
res, err := client.Do(Config, req)
if err != nil {
return nil, err
}
if client.IsError(res) && res.StatusCode != 404 {
return nil, client.NewAPIError(res)
} else if res.StatusCode == 404 {
return nil, &ZoneError{zoneName: hostname}
} else {
err = client.BodyJSON(res, zone)
if err != nil {
return nil, err
}
return zone, nil
}
} | go | func GetZone(hostname string) (*Zone, error) {
zone := NewZone(hostname)
req, err := client.NewRequest(
Config,
"GET",
"/config-dns/v1/zones/"+hostname,
nil,
)
if err != nil {
return nil, err
}
res, err := client.Do(Config, req)
if err != nil {
return nil, err
}
if client.IsError(res) && res.StatusCode != 404 {
return nil, client.NewAPIError(res)
} else if res.StatusCode == 404 {
return nil, &ZoneError{zoneName: hostname}
} else {
err = client.BodyJSON(res, zone)
if err != nil {
return nil, err
}
return zone, nil
}
} | [
"func",
"GetZone",
"(",
"hostname",
"string",
")",
"(",
"*",
"Zone",
",",
"error",
")",
"{",
"zone",
":=",
"NewZone",
"(",
"hostname",
")",
"\n",
"req",
",",
"err",
":=",
"client",
".",
"NewRequest",
"(",
"Config",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"hostname",
",",
"nil",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"Config",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"client",
".",
"IsError",
"(",
"res",
")",
"&&",
"res",
".",
"StatusCode",
"!=",
"404",
"{",
"return",
"nil",
",",
"client",
".",
"NewAPIError",
"(",
"res",
")",
"\n",
"}",
"else",
"if",
"res",
".",
"StatusCode",
"==",
"404",
"{",
"return",
"nil",
",",
"&",
"ZoneError",
"{",
"zoneName",
":",
"hostname",
"}",
"\n",
"}",
"else",
"{",
"err",
"=",
"client",
".",
"BodyJSON",
"(",
"res",
",",
"zone",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"zone",
",",
"nil",
"\n",
"}",
"\n",
"}"
]
| // GetZone retrieves a DNS Zone for a given hostname | [
"GetZone",
"retrieves",
"a",
"DNS",
"Zone",
"for",
"a",
"given",
"hostname"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/configdns-v1/zone.go#L63-L92 |
146,426 | akamai/AkamaiOPEN-edgegrid-golang | configdns-v1/zone.go | Save | func (zone *Zone) Save() error {
// This lock will restrict the concurrency of API calls
// to 1 save request at a time. This is needed for the Soa.Serial value which
// is required to be incremented for every subsequent update to a zone
// so we have to save just one request at a time to ensure this is always
// incremented properly
zoneWriteLock.Lock()
defer zoneWriteLock.Unlock()
valid, f := zone.validateCnames()
if valid == false {
var msg string
for _, v := range f {
msg = msg + fmt.Sprintf("\n%s Record '%s' conflicts with CNAME", v.recordType, v.name)
}
return &ZoneError{
zoneName: zone.Zone.Name,
apiErrorMessage: "All CNAMEs must be unique in the zone" + msg,
}
}
req, err := client.NewJSONRequest(
Config,
"POST",
"/config-dns/v1/zones/"+zone.Zone.Name,
zone,
)
if err != nil {
return err
}
res, err := client.Do(Config, req)
// Network error
if err != nil {
return &ZoneError{
zoneName: zone.Zone.Name,
httpErrorMessage: err.Error(),
err: err,
}
}
// API error
if client.IsError(res) {
err := client.NewAPIError(res)
return &ZoneError{zoneName: zone.Zone.Name, apiErrorMessage: err.Detail, err: err}
}
for {
updatedZone, err := GetZone(zone.Zone.Name)
if err != nil {
return err
}
if updatedZone.Token != zone.Token {
*zone = *updatedZone
break
}
time.Sleep(time.Second)
}
return nil
} | go | func (zone *Zone) Save() error {
// This lock will restrict the concurrency of API calls
// to 1 save request at a time. This is needed for the Soa.Serial value which
// is required to be incremented for every subsequent update to a zone
// so we have to save just one request at a time to ensure this is always
// incremented properly
zoneWriteLock.Lock()
defer zoneWriteLock.Unlock()
valid, f := zone.validateCnames()
if valid == false {
var msg string
for _, v := range f {
msg = msg + fmt.Sprintf("\n%s Record '%s' conflicts with CNAME", v.recordType, v.name)
}
return &ZoneError{
zoneName: zone.Zone.Name,
apiErrorMessage: "All CNAMEs must be unique in the zone" + msg,
}
}
req, err := client.NewJSONRequest(
Config,
"POST",
"/config-dns/v1/zones/"+zone.Zone.Name,
zone,
)
if err != nil {
return err
}
res, err := client.Do(Config, req)
// Network error
if err != nil {
return &ZoneError{
zoneName: zone.Zone.Name,
httpErrorMessage: err.Error(),
err: err,
}
}
// API error
if client.IsError(res) {
err := client.NewAPIError(res)
return &ZoneError{zoneName: zone.Zone.Name, apiErrorMessage: err.Detail, err: err}
}
for {
updatedZone, err := GetZone(zone.Zone.Name)
if err != nil {
return err
}
if updatedZone.Token != zone.Token {
*zone = *updatedZone
break
}
time.Sleep(time.Second)
}
return nil
} | [
"func",
"(",
"zone",
"*",
"Zone",
")",
"Save",
"(",
")",
"error",
"{",
"// This lock will restrict the concurrency of API calls",
"// to 1 save request at a time. This is needed for the Soa.Serial value which",
"// is required to be incremented for every subsequent update to a zone",
"// so we have to save just one request at a time to ensure this is always",
"// incremented properly",
"zoneWriteLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"zoneWriteLock",
".",
"Unlock",
"(",
")",
"\n\n",
"valid",
",",
"f",
":=",
"zone",
".",
"validateCnames",
"(",
")",
"\n",
"if",
"valid",
"==",
"false",
"{",
"var",
"msg",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"f",
"{",
"msg",
"=",
"msg",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"v",
".",
"recordType",
",",
"v",
".",
"name",
")",
"\n",
"}",
"\n",
"return",
"&",
"ZoneError",
"{",
"zoneName",
":",
"zone",
".",
"Zone",
".",
"Name",
",",
"apiErrorMessage",
":",
"\"",
"\"",
"+",
"msg",
",",
"}",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"client",
".",
"NewJSONRequest",
"(",
"Config",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"zone",
".",
"Zone",
".",
"Name",
",",
"zone",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"Config",
",",
"req",
")",
"\n\n",
"// Network error",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"ZoneError",
"{",
"zoneName",
":",
"zone",
".",
"Zone",
".",
"Name",
",",
"httpErrorMessage",
":",
"err",
".",
"Error",
"(",
")",
",",
"err",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"// API error",
"if",
"client",
".",
"IsError",
"(",
"res",
")",
"{",
"err",
":=",
"client",
".",
"NewAPIError",
"(",
"res",
")",
"\n",
"return",
"&",
"ZoneError",
"{",
"zoneName",
":",
"zone",
".",
"Zone",
".",
"Name",
",",
"apiErrorMessage",
":",
"err",
".",
"Detail",
",",
"err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"for",
"{",
"updatedZone",
",",
"err",
":=",
"GetZone",
"(",
"zone",
".",
"Zone",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"updatedZone",
".",
"Token",
"!=",
"zone",
".",
"Token",
"{",
"*",
"zone",
"=",
"*",
"updatedZone",
"\n",
"break",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Second",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Save updates the Zone | [
"Save",
"updates",
"the",
"Zone"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/configdns-v1/zone.go#L95-L157 |
146,427 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/available.go | NewAvailableBehavior | func NewAvailableBehavior(parent *AvailableBehaviors) *AvailableBehavior {
availableBehavior := &AvailableBehavior{parent: parent}
availableBehavior.Init()
return availableBehavior
} | go | func NewAvailableBehavior(parent *AvailableBehaviors) *AvailableBehavior {
availableBehavior := &AvailableBehavior{parent: parent}
availableBehavior.Init()
return availableBehavior
} | [
"func",
"NewAvailableBehavior",
"(",
"parent",
"*",
"AvailableBehaviors",
")",
"*",
"AvailableBehavior",
"{",
"availableBehavior",
":=",
"&",
"AvailableBehavior",
"{",
"parent",
":",
"parent",
"}",
"\n",
"availableBehavior",
".",
"Init",
"(",
")",
"\n\n",
"return",
"availableBehavior",
"\n",
"}"
]
| // NewAvailableBehavior creates a new AvailableBehavior | [
"NewAvailableBehavior",
"creates",
"a",
"new",
"AvailableBehavior"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/available.go#L153-L158 |
146,428 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/available.go | GetSchema | func (behavior *AvailableBehavior) GetSchema() (*gojsonschema.Schema, error) {
req, err := client.NewRequest(
Config,
"GET",
behavior.SchemaLink,
nil,
)
if err != nil {
return nil, err
}
res, err := client.Do(Config, req)
if err != nil {
return nil, err
}
schemaBytes, _ := ioutil.ReadAll(res.Body)
schemaBody := string(schemaBytes)
loader := gojsonschema.NewStringLoader(schemaBody)
schema, err := gojsonschema.NewSchema(loader)
return schema, err
} | go | func (behavior *AvailableBehavior) GetSchema() (*gojsonschema.Schema, error) {
req, err := client.NewRequest(
Config,
"GET",
behavior.SchemaLink,
nil,
)
if err != nil {
return nil, err
}
res, err := client.Do(Config, req)
if err != nil {
return nil, err
}
schemaBytes, _ := ioutil.ReadAll(res.Body)
schemaBody := string(schemaBytes)
loader := gojsonschema.NewStringLoader(schemaBody)
schema, err := gojsonschema.NewSchema(loader)
return schema, err
} | [
"func",
"(",
"behavior",
"*",
"AvailableBehavior",
")",
"GetSchema",
"(",
")",
"(",
"*",
"gojsonschema",
".",
"Schema",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"client",
".",
"NewRequest",
"(",
"Config",
",",
"\"",
"\"",
",",
"behavior",
".",
"SchemaLink",
",",
"nil",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"Config",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"schemaBytes",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"res",
".",
"Body",
")",
"\n",
"schemaBody",
":=",
"string",
"(",
"schemaBytes",
")",
"\n",
"loader",
":=",
"gojsonschema",
".",
"NewStringLoader",
"(",
"schemaBody",
")",
"\n",
"schema",
",",
"err",
":=",
"gojsonschema",
".",
"NewSchema",
"(",
"loader",
")",
"\n\n",
"return",
"schema",
",",
"err",
"\n",
"}"
]
| // GetSchema retrieves the JSON schema for an available behavior | [
"GetSchema",
"retrieves",
"the",
"JSON",
"schema",
"for",
"an",
"available",
"behavior"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/available.go#L161-L183 |
146,429 | akamai/AkamaiOPEN-edgegrid-golang | jsonhooks-v1/jsonhooks.go | ImplementsPreJSONMarshaler | func ImplementsPreJSONMarshaler(v interface{}) bool {
value := reflect.ValueOf(v)
if !value.IsValid() {
return false
}
_, ok := value.Interface().(PreJSONMarshaler)
return ok
} | go | func ImplementsPreJSONMarshaler(v interface{}) bool {
value := reflect.ValueOf(v)
if !value.IsValid() {
return false
}
_, ok := value.Interface().(PreJSONMarshaler)
return ok
} | [
"func",
"ImplementsPreJSONMarshaler",
"(",
"v",
"interface",
"{",
"}",
")",
"bool",
"{",
"value",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"!",
"value",
".",
"IsValid",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
":=",
"value",
".",
"Interface",
"(",
")",
".",
"(",
"PreJSONMarshaler",
")",
"\n",
"return",
"ok",
"\n",
"}"
]
| // ImplementsPreJSONMarshaler checks for support for the PreMarshalJSON pre-hook | [
"ImplementsPreJSONMarshaler",
"checks",
"for",
"support",
"for",
"the",
"PreMarshalJSON",
"pre",
"-",
"hook"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/jsonhooks-v1/jsonhooks.go#L45-L53 |
146,430 | akamai/AkamaiOPEN-edgegrid-golang | jsonhooks-v1/jsonhooks.go | ImplementsPostJSONUnmarshaler | func ImplementsPostJSONUnmarshaler(v interface{}) bool {
value := reflect.ValueOf(v)
if value.Kind() == reflect.Ptr && value.IsNil() {
return false
}
_, ok := value.Interface().(PostJSONUnmarshaler)
return ok
} | go | func ImplementsPostJSONUnmarshaler(v interface{}) bool {
value := reflect.ValueOf(v)
if value.Kind() == reflect.Ptr && value.IsNil() {
return false
}
_, ok := value.Interface().(PostJSONUnmarshaler)
return ok
} | [
"func",
"ImplementsPostJSONUnmarshaler",
"(",
"v",
"interface",
"{",
"}",
")",
"bool",
"{",
"value",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"value",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"&&",
"value",
".",
"IsNil",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
":=",
"value",
".",
"Interface",
"(",
")",
".",
"(",
"PostJSONUnmarshaler",
")",
"\n",
"return",
"ok",
"\n",
"}"
]
| // ImplementsPostJSONUnmarshaler checks for support for the PostUnmarshalJSON post-hook | [
"ImplementsPostJSONUnmarshaler",
"checks",
"for",
"support",
"for",
"the",
"PostUnmarshalJSON",
"post",
"-",
"hook"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/jsonhooks-v1/jsonhooks.go#L61-L69 |
146,431 | akamai/AkamaiOPEN-edgegrid-golang | client-v1/client.go | NewRequest | func NewRequest(config edgegrid.Config, method, path string, body io.Reader) (*http.Request, error) {
var (
baseURL *url.URL
err error
)
if strings.HasPrefix(config.Host, "https://") {
baseURL, err = url.Parse(config.Host)
} else {
baseURL, err = url.Parse("https://" + config.Host)
}
if err != nil {
return nil, err
}
rel, err := url.Parse(strings.TrimPrefix(path, "/"))
if err != nil {
return nil, err
}
u := baseURL.ResolveReference(rel)
req, err := http.NewRequest(method, u.String(), body)
if err != nil {
return nil, err
}
req.Header.Add("User-Agent", UserAgent)
return req, nil
} | go | func NewRequest(config edgegrid.Config, method, path string, body io.Reader) (*http.Request, error) {
var (
baseURL *url.URL
err error
)
if strings.HasPrefix(config.Host, "https://") {
baseURL, err = url.Parse(config.Host)
} else {
baseURL, err = url.Parse("https://" + config.Host)
}
if err != nil {
return nil, err
}
rel, err := url.Parse(strings.TrimPrefix(path, "/"))
if err != nil {
return nil, err
}
u := baseURL.ResolveReference(rel)
req, err := http.NewRequest(method, u.String(), body)
if err != nil {
return nil, err
}
req.Header.Add("User-Agent", UserAgent)
return req, nil
} | [
"func",
"NewRequest",
"(",
"config",
"edgegrid",
".",
"Config",
",",
"method",
",",
"path",
"string",
",",
"body",
"io",
".",
"Reader",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"var",
"(",
"baseURL",
"*",
"url",
".",
"URL",
"\n",
"err",
"error",
"\n",
")",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"config",
".",
"Host",
",",
"\"",
"\"",
")",
"{",
"baseURL",
",",
"err",
"=",
"url",
".",
"Parse",
"(",
"config",
".",
"Host",
")",
"\n",
"}",
"else",
"{",
"baseURL",
",",
"err",
"=",
"url",
".",
"Parse",
"(",
"\"",
"\"",
"+",
"config",
".",
"Host",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"rel",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"strings",
".",
"TrimPrefix",
"(",
"path",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"u",
":=",
"baseURL",
".",
"ResolveReference",
"(",
"rel",
")",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"method",
",",
"u",
".",
"String",
"(",
")",
",",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"UserAgent",
")",
"\n\n",
"return",
"req",
",",
"nil",
"\n",
"}"
]
| // NewRequest creates an HTTP request that can be sent to Akamai APIs. A relative URL can be provided in path, which will be resolved to the
// Host specified in Config. If body is specified, it will be sent as the request body. | [
"NewRequest",
"creates",
"an",
"HTTP",
"request",
"that",
"can",
"be",
"sent",
"to",
"Akamai",
"APIs",
".",
"A",
"relative",
"URL",
"can",
"be",
"provided",
"in",
"path",
"which",
"will",
"be",
"resolved",
"to",
"the",
"Host",
"specified",
"in",
"Config",
".",
"If",
"body",
"is",
"specified",
"it",
"will",
"be",
"sent",
"as",
"the",
"request",
"body",
"."
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/client-v1/client.go#L31-L62 |
146,432 | akamai/AkamaiOPEN-edgegrid-golang | client-v1/client.go | NewMultiPartFormDataRequest | func NewMultiPartFormDataRequest(config edgegrid.Config, uriPath, filePath string, otherFormParams map[string]string) (*http.Request, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
// TODO: make this field name configurable
part, err := writer.CreateFormFile("importFile", filepath.Base(filePath))
if err != nil {
return nil, err
}
_, err = io.Copy(part, file)
for key, val := range otherFormParams {
_ = writer.WriteField(key, val)
}
err = writer.Close()
if err != nil {
return nil, err
}
req, err := NewRequest(config, "POST", uriPath, body)
req.Header.Set("Content-Type", writer.FormDataContentType())
return req, err
} | go | func NewMultiPartFormDataRequest(config edgegrid.Config, uriPath, filePath string, otherFormParams map[string]string) (*http.Request, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
// TODO: make this field name configurable
part, err := writer.CreateFormFile("importFile", filepath.Base(filePath))
if err != nil {
return nil, err
}
_, err = io.Copy(part, file)
for key, val := range otherFormParams {
_ = writer.WriteField(key, val)
}
err = writer.Close()
if err != nil {
return nil, err
}
req, err := NewRequest(config, "POST", uriPath, body)
req.Header.Set("Content-Type", writer.FormDataContentType())
return req, err
} | [
"func",
"NewMultiPartFormDataRequest",
"(",
"config",
"edgegrid",
".",
"Config",
",",
"uriPath",
",",
"filePath",
"string",
",",
"otherFormParams",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"body",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"writer",
":=",
"multipart",
".",
"NewWriter",
"(",
"body",
")",
"\n",
"// TODO: make this field name configurable",
"part",
",",
"err",
":=",
"writer",
".",
"CreateFormFile",
"(",
"\"",
"\"",
",",
"filepath",
".",
"Base",
"(",
"filePath",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"part",
",",
"file",
")",
"\n\n",
"for",
"key",
",",
"val",
":=",
"range",
"otherFormParams",
"{",
"_",
"=",
"writer",
".",
"WriteField",
"(",
"key",
",",
"val",
")",
"\n",
"}",
"\n",
"err",
"=",
"writer",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"NewRequest",
"(",
"config",
",",
"\"",
"\"",
",",
"uriPath",
",",
"body",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"writer",
".",
"FormDataContentType",
"(",
")",
")",
"\n",
"return",
"req",
",",
"err",
"\n",
"}"
]
| // NewMultiPartFormDataRequest creates an HTTP request that uploads a file to the Akamai API | [
"NewMultiPartFormDataRequest",
"creates",
"an",
"HTTP",
"request",
"that",
"uploads",
"a",
"file",
"to",
"the",
"Akamai",
"API"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/client-v1/client.go#L93-L120 |
146,433 | akamai/AkamaiOPEN-edgegrid-golang | client-v1/client.go | Do | func Do(config edgegrid.Config, req *http.Request) (*http.Response, error) {
Client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
req = edgegrid.AddRequestHeader(config, req)
return nil
}
req = edgegrid.AddRequestHeader(config, req)
res, err := Client.Do(req)
if err != nil {
return nil, err
}
return res, nil
} | go | func Do(config edgegrid.Config, req *http.Request) (*http.Response, error) {
Client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
req = edgegrid.AddRequestHeader(config, req)
return nil
}
req = edgegrid.AddRequestHeader(config, req)
res, err := Client.Do(req)
if err != nil {
return nil, err
}
return res, nil
} | [
"func",
"Do",
"(",
"config",
"edgegrid",
".",
"Config",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"Client",
".",
"CheckRedirect",
"=",
"func",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"via",
"[",
"]",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"req",
"=",
"edgegrid",
".",
"AddRequestHeader",
"(",
"config",
",",
"req",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"req",
"=",
"edgegrid",
".",
"AddRequestHeader",
"(",
"config",
",",
"req",
")",
"\n",
"res",
",",
"err",
":=",
"Client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
]
| // Do performs a given HTTP Request, signed with the Akamai OPEN Edgegrid
// Authorization header. An edgegrid.Response or an error is returned. | [
"Do",
"performs",
"a",
"given",
"HTTP",
"Request",
"signed",
"with",
"the",
"Akamai",
"OPEN",
"Edgegrid",
"Authorization",
"header",
".",
"An",
"edgegrid",
".",
"Response",
"or",
"an",
"error",
"is",
"returned",
"."
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/client-v1/client.go#L124-L137 |
146,434 | akamai/AkamaiOPEN-edgegrid-golang | client-v1/client.go | BodyJSON | func BodyJSON(r *http.Response, data interface{}) error {
if data == nil {
return errors.New("You must pass in an interface{}")
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
err = jsonhooks.Unmarshal(body, data)
return err
} | go | func BodyJSON(r *http.Response, data interface{}) error {
if data == nil {
return errors.New("You must pass in an interface{}")
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
err = jsonhooks.Unmarshal(body, data)
return err
} | [
"func",
"BodyJSON",
"(",
"r",
"*",
"http",
".",
"Response",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"data",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"jsonhooks",
".",
"Unmarshal",
"(",
"body",
",",
"data",
")",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // BodyJSON unmarshals the Response.Body into a given data structure | [
"BodyJSON",
"unmarshals",
"the",
"Response",
".",
"Body",
"into",
"a",
"given",
"data",
"structure"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/client-v1/client.go#L140-L152 |
146,435 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/groups.go | AddGroup | func (groups *Groups) AddGroup(newGroup *Group) {
if newGroup.GroupID != "" {
for key, group := range groups.Groups.Items {
if group.GroupID == newGroup.GroupID {
groups.Groups.Items[key] = newGroup
return
}
}
}
newGroup.parent = groups
groups.Groups.Items = append(groups.Groups.Items, newGroup)
} | go | func (groups *Groups) AddGroup(newGroup *Group) {
if newGroup.GroupID != "" {
for key, group := range groups.Groups.Items {
if group.GroupID == newGroup.GroupID {
groups.Groups.Items[key] = newGroup
return
}
}
}
newGroup.parent = groups
groups.Groups.Items = append(groups.Groups.Items, newGroup)
} | [
"func",
"(",
"groups",
"*",
"Groups",
")",
"AddGroup",
"(",
"newGroup",
"*",
"Group",
")",
"{",
"if",
"newGroup",
".",
"GroupID",
"!=",
"\"",
"\"",
"{",
"for",
"key",
",",
"group",
":=",
"range",
"groups",
".",
"Groups",
".",
"Items",
"{",
"if",
"group",
".",
"GroupID",
"==",
"newGroup",
".",
"GroupID",
"{",
"groups",
".",
"Groups",
".",
"Items",
"[",
"key",
"]",
"=",
"newGroup",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"newGroup",
".",
"parent",
"=",
"groups",
"\n\n",
"groups",
".",
"Groups",
".",
"Items",
"=",
"append",
"(",
"groups",
".",
"Groups",
".",
"Items",
",",
"newGroup",
")",
"\n",
"}"
]
| // AddGroup adds a group to a Groups collection | [
"AddGroup",
"adds",
"a",
"group",
"to",
"a",
"Groups",
"collection"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/groups.go#L74-L87 |
146,436 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/groups.go | FindGroup | func (groups *Groups) FindGroup(id string) (*Group, error) {
var group *Group
var groupFound bool
if id == "" {
goto err
}
for _, group = range groups.Groups.Items {
if group.GroupID == id {
groupFound = true
break
}
}
err:
if !groupFound {
return nil, fmt.Errorf("Unable to find group: \"%s\"", id)
}
return group, nil
} | go | func (groups *Groups) FindGroup(id string) (*Group, error) {
var group *Group
var groupFound bool
if id == "" {
goto err
}
for _, group = range groups.Groups.Items {
if group.GroupID == id {
groupFound = true
break
}
}
err:
if !groupFound {
return nil, fmt.Errorf("Unable to find group: \"%s\"", id)
}
return group, nil
} | [
"func",
"(",
"groups",
"*",
"Groups",
")",
"FindGroup",
"(",
"id",
"string",
")",
"(",
"*",
"Group",
",",
"error",
")",
"{",
"var",
"group",
"*",
"Group",
"\n",
"var",
"groupFound",
"bool",
"\n\n",
"if",
"id",
"==",
"\"",
"\"",
"{",
"goto",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"group",
"=",
"range",
"groups",
".",
"Groups",
".",
"Items",
"{",
"if",
"group",
".",
"GroupID",
"==",
"id",
"{",
"groupFound",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
":",
"if",
"!",
"groupFound",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n\n",
"return",
"group",
",",
"nil",
"\n",
"}"
]
| // FindGroup finds a specific group by ID | [
"FindGroup",
"finds",
"a",
"specific",
"group",
"by",
"ID"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/groups.go#L90-L111 |
146,437 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/groups.go | NewGroup | func NewGroup(parent *Groups) *Group {
group := &Group{
parent: parent,
}
group.Init()
return group
} | go | func NewGroup(parent *Groups) *Group {
group := &Group{
parent: parent,
}
group.Init()
return group
} | [
"func",
"NewGroup",
"(",
"parent",
"*",
"Groups",
")",
"*",
"Group",
"{",
"group",
":=",
"&",
"Group",
"{",
"parent",
":",
"parent",
",",
"}",
"\n",
"group",
".",
"Init",
"(",
")",
"\n",
"return",
"group",
"\n",
"}"
]
| // NewGroup creates a new Group | [
"NewGroup",
"creates",
"a",
"new",
"Group"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/groups.go#L124-L130 |
146,438 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/groups.go | GetGroup | func (group *Group) GetGroup() {
groups, err := GetGroups()
if err != nil {
return
}
for _, g := range groups.Groups.Items {
if g.GroupID == group.GroupID {
group.parent = groups
group.ContractIDs = g.ContractIDs
group.GroupName = g.GroupName
group.ParentGroupID = g.ParentGroupID
group.Complete <- true
return
}
}
group.Complete <- false
} | go | func (group *Group) GetGroup() {
groups, err := GetGroups()
if err != nil {
return
}
for _, g := range groups.Groups.Items {
if g.GroupID == group.GroupID {
group.parent = groups
group.ContractIDs = g.ContractIDs
group.GroupName = g.GroupName
group.ParentGroupID = g.ParentGroupID
group.Complete <- true
return
}
}
group.Complete <- false
} | [
"func",
"(",
"group",
"*",
"Group",
")",
"GetGroup",
"(",
")",
"{",
"groups",
",",
"err",
":=",
"GetGroups",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"g",
":=",
"range",
"groups",
".",
"Groups",
".",
"Items",
"{",
"if",
"g",
".",
"GroupID",
"==",
"group",
".",
"GroupID",
"{",
"group",
".",
"parent",
"=",
"groups",
"\n",
"group",
".",
"ContractIDs",
"=",
"g",
".",
"ContractIDs",
"\n",
"group",
".",
"GroupName",
"=",
"g",
".",
"GroupName",
"\n",
"group",
".",
"ParentGroupID",
"=",
"g",
".",
"ParentGroupID",
"\n",
"group",
".",
"Complete",
"<-",
"true",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"group",
".",
"Complete",
"<-",
"false",
"\n",
"}"
]
| // GetGroup populates a Group | [
"GetGroup",
"populates",
"a",
"Group"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/groups.go#L133-L151 |
146,439 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/groups.go | GetProperties | func (group *Group) GetProperties(contract *Contract) (*Properties, error) {
return GetProperties(contract, group)
} | go | func (group *Group) GetProperties(contract *Contract) (*Properties, error) {
return GetProperties(contract, group)
} | [
"func",
"(",
"group",
"*",
"Group",
")",
"GetProperties",
"(",
"contract",
"*",
"Contract",
")",
"(",
"*",
"Properties",
",",
"error",
")",
"{",
"return",
"GetProperties",
"(",
"contract",
",",
"group",
")",
"\n",
"}"
]
| // GetProperties retrieves all properties associated with a given group and contract | [
"GetProperties",
"retrieves",
"all",
"properties",
"associated",
"with",
"a",
"given",
"group",
"and",
"contract"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/groups.go#L154-L156 |
146,440 | akamai/AkamaiOPEN-edgegrid-golang | papi-v1/groups.go | GetCpCodes | func (group *Group) GetCpCodes(contract *Contract) (*CpCodes, error) {
return GetCpCodes(contract, group)
} | go | func (group *Group) GetCpCodes(contract *Contract) (*CpCodes, error) {
return GetCpCodes(contract, group)
} | [
"func",
"(",
"group",
"*",
"Group",
")",
"GetCpCodes",
"(",
"contract",
"*",
"Contract",
")",
"(",
"*",
"CpCodes",
",",
"error",
")",
"{",
"return",
"GetCpCodes",
"(",
"contract",
",",
"group",
")",
"\n",
"}"
]
| // GetCpCodes retrieves all CP codes associated with a given group and contract | [
"GetCpCodes",
"retrieves",
"all",
"CP",
"codes",
"associated",
"with",
"a",
"given",
"group",
"and",
"contract"
]
| 009960c8b2c7c57a0c5c488a3c8c778c16f3f586 | https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/groups.go#L159-L161 |
146,441 | giantswarm/mayu | client/client.go | New | func New(scheme, host string, port uint16) (*Client, error) {
client := &Client{
Scheme: scheme,
Host: host,
Port: port,
}
return client, nil
} | go | func New(scheme, host string, port uint16) (*Client, error) {
client := &Client{
Scheme: scheme,
Host: host,
Port: port,
}
return client, nil
} | [
"func",
"New",
"(",
"scheme",
",",
"host",
"string",
",",
"port",
"uint16",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"client",
":=",
"&",
"Client",
"{",
"Scheme",
":",
"scheme",
",",
"Host",
":",
"host",
",",
"Port",
":",
"port",
",",
"}",
"\n\n",
"return",
"client",
",",
"nil",
"\n",
"}"
]
| // New creates a new configured client to interact with mayu over its network
// API. | [
"New",
"creates",
"a",
"new",
"configured",
"client",
"to",
"interact",
"with",
"mayu",
"over",
"its",
"network",
"API",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/client/client.go#L33-L41 |
146,442 | giantswarm/mayu | client/client.go | SetProviderId | func (c *Client) SetProviderId(serial, value string) error {
data, err := json.Marshal(hostmgr.Host{
ProviderId: value,
})
if err != nil {
return microerror.Mask(err)
}
resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/set_provider_id", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
if err != nil {
return microerror.Mask(err)
}
defer resp.Body.Close()
if resp.StatusCode > 399 {
return microerror.Mask(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}
return nil
} | go | func (c *Client) SetProviderId(serial, value string) error {
data, err := json.Marshal(hostmgr.Host{
ProviderId: value,
})
if err != nil {
return microerror.Mask(err)
}
resp, err := httputil.Put(fmt.Sprintf("%s://%s:%d/admin/host/%s/set_provider_id", c.Scheme, c.Host, c.Port, serial), contentType, bytes.NewBuffer(data))
if err != nil {
return microerror.Mask(err)
}
defer resp.Body.Close()
if resp.StatusCode > 399 {
return microerror.Mask(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetProviderId",
"(",
"serial",
",",
"value",
"string",
")",
"error",
"{",
"data",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"hostmgr",
".",
"Host",
"{",
"ProviderId",
":",
"value",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"httputil",
".",
"Put",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Scheme",
",",
"c",
".",
"Host",
",",
"c",
".",
"Port",
",",
"serial",
")",
",",
"contentType",
",",
"bytes",
".",
"NewBuffer",
"(",
"data",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
">",
"399",
"{",
"return",
"microerror",
".",
"Mask",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // SetProviderId sets the provider ID given by value for a node given by serial. | [
"SetProviderId",
"sets",
"the",
"provider",
"ID",
"given",
"by",
"value",
"for",
"a",
"node",
"given",
"by",
"serial",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/client/client.go#L59-L78 |
146,443 | giantswarm/mayu | client/client.go | List | func (c *Client) List() ([]hostmgr.Host, error) {
list := []hostmgr.Host{}
resp, err := http.Get(fmt.Sprintf("%s://%s:%d/admin/hosts", c.Scheme, c.Host, c.Port))
if err != nil {
return list, microerror.Mask(err)
}
defer resp.Body.Close()
if resp.StatusCode > 399 {
return nil, microerror.Mask(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return list, microerror.Mask(err)
}
err = json.Unmarshal(body, &list)
if err != nil {
return list, microerror.Mask(err)
}
return list, nil
} | go | func (c *Client) List() ([]hostmgr.Host, error) {
list := []hostmgr.Host{}
resp, err := http.Get(fmt.Sprintf("%s://%s:%d/admin/hosts", c.Scheme, c.Host, c.Port))
if err != nil {
return list, microerror.Mask(err)
}
defer resp.Body.Close()
if resp.StatusCode > 399 {
return nil, microerror.Mask(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return list, microerror.Mask(err)
}
err = json.Unmarshal(body, &list)
if err != nil {
return list, microerror.Mask(err)
}
return list, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"List",
"(",
")",
"(",
"[",
"]",
"hostmgr",
".",
"Host",
",",
"error",
")",
"{",
"list",
":=",
"[",
"]",
"hostmgr",
".",
"Host",
"{",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Scheme",
",",
"c",
".",
"Host",
",",
"c",
".",
"Port",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"list",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
">",
"399",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
")",
"\n",
"}",
"\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"list",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"list",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"list",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"list",
",",
"nil",
"\n",
"}"
]
| // List fetches a list of node information within the current cluster. | [
"List",
"fetches",
"a",
"list",
"of",
"node",
"information",
"within",
"the",
"current",
"cluster",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/client/client.go#L174-L197 |
146,444 | giantswarm/mayu | client/client.go | Status | func (c *Client) Status(serial string) (hostmgr.Host, error) {
var host hostmgr.Host
resp, err := http.Get(fmt.Sprintf("%s://%s:%d/admin/hosts", c.Scheme, c.Host, c.Port))
if err != nil {
return host, microerror.Mask(err)
}
defer resp.Body.Close()
if resp.StatusCode > 399 {
return host, microerror.Mask(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return host, microerror.Mask(err)
}
list := []hostmgr.Host{}
err = json.Unmarshal(body, &list)
if err != nil {
return host, microerror.Mask(err)
}
for _, host = range list {
if host.Serial == serial {
return host, nil
}
}
return host, microerror.Mask(fmt.Errorf("host %s not found", serial))
} | go | func (c *Client) Status(serial string) (hostmgr.Host, error) {
var host hostmgr.Host
resp, err := http.Get(fmt.Sprintf("%s://%s:%d/admin/hosts", c.Scheme, c.Host, c.Port))
if err != nil {
return host, microerror.Mask(err)
}
defer resp.Body.Close()
if resp.StatusCode > 399 {
return host, microerror.Mask(fmt.Errorf("invalid status code '%d'", resp.StatusCode))
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return host, microerror.Mask(err)
}
list := []hostmgr.Host{}
err = json.Unmarshal(body, &list)
if err != nil {
return host, microerror.Mask(err)
}
for _, host = range list {
if host.Serial == serial {
return host, nil
}
}
return host, microerror.Mask(fmt.Errorf("host %s not found", serial))
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Status",
"(",
"serial",
"string",
")",
"(",
"hostmgr",
".",
"Host",
",",
"error",
")",
"{",
"var",
"host",
"hostmgr",
".",
"Host",
"\n\n",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Scheme",
",",
"c",
".",
"Host",
",",
"c",
".",
"Port",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"host",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
">",
"399",
"{",
"return",
"host",
",",
"microerror",
".",
"Mask",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
")",
"\n",
"}",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"host",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"list",
":=",
"[",
"]",
"hostmgr",
".",
"Host",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"list",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"host",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"host",
"=",
"range",
"list",
"{",
"if",
"host",
".",
"Serial",
"==",
"serial",
"{",
"return",
"host",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"host",
",",
"microerror",
".",
"Mask",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"serial",
")",
")",
"\n",
"}"
]
| // Status fetches status information for a node given by serial. | [
"Status",
"fetches",
"status",
"information",
"for",
"a",
"node",
"given",
"by",
"serial",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/client/client.go#L200-L230 |
146,445 | giantswarm/mayu | pxemgr/iputil.go | ipLessThanOrEqual | func ipLessThanOrEqual(ip net.IP, upperBound net.IP) bool {
if ip[3] < upperBound[3] {
return true
}
if ip[2] < upperBound[2] {
return true
}
if ip[1] < upperBound[1] {
return true
}
if ip[0] <= upperBound[0] {
return true
}
return false
} | go | func ipLessThanOrEqual(ip net.IP, upperBound net.IP) bool {
if ip[3] < upperBound[3] {
return true
}
if ip[2] < upperBound[2] {
return true
}
if ip[1] < upperBound[1] {
return true
}
if ip[0] <= upperBound[0] {
return true
}
return false
} | [
"func",
"ipLessThanOrEqual",
"(",
"ip",
"net",
".",
"IP",
",",
"upperBound",
"net",
".",
"IP",
")",
"bool",
"{",
"if",
"ip",
"[",
"3",
"]",
"<",
"upperBound",
"[",
"3",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"ip",
"[",
"2",
"]",
"<",
"upperBound",
"[",
"2",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"ip",
"[",
"1",
"]",
"<",
"upperBound",
"[",
"1",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"ip",
"[",
"0",
"]",
"<=",
"upperBound",
"[",
"0",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
]
| // ip less or equal | [
"ip",
"less",
"or",
"equal"
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/pxemgr/iputil.go#L18-L33 |
146,446 | giantswarm/mayu | fs/fake.go | NewFakeFilesystemWithFiles | func NewFakeFilesystemWithFiles(fs []FakeFile) FakeFilesystem {
fileMap := make(map[string]FakeFile)
for _, f := range fs {
fileMap[f.Name] = f
}
return FakeFilesystem{files: fileMap}
} | go | func NewFakeFilesystemWithFiles(fs []FakeFile) FakeFilesystem {
fileMap := make(map[string]FakeFile)
for _, f := range fs {
fileMap[f.Name] = f
}
return FakeFilesystem{files: fileMap}
} | [
"func",
"NewFakeFilesystemWithFiles",
"(",
"fs",
"[",
"]",
"FakeFile",
")",
"FakeFilesystem",
"{",
"fileMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"FakeFile",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"fs",
"{",
"fileMap",
"[",
"f",
".",
"Name",
"]",
"=",
"f",
"\n",
"}",
"\n\n",
"return",
"FakeFilesystem",
"{",
"files",
":",
"fileMap",
"}",
"\n",
"}"
]
| // NewFakeFilesystemWithFiles creates a new FakeFilesystem
// instance bundled with a list of FakeFile instances that
// can be passed. | [
"NewFakeFilesystemWithFiles",
"creates",
"a",
"new",
"FakeFilesystem",
"instance",
"bundled",
"with",
"a",
"list",
"of",
"FakeFile",
"instances",
"that",
"can",
"be",
"passed",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/fs/fake.go#L25-L32 |
146,447 | giantswarm/mayu | fs/fake.go | NewFakeFile | func NewFakeFile(name, content string) FakeFile {
return FakeFile{
Name: name,
Mode: os.FileMode(0777),
ModTime: time.Now(),
Buffer: bytes.NewReader([]byte(content)),
}
} | go | func NewFakeFile(name, content string) FakeFile {
return FakeFile{
Name: name,
Mode: os.FileMode(0777),
ModTime: time.Now(),
Buffer: bytes.NewReader([]byte(content)),
}
} | [
"func",
"NewFakeFile",
"(",
"name",
",",
"content",
"string",
")",
"FakeFile",
"{",
"return",
"FakeFile",
"{",
"Name",
":",
"name",
",",
"Mode",
":",
"os",
".",
"FileMode",
"(",
"0777",
")",
",",
"ModTime",
":",
"time",
".",
"Now",
"(",
")",
",",
"Buffer",
":",
"bytes",
".",
"NewReader",
"(",
"[",
"]",
"byte",
"(",
"content",
")",
")",
",",
"}",
"\n",
"}"
]
| // NewFakeFile creates a new FakeFile instances based on a file name
// and it's contents from strings. The content of the new instance will
// be stored in an internal bytes.Reader instance. The default file mode
// will be 0777 and the last modification time the moment when the
// function is called. | [
"NewFakeFile",
"creates",
"a",
"new",
"FakeFile",
"instances",
"based",
"on",
"a",
"file",
"name",
"and",
"it",
"s",
"contents",
"from",
"strings",
".",
"The",
"content",
"of",
"the",
"new",
"instance",
"will",
"be",
"stored",
"in",
"an",
"internal",
"bytes",
".",
"Reader",
"instance",
".",
"The",
"default",
"file",
"mode",
"will",
"be",
"0777",
"and",
"the",
"last",
"modification",
"time",
"the",
"moment",
"when",
"the",
"function",
"is",
"called",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/fs/fake.go#L75-L82 |
146,448 | giantswarm/mayu | fs/fake.go | Read | func (f FakeFile) Read(p []byte) (n int, err error) {
return f.Buffer.Read(p)
} | go | func (f FakeFile) Read(p []byte) (n int, err error) {
return f.Buffer.Read(p)
} | [
"func",
"(",
"f",
"FakeFile",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"f",
".",
"Buffer",
".",
"Read",
"(",
"p",
")",
"\n",
"}"
]
| // Read wraps io.Reader's functionality around the internal
// bytes.Reader instance. | [
"Read",
"wraps",
"io",
".",
"Reader",
"s",
"functionality",
"around",
"the",
"internal",
"bytes",
".",
"Reader",
"instance",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/fs/fake.go#L91-L93 |
146,449 | giantswarm/mayu | fs/fake.go | ReadAt | func (f FakeFile) ReadAt(p []byte, off int64) (n int, err error) {
return f.Buffer.ReadAt(p, off)
} | go | func (f FakeFile) ReadAt(p []byte, off int64) (n int, err error) {
return f.Buffer.ReadAt(p, off)
} | [
"func",
"(",
"f",
"FakeFile",
")",
"ReadAt",
"(",
"p",
"[",
"]",
"byte",
",",
"off",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"f",
".",
"Buffer",
".",
"ReadAt",
"(",
"p",
",",
"off",
")",
"\n",
"}"
]
| // ReadAt wraps io.ReaderAt's functionality around the internalt
// bytes.Reader instance. | [
"ReadAt",
"wraps",
"io",
".",
"ReaderAt",
"s",
"functionality",
"around",
"the",
"internalt",
"bytes",
".",
"Reader",
"instance",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/fs/fake.go#L97-L99 |
146,450 | giantswarm/mayu | fs/fake.go | Seek | func (f FakeFile) Seek(offset int64, whence int) (int64, error) {
return f.Buffer.Seek(offset, whence)
} | go | func (f FakeFile) Seek(offset int64, whence int) (int64, error) {
return f.Buffer.Seek(offset, whence)
} | [
"func",
"(",
"f",
"FakeFile",
")",
"Seek",
"(",
"offset",
"int64",
",",
"whence",
"int",
")",
"(",
"int64",
",",
"error",
")",
"{",
"return",
"f",
".",
"Buffer",
".",
"Seek",
"(",
"offset",
",",
"whence",
")",
"\n",
"}"
]
| // Seek wraps io.Seeker's functionality around the internalt
// bytes.Reader instance. | [
"Seek",
"wraps",
"io",
".",
"Seeker",
"s",
"functionality",
"around",
"the",
"internalt",
"bytes",
".",
"Reader",
"instance",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/fs/fake.go#L103-L105 |
146,451 | giantswarm/mayu | fs/fake.go | Stat | func (f FakeFile) Stat() (os.FileInfo, error) {
return FakeFileInfo{File: f}, nil
} | go | func (f FakeFile) Stat() (os.FileInfo, error) {
return FakeFileInfo{File: f}, nil
} | [
"func",
"(",
"f",
"FakeFile",
")",
"Stat",
"(",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"return",
"FakeFileInfo",
"{",
"File",
":",
"f",
"}",
",",
"nil",
"\n",
"}"
]
| // Stat returns the FakeFileInfo structure describing the FakeFile
// instance. | [
"Stat",
"returns",
"the",
"FakeFileInfo",
"structure",
"describing",
"the",
"FakeFile",
"instance",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/fs/fake.go#L109-L111 |
146,452 | giantswarm/mayu | flag.go | ValidateHTTPCertificateUsage | func (g MayuFlags) ValidateHTTPCertificateUsage() (bool, error) {
if g.noTLS {
return true, nil
}
if !g.noTLS && g.tlsCertFile != "" && g.tlsKeyFile != "" {
return true, nil
}
return false, ErrNotAllCertFilesProvided
} | go | func (g MayuFlags) ValidateHTTPCertificateUsage() (bool, error) {
if g.noTLS {
return true, nil
}
if !g.noTLS && g.tlsCertFile != "" && g.tlsKeyFile != "" {
return true, nil
}
return false, ErrNotAllCertFilesProvided
} | [
"func",
"(",
"g",
"MayuFlags",
")",
"ValidateHTTPCertificateUsage",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"g",
".",
"noTLS",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"!",
"g",
".",
"noTLS",
"&&",
"g",
".",
"tlsCertFile",
"!=",
"\"",
"\"",
"&&",
"g",
".",
"tlsKeyFile",
"!=",
"\"",
"\"",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"false",
",",
"ErrNotAllCertFilesProvided",
"\n",
"}"
]
| // ValidateHTTPCertificateUsage checks if the fields HTTPSCertFile and HTTPSKeyFile
// of the configuration struct are set whenever the NoTLS is set to false.
// This makes sure that users are configuring the needed certificate files when
// using TLS encrypted connections. | [
"ValidateHTTPCertificateUsage",
"checks",
"if",
"the",
"fields",
"HTTPSCertFile",
"and",
"HTTPSKeyFile",
"of",
"the",
"configuration",
"struct",
"are",
"set",
"whenever",
"the",
"NoTLS",
"is",
"set",
"to",
"false",
".",
"This",
"makes",
"sure",
"that",
"users",
"are",
"configuring",
"the",
"needed",
"certificate",
"files",
"when",
"using",
"TLS",
"encrypted",
"connections",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/flag.go#L96-L106 |
146,453 | giantswarm/mayu | flag.go | ValidateHTTPCertificateFileExistance | func (g MayuFlags) ValidateHTTPCertificateFileExistance() (bool, error) {
if g.noTLS {
return true, nil
}
if _, err := g.filesystem.Stat(g.tlsCertFile); err != nil {
return false, ErrHTTPSCertFileNotRedable
}
if _, err := g.filesystem.Stat(g.tlsKeyFile); err != nil {
return false, ErrHTTPSKeyFileNotReadable
}
return true, nil
} | go | func (g MayuFlags) ValidateHTTPCertificateFileExistance() (bool, error) {
if g.noTLS {
return true, nil
}
if _, err := g.filesystem.Stat(g.tlsCertFile); err != nil {
return false, ErrHTTPSCertFileNotRedable
}
if _, err := g.filesystem.Stat(g.tlsKeyFile); err != nil {
return false, ErrHTTPSKeyFileNotReadable
}
return true, nil
} | [
"func",
"(",
"g",
"MayuFlags",
")",
"ValidateHTTPCertificateFileExistance",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"g",
".",
"noTLS",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"g",
".",
"filesystem",
".",
"Stat",
"(",
"g",
".",
"tlsCertFile",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"ErrHTTPSCertFileNotRedable",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"g",
".",
"filesystem",
".",
"Stat",
"(",
"g",
".",
"tlsKeyFile",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"ErrHTTPSKeyFileNotReadable",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
]
| // ValidateHTTPCertificateFileExistance checks if the filenames configured
// in the fields HTTPSCertFile and HTTPSKeyFile can be stat'ed to make sure
// they actually exist. | [
"ValidateHTTPCertificateFileExistance",
"checks",
"if",
"the",
"filenames",
"configured",
"in",
"the",
"fields",
"HTTPSCertFile",
"and",
"HTTPSKeyFile",
"can",
"be",
"stat",
"ed",
"to",
"make",
"sure",
"they",
"actually",
"exist",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/flag.go#L111-L125 |
146,454 | giantswarm/mayu | hostmgr/host.go | Commit | func (h *Host) Commit(msg string) error {
h.save()
return h.maybeGitCommit(h.Serial + ": " + msg)
} | go | func (h *Host) Commit(msg string) error {
h.save()
return h.maybeGitCommit(h.Serial + ": " + msg)
} | [
"func",
"(",
"h",
"*",
"Host",
")",
"Commit",
"(",
"msg",
"string",
")",
"error",
"{",
"h",
".",
"save",
"(",
")",
"\n",
"return",
"h",
".",
"maybeGitCommit",
"(",
"h",
".",
"Serial",
"+",
"\"",
"\"",
"+",
"msg",
")",
"\n",
"}"
]
| // Commit stores the given msg in git version control. | [
"Commit",
"stores",
"the",
"given",
"msg",
"in",
"git",
"version",
"control",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/host.go#L51-L54 |
146,455 | giantswarm/mayu | hostmgr/host.go | HostFromDir | func HostFromDir(hostdir string) (*Host, error) {
confPath := path.Join(hostdir, hostConfFile)
h := &Host{}
err := loadJson(h, confPath)
if err != nil {
return nil, microerror.Mask(err)
}
h.hostDir, err = os.Open(hostdir)
if err != nil {
return nil, microerror.Mask(err)
}
fi, err := os.Stat(confPath)
if err != nil {
return nil, microerror.Mask(err)
}
h.lastModTime = fi.ModTime()
return h, nil
} | go | func HostFromDir(hostdir string) (*Host, error) {
confPath := path.Join(hostdir, hostConfFile)
h := &Host{}
err := loadJson(h, confPath)
if err != nil {
return nil, microerror.Mask(err)
}
h.hostDir, err = os.Open(hostdir)
if err != nil {
return nil, microerror.Mask(err)
}
fi, err := os.Stat(confPath)
if err != nil {
return nil, microerror.Mask(err)
}
h.lastModTime = fi.ModTime()
return h, nil
} | [
"func",
"HostFromDir",
"(",
"hostdir",
"string",
")",
"(",
"*",
"Host",
",",
"error",
")",
"{",
"confPath",
":=",
"path",
".",
"Join",
"(",
"hostdir",
",",
"hostConfFile",
")",
"\n\n",
"h",
":=",
"&",
"Host",
"{",
"}",
"\n",
"err",
":=",
"loadJson",
"(",
"h",
",",
"confPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"h",
".",
"hostDir",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"hostdir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"confPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"h",
".",
"lastModTime",
"=",
"fi",
".",
"ModTime",
"(",
")",
"\n\n",
"return",
"h",
",",
"nil",
"\n",
"}"
]
| // HostFromDir takes a path to a host directory within the cluster directory
// and loads the found configuration. Then the corresponding Host is returned. | [
"HostFromDir",
"takes",
"a",
"path",
"to",
"a",
"host",
"directory",
"within",
"the",
"cluster",
"directory",
"and",
"loads",
"the",
"found",
"configuration",
".",
"Then",
"the",
"corresponding",
"Host",
"is",
"returned",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/host.go#L67-L88 |
146,456 | giantswarm/mayu | pxemgr/ignition.go | hasUnrecognizedKeys | func hasUnrecognizedKeys(inCfg interface{}, refType reflect.Type) (warnings bool) {
if refType.Kind() == reflect.Ptr {
refType = refType.Elem()
}
switch inCfg.(type) {
case map[interface{}]interface{}:
ks := inCfg.(map[interface{}]interface{})
keys:
for key := range ks {
for i := 0; i < refType.NumField(); i++ {
sf := refType.Field(i)
tv := sf.Tag.Get("yaml")
if tv == key {
if warn := hasUnrecognizedKeys(ks[key], sf.Type); warn {
warnings = true
}
continue keys
}
}
fmt.Printf("Unrecognized keyword: %v", key)
warnings = true
}
case []interface{}:
ks := inCfg.([]interface{})
for i := range ks {
if warn := hasUnrecognizedKeys(ks[i], refType.Elem()); warn {
warnings = true
}
}
default:
}
return
} | go | func hasUnrecognizedKeys(inCfg interface{}, refType reflect.Type) (warnings bool) {
if refType.Kind() == reflect.Ptr {
refType = refType.Elem()
}
switch inCfg.(type) {
case map[interface{}]interface{}:
ks := inCfg.(map[interface{}]interface{})
keys:
for key := range ks {
for i := 0; i < refType.NumField(); i++ {
sf := refType.Field(i)
tv := sf.Tag.Get("yaml")
if tv == key {
if warn := hasUnrecognizedKeys(ks[key], sf.Type); warn {
warnings = true
}
continue keys
}
}
fmt.Printf("Unrecognized keyword: %v", key)
warnings = true
}
case []interface{}:
ks := inCfg.([]interface{})
for i := range ks {
if warn := hasUnrecognizedKeys(ks[i], refType.Elem()); warn {
warnings = true
}
}
default:
}
return
} | [
"func",
"hasUnrecognizedKeys",
"(",
"inCfg",
"interface",
"{",
"}",
",",
"refType",
"reflect",
".",
"Type",
")",
"(",
"warnings",
"bool",
")",
"{",
"if",
"refType",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"refType",
"=",
"refType",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"switch",
"inCfg",
".",
"(",
"type",
")",
"{",
"case",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
":",
"ks",
":=",
"inCfg",
".",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"keys",
":",
"for",
"key",
":=",
"range",
"ks",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"refType",
".",
"NumField",
"(",
")",
";",
"i",
"++",
"{",
"sf",
":=",
"refType",
".",
"Field",
"(",
"i",
")",
"\n",
"tv",
":=",
"sf",
".",
"Tag",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"tv",
"==",
"key",
"{",
"if",
"warn",
":=",
"hasUnrecognizedKeys",
"(",
"ks",
"[",
"key",
"]",
",",
"sf",
".",
"Type",
")",
";",
"warn",
"{",
"warnings",
"=",
"true",
"\n",
"}",
"\n",
"continue",
"keys",
"\n",
"}",
"\n",
"}",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"warnings",
"=",
"true",
"\n",
"}",
"\n",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"ks",
":=",
"inCfg",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"i",
":=",
"range",
"ks",
"{",
"if",
"warn",
":=",
"hasUnrecognizedKeys",
"(",
"ks",
"[",
"i",
"]",
",",
"refType",
".",
"Elem",
"(",
")",
")",
";",
"warn",
"{",
"warnings",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"default",
":",
"}",
"\n",
"return",
"\n",
"}"
]
| // hasUnrecognizedKeys finds unrecognized keys and warns about them on stderr.
// returns false when no unrecognized keys were found, true otherwise. | [
"hasUnrecognizedKeys",
"finds",
"unrecognized",
"keys",
"and",
"warns",
"about",
"them",
"on",
"stderr",
".",
"returns",
"false",
"when",
"no",
"unrecognized",
"keys",
"were",
"found",
"true",
"otherwise",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/pxemgr/ignition.go#L142-L175 |
146,457 | giantswarm/mayu | hostmgr/cluster.go | NewCluster | func NewCluster(baseDir string, gitStore bool, logger micrologger.Logger) (*Cluster, error) {
if !fileExists(baseDir) {
err := os.Mkdir(baseDir, 0755)
if err != nil {
return nil, microerror.Mask(err)
}
}
if gitStore && !isGitRepo(baseDir) {
err := gitInit(baseDir)
if err != nil {
return nil, microerror.Mask(err)
}
}
c := &Cluster{
baseDir: baseDir,
GitStore: gitStore,
mu: new(sync.Mutex),
Config: ClusterConfig{},
predefinedVals: map[string]map[string]string{},
hostsCache: map[string]*cachedHost{},
logger: logger,
}
err := c.Commit("initial commit")
if err != nil {
return nil, microerror.Mask(err)
}
return c, nil
} | go | func NewCluster(baseDir string, gitStore bool, logger micrologger.Logger) (*Cluster, error) {
if !fileExists(baseDir) {
err := os.Mkdir(baseDir, 0755)
if err != nil {
return nil, microerror.Mask(err)
}
}
if gitStore && !isGitRepo(baseDir) {
err := gitInit(baseDir)
if err != nil {
return nil, microerror.Mask(err)
}
}
c := &Cluster{
baseDir: baseDir,
GitStore: gitStore,
mu: new(sync.Mutex),
Config: ClusterConfig{},
predefinedVals: map[string]map[string]string{},
hostsCache: map[string]*cachedHost{},
logger: logger,
}
err := c.Commit("initial commit")
if err != nil {
return nil, microerror.Mask(err)
}
return c, nil
} | [
"func",
"NewCluster",
"(",
"baseDir",
"string",
",",
"gitStore",
"bool",
",",
"logger",
"micrologger",
".",
"Logger",
")",
"(",
"*",
"Cluster",
",",
"error",
")",
"{",
"if",
"!",
"fileExists",
"(",
"baseDir",
")",
"{",
"err",
":=",
"os",
".",
"Mkdir",
"(",
"baseDir",
",",
"0755",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"gitStore",
"&&",
"!",
"isGitRepo",
"(",
"baseDir",
")",
"{",
"err",
":=",
"gitInit",
"(",
"baseDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
":=",
"&",
"Cluster",
"{",
"baseDir",
":",
"baseDir",
",",
"GitStore",
":",
"gitStore",
",",
"mu",
":",
"new",
"(",
"sync",
".",
"Mutex",
")",
",",
"Config",
":",
"ClusterConfig",
"{",
"}",
",",
"predefinedVals",
":",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"hostsCache",
":",
"map",
"[",
"string",
"]",
"*",
"cachedHost",
"{",
"}",
",",
"logger",
":",
"logger",
",",
"}",
"\n\n",
"err",
":=",
"c",
".",
"Commit",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
]
| // NewCluster creates a new cluster based on the cluster directory. gitStore
// defines whether cluster changes should be tracked using version control or
// not. | [
"NewCluster",
"creates",
"a",
"new",
"cluster",
"based",
"on",
"the",
"cluster",
"directory",
".",
"gitStore",
"defines",
"whether",
"cluster",
"changes",
"should",
"be",
"tracked",
"using",
"version",
"control",
"or",
"not",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/cluster.go#L78-L108 |
146,458 | giantswarm/mayu | hostmgr/cluster.go | CreateNewHost | func (c *Cluster) CreateNewHost(serial string) (*Host, error) {
serial = strings.ToLower(serial)
hostDir := path.Join(c.baseDir, strings.ToLower(serial))
newHost, err := createHost(serial, hostDir)
if err != nil {
return nil, microerror.Mask(err)
}
if predef, exists := c.predefinedVals[serial]; exists {
c.logger.Log("level", "info", "message", fmt.Sprintf("found predefined values for '%s'", serial))
if s, exists := predef["ipmiaddr"]; exists {
newHost.IPMIAddr = net.ParseIP(s)
c.logger.Log("level", "info", "message", fmt.Sprintf("setting IPMIAdddress for '%s': %s", serial, newHost.IPMIAddr.String()))
}
if s, exists := predef["internaladdr"]; exists {
newHost.InternalAddr = net.ParseIP(s)
c.logger.Log("level", "info", "message", fmt.Sprintf("setting internal address for '%s': %s", serial, newHost.InternalAddr.String()))
newHost.Hostname = strings.Replace(newHost.InternalAddr.String(), ".", "-", 4)
}
if s, exists := predef["etcdclustertoken"]; exists {
newHost.EtcdClusterToken = s
}
} else {
c.logger.Log("level", "info", "message", fmt.Sprintf("no predefined values for '%s'", serial))
}
machineID := genMachineID()
newHost.MachineID = machineID
if newHost.InternalAddr != nil {
newHost.Hostname = strings.Replace(newHost.InternalAddr.String(), ".", "-", 4)
}
c.logger.Log("level", "info", "message", fmt.Sprintf("hostname for '%s' is %s", newHost.InternalAddr.String(), newHost.Hostname))
newHost.Commit("updated with predefined settings")
err = c.reindex()
if err != nil {
return nil, microerror.Mask(err)
}
return newHost, nil
} | go | func (c *Cluster) CreateNewHost(serial string) (*Host, error) {
serial = strings.ToLower(serial)
hostDir := path.Join(c.baseDir, strings.ToLower(serial))
newHost, err := createHost(serial, hostDir)
if err != nil {
return nil, microerror.Mask(err)
}
if predef, exists := c.predefinedVals[serial]; exists {
c.logger.Log("level", "info", "message", fmt.Sprintf("found predefined values for '%s'", serial))
if s, exists := predef["ipmiaddr"]; exists {
newHost.IPMIAddr = net.ParseIP(s)
c.logger.Log("level", "info", "message", fmt.Sprintf("setting IPMIAdddress for '%s': %s", serial, newHost.IPMIAddr.String()))
}
if s, exists := predef["internaladdr"]; exists {
newHost.InternalAddr = net.ParseIP(s)
c.logger.Log("level", "info", "message", fmt.Sprintf("setting internal address for '%s': %s", serial, newHost.InternalAddr.String()))
newHost.Hostname = strings.Replace(newHost.InternalAddr.String(), ".", "-", 4)
}
if s, exists := predef["etcdclustertoken"]; exists {
newHost.EtcdClusterToken = s
}
} else {
c.logger.Log("level", "info", "message", fmt.Sprintf("no predefined values for '%s'", serial))
}
machineID := genMachineID()
newHost.MachineID = machineID
if newHost.InternalAddr != nil {
newHost.Hostname = strings.Replace(newHost.InternalAddr.String(), ".", "-", 4)
}
c.logger.Log("level", "info", "message", fmt.Sprintf("hostname for '%s' is %s", newHost.InternalAddr.String(), newHost.Hostname))
newHost.Commit("updated with predefined settings")
err = c.reindex()
if err != nil {
return nil, microerror.Mask(err)
}
return newHost, nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"CreateNewHost",
"(",
"serial",
"string",
")",
"(",
"*",
"Host",
",",
"error",
")",
"{",
"serial",
"=",
"strings",
".",
"ToLower",
"(",
"serial",
")",
"\n",
"hostDir",
":=",
"path",
".",
"Join",
"(",
"c",
".",
"baseDir",
",",
"strings",
".",
"ToLower",
"(",
"serial",
")",
")",
"\n",
"newHost",
",",
"err",
":=",
"createHost",
"(",
"serial",
",",
"hostDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"predef",
",",
"exists",
":=",
"c",
".",
"predefinedVals",
"[",
"serial",
"]",
";",
"exists",
"{",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"serial",
")",
")",
"\n\n",
"if",
"s",
",",
"exists",
":=",
"predef",
"[",
"\"",
"\"",
"]",
";",
"exists",
"{",
"newHost",
".",
"IPMIAddr",
"=",
"net",
".",
"ParseIP",
"(",
"s",
")",
"\n",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"serial",
",",
"newHost",
".",
"IPMIAddr",
".",
"String",
"(",
")",
")",
")",
"\n\n",
"}",
"\n",
"if",
"s",
",",
"exists",
":=",
"predef",
"[",
"\"",
"\"",
"]",
";",
"exists",
"{",
"newHost",
".",
"InternalAddr",
"=",
"net",
".",
"ParseIP",
"(",
"s",
")",
"\n",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"serial",
",",
"newHost",
".",
"InternalAddr",
".",
"String",
"(",
")",
")",
")",
"\n\n",
"newHost",
".",
"Hostname",
"=",
"strings",
".",
"Replace",
"(",
"newHost",
".",
"InternalAddr",
".",
"String",
"(",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"4",
")",
"\n",
"}",
"\n",
"if",
"s",
",",
"exists",
":=",
"predef",
"[",
"\"",
"\"",
"]",
";",
"exists",
"{",
"newHost",
".",
"EtcdClusterToken",
"=",
"s",
"\n",
"}",
"\n",
"}",
"else",
"{",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"serial",
")",
")",
"\n",
"}",
"\n\n",
"machineID",
":=",
"genMachineID",
"(",
")",
"\n",
"newHost",
".",
"MachineID",
"=",
"machineID",
"\n",
"if",
"newHost",
".",
"InternalAddr",
"!=",
"nil",
"{",
"newHost",
".",
"Hostname",
"=",
"strings",
".",
"Replace",
"(",
"newHost",
".",
"InternalAddr",
".",
"String",
"(",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"4",
")",
"\n",
"}",
"\n",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"newHost",
".",
"InternalAddr",
".",
"String",
"(",
")",
",",
"newHost",
".",
"Hostname",
")",
")",
"\n",
"newHost",
".",
"Commit",
"(",
"\"",
"\"",
")",
"\n\n",
"err",
"=",
"c",
".",
"reindex",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"newHost",
",",
"nil",
"\n",
"}"
]
| // CreateNewHost creates a new host with the given serial. | [
"CreateNewHost",
"creates",
"a",
"new",
"host",
"with",
"the",
"given",
"serial",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/cluster.go#L111-L153 |
146,459 | giantswarm/mayu | hostmgr/cluster.go | Update | func (c *Cluster) Update() error {
c.mu.Lock()
defer c.mu.Unlock()
if err := c.cacheHosts(); err != nil {
return microerror.Mask(err)
}
err := c.reindex()
if err != nil {
return microerror.Mask(err)
}
return nil
} | go | func (c *Cluster) Update() error {
c.mu.Lock()
defer c.mu.Unlock()
if err := c.cacheHosts(); err != nil {
return microerror.Mask(err)
}
err := c.reindex()
if err != nil {
return microerror.Mask(err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"Update",
"(",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"cacheHosts",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"err",
":=",
"c",
".",
"reindex",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"microerror",
".",
"Mask",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Update refreshs the internal host cache based on information within the
// cluster directory. | [
"Update",
"refreshs",
"the",
"internal",
"host",
"cache",
"based",
"on",
"information",
"within",
"the",
"cluster",
"directory",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/cluster.go#L168-L180 |
146,460 | giantswarm/mayu | hostmgr/cluster.go | HostWithMacAddress | func (c *Cluster) HostWithMacAddress(macAddr string) (*Host, bool) {
if err := c.Update(); err != nil {
c.logger.Log("level", "error", "message", "error getting the mac address using the internal cache", "stack", err)
return nil, false
}
c.mu.Lock()
defer c.mu.Unlock()
if cached, exists := c.hostByMacAddr[strings.ToLower(macAddr)]; exists {
return cached.get(), true
} else {
return nil, false
}
} | go | func (c *Cluster) HostWithMacAddress(macAddr string) (*Host, bool) {
if err := c.Update(); err != nil {
c.logger.Log("level", "error", "message", "error getting the mac address using the internal cache", "stack", err)
return nil, false
}
c.mu.Lock()
defer c.mu.Unlock()
if cached, exists := c.hostByMacAddr[strings.ToLower(macAddr)]; exists {
return cached.get(), true
} else {
return nil, false
}
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"HostWithMacAddress",
"(",
"macAddr",
"string",
")",
"(",
"*",
"Host",
",",
"bool",
")",
"{",
"if",
"err",
":=",
"c",
".",
"Update",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"cached",
",",
"exists",
":=",
"c",
".",
"hostByMacAddr",
"[",
"strings",
".",
"ToLower",
"(",
"macAddr",
")",
"]",
";",
"exists",
"{",
"return",
"cached",
".",
"get",
"(",
")",
",",
"true",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"}"
]
| // HostWithMacAddress returns the host object given by macAddr based on the
// internal cache. In case the host could not be found, host is nil and false
// is returned as second return value. | [
"HostWithMacAddress",
"returns",
"the",
"host",
"object",
"given",
"by",
"macAddr",
"based",
"on",
"the",
"internal",
"cache",
".",
"In",
"case",
"the",
"host",
"could",
"not",
"be",
"found",
"host",
"is",
"nil",
"and",
"false",
"is",
"returned",
"as",
"second",
"return",
"value",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/cluster.go#L185-L198 |
146,461 | giantswarm/mayu | hostmgr/cluster.go | HostWithInternalAddr | func (c *Cluster) HostWithInternalAddr(ipAddr net.IP) (*Host, bool) {
if err := c.Update(); err != nil {
c.logger.Log("level", "error", "message", "error getting the ip address using the internal cache", "stack", err)
return nil, false
}
c.mu.Lock()
defer c.mu.Unlock()
if cached, exists := c.hostByInternalAddr[ipAddr.String()]; exists {
return cached.get(), true
} else {
return nil, false
}
} | go | func (c *Cluster) HostWithInternalAddr(ipAddr net.IP) (*Host, bool) {
if err := c.Update(); err != nil {
c.logger.Log("level", "error", "message", "error getting the ip address using the internal cache", "stack", err)
return nil, false
}
c.mu.Lock()
defer c.mu.Unlock()
if cached, exists := c.hostByInternalAddr[ipAddr.String()]; exists {
return cached.get(), true
} else {
return nil, false
}
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"HostWithInternalAddr",
"(",
"ipAddr",
"net",
".",
"IP",
")",
"(",
"*",
"Host",
",",
"bool",
")",
"{",
"if",
"err",
":=",
"c",
".",
"Update",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"cached",
",",
"exists",
":=",
"c",
".",
"hostByInternalAddr",
"[",
"ipAddr",
".",
"String",
"(",
")",
"]",
";",
"exists",
"{",
"return",
"cached",
".",
"get",
"(",
")",
",",
"true",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"}"
]
| // HostWithInternalAddr returns the host object given by ipAddr based on the
// internal cache. In case the host could not be found, host is nil and false
// is returned as second return value. | [
"HostWithInternalAddr",
"returns",
"the",
"host",
"object",
"given",
"by",
"ipAddr",
"based",
"on",
"the",
"internal",
"cache",
".",
"In",
"case",
"the",
"host",
"could",
"not",
"be",
"found",
"host",
"is",
"nil",
"and",
"false",
"is",
"returned",
"as",
"second",
"return",
"value",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/cluster.go#L203-L216 |
146,462 | giantswarm/mayu | hostmgr/cluster.go | HostWithSerial | func (c *Cluster) HostWithSerial(serial string) (*Host, bool) {
if err := c.Update(); err != nil {
c.logger.Log("level", "error", "message", "error getting the serial number using the internal cache", "stack", err)
return nil, false
}
c.mu.Lock()
defer c.mu.Unlock()
if cached, exists := c.hostsCache[strings.ToLower(serial)]; exists {
return cached.get(), true
} else {
return nil, false
}
} | go | func (c *Cluster) HostWithSerial(serial string) (*Host, bool) {
if err := c.Update(); err != nil {
c.logger.Log("level", "error", "message", "error getting the serial number using the internal cache", "stack", err)
return nil, false
}
c.mu.Lock()
defer c.mu.Unlock()
if cached, exists := c.hostsCache[strings.ToLower(serial)]; exists {
return cached.get(), true
} else {
return nil, false
}
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"HostWithSerial",
"(",
"serial",
"string",
")",
"(",
"*",
"Host",
",",
"bool",
")",
"{",
"if",
"err",
":=",
"c",
".",
"Update",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"cached",
",",
"exists",
":=",
"c",
".",
"hostsCache",
"[",
"strings",
".",
"ToLower",
"(",
"serial",
")",
"]",
";",
"exists",
"{",
"return",
"cached",
".",
"get",
"(",
")",
",",
"true",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"}"
]
| // HostWithSerial returns the host object given by serial based on the internal
// cache. In case the host could not be found, host is nil and false is
// returned as second return value. | [
"HostWithSerial",
"returns",
"the",
"host",
"object",
"given",
"by",
"serial",
"based",
"on",
"the",
"internal",
"cache",
".",
"In",
"case",
"the",
"host",
"could",
"not",
"be",
"found",
"host",
"is",
"nil",
"and",
"false",
"is",
"returned",
"as",
"second",
"return",
"value",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/cluster.go#L221-L234 |
146,463 | giantswarm/mayu | hostmgr/cluster.go | GetAllHosts | func (c *Cluster) GetAllHosts() []*Host {
hosts := make([]*Host, 0, len(c.hostsCache))
if err := c.Update(); err != nil {
c.logger.Log("level", "error", "message", "error getting the list of hosts based on the internal cache: %#v", "stack", err)
return hosts
}
for _, cachedHost := range c.hostsCache {
hosts = append(hosts, cachedHost.get())
}
return hosts
} | go | func (c *Cluster) GetAllHosts() []*Host {
hosts := make([]*Host, 0, len(c.hostsCache))
if err := c.Update(); err != nil {
c.logger.Log("level", "error", "message", "error getting the list of hosts based on the internal cache: %#v", "stack", err)
return hosts
}
for _, cachedHost := range c.hostsCache {
hosts = append(hosts, cachedHost.get())
}
return hosts
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"GetAllHosts",
"(",
")",
"[",
"]",
"*",
"Host",
"{",
"hosts",
":=",
"make",
"(",
"[",
"]",
"*",
"Host",
",",
"0",
",",
"len",
"(",
"c",
".",
"hostsCache",
")",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Update",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"hosts",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"cachedHost",
":=",
"range",
"c",
".",
"hostsCache",
"{",
"hosts",
"=",
"append",
"(",
"hosts",
",",
"cachedHost",
".",
"get",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"hosts",
"\n",
"}"
]
| // GetAllHosts returns a list of all hosts based on the internal cache. | [
"GetAllHosts",
"returns",
"a",
"list",
"of",
"all",
"hosts",
"based",
"on",
"the",
"internal",
"cache",
"."
]
| 00428982411d0e1679e86e25287827b3a308a9e4 | https://github.com/giantswarm/mayu/blob/00428982411d0e1679e86e25287827b3a308a9e4/hostmgr/cluster.go#L261-L273 |
146,464 | fatih/color | color.go | New | func New(value ...Attribute) *Color {
c := &Color{params: make([]Attribute, 0)}
c.Add(value...)
return c
} | go | func New(value ...Attribute) *Color {
c := &Color{params: make([]Attribute, 0)}
c.Add(value...)
return c
} | [
"func",
"New",
"(",
"value",
"...",
"Attribute",
")",
"*",
"Color",
"{",
"c",
":=",
"&",
"Color",
"{",
"params",
":",
"make",
"(",
"[",
"]",
"Attribute",
",",
"0",
")",
"}",
"\n",
"c",
".",
"Add",
"(",
"value",
"...",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // New returns a newly created color object. | [
"New",
"returns",
"a",
"newly",
"created",
"color",
"object",
"."
]
| 3f9d52f7176a6927daacff70a3e8d1dc2025c53e | https://github.com/fatih/color/blob/3f9d52f7176a6927daacff70a3e8d1dc2025c53e/color.go#L110-L114 |
146,465 | fatih/color | color.go | Set | func (c *Color) Set() *Color {
if c.isNoColorSet() {
return c
}
fmt.Fprintf(Output, c.format())
return c
} | go | func (c *Color) Set() *Color {
if c.isNoColorSet() {
return c
}
fmt.Fprintf(Output, c.format())
return c
} | [
"func",
"(",
"c",
"*",
"Color",
")",
"Set",
"(",
")",
"*",
"Color",
"{",
"if",
"c",
".",
"isNoColorSet",
"(",
")",
"{",
"return",
"c",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintf",
"(",
"Output",
",",
"c",
".",
"format",
"(",
")",
")",
"\n",
"return",
"c",
"\n",
"}"
]
| // Set sets the SGR sequence. | [
"Set",
"sets",
"the",
"SGR",
"sequence",
"."
]
| 3f9d52f7176a6927daacff70a3e8d1dc2025c53e | https://github.com/fatih/color/blob/3f9d52f7176a6927daacff70a3e8d1dc2025c53e/color.go#L135-L142 |
146,466 | fatih/color | color.go | Sprint | func (c *Color) Sprint(a ...interface{}) string {
return c.wrap(fmt.Sprint(a...))
} | go | func (c *Color) Sprint(a ...interface{}) string {
return c.wrap(fmt.Sprint(a...))
} | [
"func",
"(",
"c",
"*",
"Color",
")",
"Sprint",
"(",
"a",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"return",
"c",
".",
"wrap",
"(",
"fmt",
".",
"Sprint",
"(",
"a",
"...",
")",
")",
"\n",
"}"
]
| // Sprint is just like Print, but returns a string instead of printing it. | [
"Sprint",
"is",
"just",
"like",
"Print",
"but",
"returns",
"a",
"string",
"instead",
"of",
"printing",
"it",
"."
]
| 3f9d52f7176a6927daacff70a3e8d1dc2025c53e | https://github.com/fatih/color/blob/3f9d52f7176a6927daacff70a3e8d1dc2025c53e/color.go#L255-L257 |
146,467 | fatih/color | color.go | Sprintln | func (c *Color) Sprintln(a ...interface{}) string {
return c.wrap(fmt.Sprintln(a...))
} | go | func (c *Color) Sprintln(a ...interface{}) string {
return c.wrap(fmt.Sprintln(a...))
} | [
"func",
"(",
"c",
"*",
"Color",
")",
"Sprintln",
"(",
"a",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"return",
"c",
".",
"wrap",
"(",
"fmt",
".",
"Sprintln",
"(",
"a",
"...",
")",
")",
"\n",
"}"
]
| // Sprintln is just like Println, but returns a string instead of printing it. | [
"Sprintln",
"is",
"just",
"like",
"Println",
"but",
"returns",
"a",
"string",
"instead",
"of",
"printing",
"it",
"."
]
| 3f9d52f7176a6927daacff70a3e8d1dc2025c53e | https://github.com/fatih/color/blob/3f9d52f7176a6927daacff70a3e8d1dc2025c53e/color.go#L260-L262 |
146,468 | fatih/color | color.go | Sprintf | func (c *Color) Sprintf(format string, a ...interface{}) string {
return c.wrap(fmt.Sprintf(format, a...))
} | go | func (c *Color) Sprintf(format string, a ...interface{}) string {
return c.wrap(fmt.Sprintf(format, a...))
} | [
"func",
"(",
"c",
"*",
"Color",
")",
"Sprintf",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"return",
"c",
".",
"wrap",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"a",
"...",
")",
")",
"\n",
"}"
]
| // Sprintf is just like Printf, but returns a string instead of printing it. | [
"Sprintf",
"is",
"just",
"like",
"Printf",
"but",
"returns",
"a",
"string",
"instead",
"of",
"printing",
"it",
"."
]
| 3f9d52f7176a6927daacff70a3e8d1dc2025c53e | https://github.com/fatih/color/blob/3f9d52f7176a6927daacff70a3e8d1dc2025c53e/color.go#L265-L267 |
146,469 | fatih/color | color.go | wrap | func (c *Color) wrap(s string) string {
if c.isNoColorSet() {
return s
}
return c.format() + s + c.unformat()
} | go | func (c *Color) wrap(s string) string {
if c.isNoColorSet() {
return s
}
return c.format() + s + c.unformat()
} | [
"func",
"(",
"c",
"*",
"Color",
")",
"wrap",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"c",
".",
"isNoColorSet",
"(",
")",
"{",
"return",
"s",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"format",
"(",
")",
"+",
"s",
"+",
"c",
".",
"unformat",
"(",
")",
"\n",
"}"
]
| // wrap wraps the s string with the colors attributes. The string is ready to
// be printed. | [
"wrap",
"wraps",
"the",
"s",
"string",
"with",
"the",
"colors",
"attributes",
".",
"The",
"string",
"is",
"ready",
"to",
"be",
"printed",
"."
]
| 3f9d52f7176a6927daacff70a3e8d1dc2025c53e | https://github.com/fatih/color/blob/3f9d52f7176a6927daacff70a3e8d1dc2025c53e/color.go#L360-L366 |
146,470 | fatih/color | color.go | Equals | func (c *Color) Equals(c2 *Color) bool {
if len(c.params) != len(c2.params) {
return false
}
for _, attr := range c.params {
if !c2.attrExists(attr) {
return false
}
}
return true
} | go | func (c *Color) Equals(c2 *Color) bool {
if len(c.params) != len(c2.params) {
return false
}
for _, attr := range c.params {
if !c2.attrExists(attr) {
return false
}
}
return true
} | [
"func",
"(",
"c",
"*",
"Color",
")",
"Equals",
"(",
"c2",
"*",
"Color",
")",
"bool",
"{",
"if",
"len",
"(",
"c",
".",
"params",
")",
"!=",
"len",
"(",
"c2",
".",
"params",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"attr",
":=",
"range",
"c",
".",
"params",
"{",
"if",
"!",
"c2",
".",
"attrExists",
"(",
"attr",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
]
| // Equals returns a boolean value indicating whether two colors are equal. | [
"Equals",
"returns",
"a",
"boolean",
"value",
"indicating",
"whether",
"two",
"colors",
"are",
"equal",
"."
]
| 3f9d52f7176a6927daacff70a3e8d1dc2025c53e | https://github.com/fatih/color/blob/3f9d52f7176a6927daacff70a3e8d1dc2025c53e/color.go#L400-L412 |
146,471 | BurntSushi/toml | decode.go | PrimitiveDecode | func PrimitiveDecode(primValue Primitive, v interface{}) error {
md := MetaData{decoded: make(map[string]bool)}
return md.unify(primValue.undecoded, rvalue(v))
} | go | func PrimitiveDecode(primValue Primitive, v interface{}) error {
md := MetaData{decoded: make(map[string]bool)}
return md.unify(primValue.undecoded, rvalue(v))
} | [
"func",
"PrimitiveDecode",
"(",
"primValue",
"Primitive",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"md",
":=",
"MetaData",
"{",
"decoded",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"}",
"\n",
"return",
"md",
".",
"unify",
"(",
"primValue",
".",
"undecoded",
",",
"rvalue",
"(",
"v",
")",
")",
"\n",
"}"
]
| // DEPRECATED!
//
// Use MetaData.PrimitiveDecode instead. | [
"DEPRECATED!",
"Use",
"MetaData",
".",
"PrimitiveDecode",
"instead",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/decode.go#L49-L52 |
146,472 | BurntSushi/toml | decode.go | DecodeFile | func DecodeFile(fpath string, v interface{}) (MetaData, error) {
bs, err := ioutil.ReadFile(fpath)
if err != nil {
return MetaData{}, err
}
return Decode(string(bs), v)
} | go | func DecodeFile(fpath string, v interface{}) (MetaData, error) {
bs, err := ioutil.ReadFile(fpath)
if err != nil {
return MetaData{}, err
}
return Decode(string(bs), v)
} | [
"func",
"DecodeFile",
"(",
"fpath",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"MetaData",
",",
"error",
")",
"{",
"bs",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"fpath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"MetaData",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"Decode",
"(",
"string",
"(",
"bs",
")",
",",
"v",
")",
"\n",
"}"
]
| // DecodeFile is just like Decode, except it will automatically read the
// contents of the file at `fpath` and decode it for you. | [
"DecodeFile",
"is",
"just",
"like",
"Decode",
"except",
"it",
"will",
"automatically",
"read",
"the",
"contents",
"of",
"the",
"file",
"at",
"fpath",
"and",
"decode",
"it",
"for",
"you",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/decode.go#L128-L134 |
146,473 | BurntSushi/toml | decode.go | DecodeReader | func DecodeReader(r io.Reader, v interface{}) (MetaData, error) {
bs, err := ioutil.ReadAll(r)
if err != nil {
return MetaData{}, err
}
return Decode(string(bs), v)
} | go | func DecodeReader(r io.Reader, v interface{}) (MetaData, error) {
bs, err := ioutil.ReadAll(r)
if err != nil {
return MetaData{}, err
}
return Decode(string(bs), v)
} | [
"func",
"DecodeReader",
"(",
"r",
"io",
".",
"Reader",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"MetaData",
",",
"error",
")",
"{",
"bs",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"MetaData",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"Decode",
"(",
"string",
"(",
"bs",
")",
",",
"v",
")",
"\n",
"}"
]
| // DecodeReader is just like Decode, except it will consume all bytes
// from the reader and decode it for you. | [
"DecodeReader",
"is",
"just",
"like",
"Decode",
"except",
"it",
"will",
"consume",
"all",
"bytes",
"from",
"the",
"reader",
"and",
"decode",
"it",
"for",
"you",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/decode.go#L138-L144 |
146,474 | BurntSushi/toml | decode.go | unify | func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
// Special case. Look for a `Primitive` value.
if rv.Type() == reflect.TypeOf((*Primitive)(nil)).Elem() {
// Save the undecoded data and the key context into the primitive
// value.
context := make(Key, len(md.context))
copy(context, md.context)
rv.Set(reflect.ValueOf(Primitive{
undecoded: data,
context: context,
}))
return nil
}
// Special case. Unmarshaler Interface support.
if rv.CanAddr() {
if v, ok := rv.Addr().Interface().(Unmarshaler); ok {
return v.UnmarshalTOML(data)
}
}
// Special case. Handle time.Time values specifically.
// TODO: Remove this code when we decide to drop support for Go 1.1.
// This isn't necessary in Go 1.2 because time.Time satisfies the encoding
// interfaces.
if rv.Type().AssignableTo(rvalue(time.Time{}).Type()) {
return md.unifyDatetime(data, rv)
}
// Special case. Look for a value satisfying the TextUnmarshaler interface.
if v, ok := rv.Interface().(TextUnmarshaler); ok {
return md.unifyText(data, v)
}
// BUG(burntsushi)
// The behavior here is incorrect whenever a Go type satisfies the
// encoding.TextUnmarshaler interface but also corresponds to a TOML
// hash or array. In particular, the unmarshaler should only be applied
// to primitive TOML values. But at this point, it will be applied to
// all kinds of values and produce an incorrect error whenever those values
// are hashes or arrays (including arrays of tables).
k := rv.Kind()
// laziness
if k >= reflect.Int && k <= reflect.Uint64 {
return md.unifyInt(data, rv)
}
switch k {
case reflect.Ptr:
elem := reflect.New(rv.Type().Elem())
err := md.unify(data, reflect.Indirect(elem))
if err != nil {
return err
}
rv.Set(elem)
return nil
case reflect.Struct:
return md.unifyStruct(data, rv)
case reflect.Map:
return md.unifyMap(data, rv)
case reflect.Array:
return md.unifyArray(data, rv)
case reflect.Slice:
return md.unifySlice(data, rv)
case reflect.String:
return md.unifyString(data, rv)
case reflect.Bool:
return md.unifyBool(data, rv)
case reflect.Interface:
// we only support empty interfaces.
if rv.NumMethod() > 0 {
return e("unsupported type %s", rv.Type())
}
return md.unifyAnything(data, rv)
case reflect.Float32:
fallthrough
case reflect.Float64:
return md.unifyFloat64(data, rv)
}
return e("unsupported type %s", rv.Kind())
} | go | func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
// Special case. Look for a `Primitive` value.
if rv.Type() == reflect.TypeOf((*Primitive)(nil)).Elem() {
// Save the undecoded data and the key context into the primitive
// value.
context := make(Key, len(md.context))
copy(context, md.context)
rv.Set(reflect.ValueOf(Primitive{
undecoded: data,
context: context,
}))
return nil
}
// Special case. Unmarshaler Interface support.
if rv.CanAddr() {
if v, ok := rv.Addr().Interface().(Unmarshaler); ok {
return v.UnmarshalTOML(data)
}
}
// Special case. Handle time.Time values specifically.
// TODO: Remove this code when we decide to drop support for Go 1.1.
// This isn't necessary in Go 1.2 because time.Time satisfies the encoding
// interfaces.
if rv.Type().AssignableTo(rvalue(time.Time{}).Type()) {
return md.unifyDatetime(data, rv)
}
// Special case. Look for a value satisfying the TextUnmarshaler interface.
if v, ok := rv.Interface().(TextUnmarshaler); ok {
return md.unifyText(data, v)
}
// BUG(burntsushi)
// The behavior here is incorrect whenever a Go type satisfies the
// encoding.TextUnmarshaler interface but also corresponds to a TOML
// hash or array. In particular, the unmarshaler should only be applied
// to primitive TOML values. But at this point, it will be applied to
// all kinds of values and produce an incorrect error whenever those values
// are hashes or arrays (including arrays of tables).
k := rv.Kind()
// laziness
if k >= reflect.Int && k <= reflect.Uint64 {
return md.unifyInt(data, rv)
}
switch k {
case reflect.Ptr:
elem := reflect.New(rv.Type().Elem())
err := md.unify(data, reflect.Indirect(elem))
if err != nil {
return err
}
rv.Set(elem)
return nil
case reflect.Struct:
return md.unifyStruct(data, rv)
case reflect.Map:
return md.unifyMap(data, rv)
case reflect.Array:
return md.unifyArray(data, rv)
case reflect.Slice:
return md.unifySlice(data, rv)
case reflect.String:
return md.unifyString(data, rv)
case reflect.Bool:
return md.unifyBool(data, rv)
case reflect.Interface:
// we only support empty interfaces.
if rv.NumMethod() > 0 {
return e("unsupported type %s", rv.Type())
}
return md.unifyAnything(data, rv)
case reflect.Float32:
fallthrough
case reflect.Float64:
return md.unifyFloat64(data, rv)
}
return e("unsupported type %s", rv.Kind())
} | [
"func",
"(",
"md",
"*",
"MetaData",
")",
"unify",
"(",
"data",
"interface",
"{",
"}",
",",
"rv",
"reflect",
".",
"Value",
")",
"error",
"{",
"// Special case. Look for a `Primitive` value.",
"if",
"rv",
".",
"Type",
"(",
")",
"==",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"Primitive",
")",
"(",
"nil",
")",
")",
".",
"Elem",
"(",
")",
"{",
"// Save the undecoded data and the key context into the primitive",
"// value.",
"context",
":=",
"make",
"(",
"Key",
",",
"len",
"(",
"md",
".",
"context",
")",
")",
"\n",
"copy",
"(",
"context",
",",
"md",
".",
"context",
")",
"\n",
"rv",
".",
"Set",
"(",
"reflect",
".",
"ValueOf",
"(",
"Primitive",
"{",
"undecoded",
":",
"data",
",",
"context",
":",
"context",
",",
"}",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Special case. Unmarshaler Interface support.",
"if",
"rv",
".",
"CanAddr",
"(",
")",
"{",
"if",
"v",
",",
"ok",
":=",
"rv",
".",
"Addr",
"(",
")",
".",
"Interface",
"(",
")",
".",
"(",
"Unmarshaler",
")",
";",
"ok",
"{",
"return",
"v",
".",
"UnmarshalTOML",
"(",
"data",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Special case. Handle time.Time values specifically.",
"// TODO: Remove this code when we decide to drop support for Go 1.1.",
"// This isn't necessary in Go 1.2 because time.Time satisfies the encoding",
"// interfaces.",
"if",
"rv",
".",
"Type",
"(",
")",
".",
"AssignableTo",
"(",
"rvalue",
"(",
"time",
".",
"Time",
"{",
"}",
")",
".",
"Type",
"(",
")",
")",
"{",
"return",
"md",
".",
"unifyDatetime",
"(",
"data",
",",
"rv",
")",
"\n",
"}",
"\n\n",
"// Special case. Look for a value satisfying the TextUnmarshaler interface.",
"if",
"v",
",",
"ok",
":=",
"rv",
".",
"Interface",
"(",
")",
".",
"(",
"TextUnmarshaler",
")",
";",
"ok",
"{",
"return",
"md",
".",
"unifyText",
"(",
"data",
",",
"v",
")",
"\n",
"}",
"\n",
"// BUG(burntsushi)",
"// The behavior here is incorrect whenever a Go type satisfies the",
"// encoding.TextUnmarshaler interface but also corresponds to a TOML",
"// hash or array. In particular, the unmarshaler should only be applied",
"// to primitive TOML values. But at this point, it will be applied to",
"// all kinds of values and produce an incorrect error whenever those values",
"// are hashes or arrays (including arrays of tables).",
"k",
":=",
"rv",
".",
"Kind",
"(",
")",
"\n\n",
"// laziness",
"if",
"k",
">=",
"reflect",
".",
"Int",
"&&",
"k",
"<=",
"reflect",
".",
"Uint64",
"{",
"return",
"md",
".",
"unifyInt",
"(",
"data",
",",
"rv",
")",
"\n",
"}",
"\n",
"switch",
"k",
"{",
"case",
"reflect",
".",
"Ptr",
":",
"elem",
":=",
"reflect",
".",
"New",
"(",
"rv",
".",
"Type",
"(",
")",
".",
"Elem",
"(",
")",
")",
"\n",
"err",
":=",
"md",
".",
"unify",
"(",
"data",
",",
"reflect",
".",
"Indirect",
"(",
"elem",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"rv",
".",
"Set",
"(",
"elem",
")",
"\n",
"return",
"nil",
"\n",
"case",
"reflect",
".",
"Struct",
":",
"return",
"md",
".",
"unifyStruct",
"(",
"data",
",",
"rv",
")",
"\n",
"case",
"reflect",
".",
"Map",
":",
"return",
"md",
".",
"unifyMap",
"(",
"data",
",",
"rv",
")",
"\n",
"case",
"reflect",
".",
"Array",
":",
"return",
"md",
".",
"unifyArray",
"(",
"data",
",",
"rv",
")",
"\n",
"case",
"reflect",
".",
"Slice",
":",
"return",
"md",
".",
"unifySlice",
"(",
"data",
",",
"rv",
")",
"\n",
"case",
"reflect",
".",
"String",
":",
"return",
"md",
".",
"unifyString",
"(",
"data",
",",
"rv",
")",
"\n",
"case",
"reflect",
".",
"Bool",
":",
"return",
"md",
".",
"unifyBool",
"(",
"data",
",",
"rv",
")",
"\n",
"case",
"reflect",
".",
"Interface",
":",
"// we only support empty interfaces.",
"if",
"rv",
".",
"NumMethod",
"(",
")",
">",
"0",
"{",
"return",
"e",
"(",
"\"",
"\"",
",",
"rv",
".",
"Type",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"md",
".",
"unifyAnything",
"(",
"data",
",",
"rv",
")",
"\n",
"case",
"reflect",
".",
"Float32",
":",
"fallthrough",
"\n",
"case",
"reflect",
".",
"Float64",
":",
"return",
"md",
".",
"unifyFloat64",
"(",
"data",
",",
"rv",
")",
"\n",
"}",
"\n",
"return",
"e",
"(",
"\"",
"\"",
",",
"rv",
".",
"Kind",
"(",
")",
")",
"\n",
"}"
]
| // unify performs a sort of type unification based on the structure of `rv`,
// which is the client representation.
//
// Any type mismatch produces an error. Finding a type that we don't know
// how to handle produces an unsupported type error. | [
"unify",
"performs",
"a",
"sort",
"of",
"type",
"unification",
"based",
"on",
"the",
"structure",
"of",
"rv",
"which",
"is",
"the",
"client",
"representation",
".",
"Any",
"type",
"mismatch",
"produces",
"an",
"error",
".",
"Finding",
"a",
"type",
"that",
"we",
"don",
"t",
"know",
"how",
"to",
"handle",
"produces",
"an",
"unsupported",
"type",
"error",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/decode.go#L151-L232 |
146,475 | BurntSushi/toml | parse.go | numUnderscoresOK | func numUnderscoresOK(s string) bool {
accept := false
for _, r := range s {
if r == '_' {
if !accept {
return false
}
accept = false
continue
}
accept = true
}
return accept
} | go | func numUnderscoresOK(s string) bool {
accept := false
for _, r := range s {
if r == '_' {
if !accept {
return false
}
accept = false
continue
}
accept = true
}
return accept
} | [
"func",
"numUnderscoresOK",
"(",
"s",
"string",
")",
"bool",
"{",
"accept",
":=",
"false",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"if",
"r",
"==",
"'_'",
"{",
"if",
"!",
"accept",
"{",
"return",
"false",
"\n",
"}",
"\n",
"accept",
"=",
"false",
"\n",
"continue",
"\n",
"}",
"\n",
"accept",
"=",
"true",
"\n",
"}",
"\n",
"return",
"accept",
"\n",
"}"
]
| // numUnderscoresOK checks whether each underscore in s is surrounded by
// characters that are not underscores. | [
"numUnderscoresOK",
"checks",
"whether",
"each",
"underscore",
"in",
"s",
"is",
"surrounded",
"by",
"characters",
"that",
"are",
"not",
"underscores",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/parse.go#L314-L327 |
146,476 | BurntSushi/toml | parse.go | numPeriodsOK | func numPeriodsOK(s string) bool {
period := false
for _, r := range s {
if period && !isDigit(r) {
return false
}
period = r == '.'
}
return !period
} | go | func numPeriodsOK(s string) bool {
period := false
for _, r := range s {
if period && !isDigit(r) {
return false
}
period = r == '.'
}
return !period
} | [
"func",
"numPeriodsOK",
"(",
"s",
"string",
")",
"bool",
"{",
"period",
":=",
"false",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"if",
"period",
"&&",
"!",
"isDigit",
"(",
"r",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"period",
"=",
"r",
"==",
"'.'",
"\n",
"}",
"\n",
"return",
"!",
"period",
"\n",
"}"
]
| // numPeriodsOK checks whether every period in s is followed by a digit. | [
"numPeriodsOK",
"checks",
"whether",
"every",
"period",
"in",
"s",
"is",
"followed",
"by",
"a",
"digit",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/parse.go#L330-L339 |
146,477 | BurntSushi/toml | parse.go | establishContext | func (p *parser) establishContext(key Key, array bool) {
var ok bool
// Always start at the top level and drill down for our context.
hashContext := p.mapping
keyContext := make(Key, 0)
// We only need implicit hashes for key[0:-1]
for _, k := range key[0 : len(key)-1] {
_, ok = hashContext[k]
keyContext = append(keyContext, k)
// No key? Make an implicit hash and move on.
if !ok {
p.addImplicit(keyContext)
hashContext[k] = make(map[string]interface{})
}
// If the hash context is actually an array of tables, then set
// the hash context to the last element in that array.
//
// Otherwise, it better be a table, since this MUST be a key group (by
// virtue of it not being the last element in a key).
switch t := hashContext[k].(type) {
case []map[string]interface{}:
hashContext = t[len(t)-1]
case map[string]interface{}:
hashContext = t
default:
p.panicf("Key '%s' was already created as a hash.", keyContext)
}
}
p.context = keyContext
if array {
// If this is the first element for this array, then allocate a new
// list of tables for it.
k := key[len(key)-1]
if _, ok := hashContext[k]; !ok {
hashContext[k] = make([]map[string]interface{}, 0, 5)
}
// Add a new table. But make sure the key hasn't already been used
// for something else.
if hash, ok := hashContext[k].([]map[string]interface{}); ok {
hashContext[k] = append(hash, make(map[string]interface{}))
} else {
p.panicf("Key '%s' was already created and cannot be used as "+
"an array.", keyContext)
}
} else {
p.setValue(key[len(key)-1], make(map[string]interface{}))
}
p.context = append(p.context, key[len(key)-1])
} | go | func (p *parser) establishContext(key Key, array bool) {
var ok bool
// Always start at the top level and drill down for our context.
hashContext := p.mapping
keyContext := make(Key, 0)
// We only need implicit hashes for key[0:-1]
for _, k := range key[0 : len(key)-1] {
_, ok = hashContext[k]
keyContext = append(keyContext, k)
// No key? Make an implicit hash and move on.
if !ok {
p.addImplicit(keyContext)
hashContext[k] = make(map[string]interface{})
}
// If the hash context is actually an array of tables, then set
// the hash context to the last element in that array.
//
// Otherwise, it better be a table, since this MUST be a key group (by
// virtue of it not being the last element in a key).
switch t := hashContext[k].(type) {
case []map[string]interface{}:
hashContext = t[len(t)-1]
case map[string]interface{}:
hashContext = t
default:
p.panicf("Key '%s' was already created as a hash.", keyContext)
}
}
p.context = keyContext
if array {
// If this is the first element for this array, then allocate a new
// list of tables for it.
k := key[len(key)-1]
if _, ok := hashContext[k]; !ok {
hashContext[k] = make([]map[string]interface{}, 0, 5)
}
// Add a new table. But make sure the key hasn't already been used
// for something else.
if hash, ok := hashContext[k].([]map[string]interface{}); ok {
hashContext[k] = append(hash, make(map[string]interface{}))
} else {
p.panicf("Key '%s' was already created and cannot be used as "+
"an array.", keyContext)
}
} else {
p.setValue(key[len(key)-1], make(map[string]interface{}))
}
p.context = append(p.context, key[len(key)-1])
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"establishContext",
"(",
"key",
"Key",
",",
"array",
"bool",
")",
"{",
"var",
"ok",
"bool",
"\n\n",
"// Always start at the top level and drill down for our context.",
"hashContext",
":=",
"p",
".",
"mapping",
"\n",
"keyContext",
":=",
"make",
"(",
"Key",
",",
"0",
")",
"\n\n",
"// We only need implicit hashes for key[0:-1]",
"for",
"_",
",",
"k",
":=",
"range",
"key",
"[",
"0",
":",
"len",
"(",
"key",
")",
"-",
"1",
"]",
"{",
"_",
",",
"ok",
"=",
"hashContext",
"[",
"k",
"]",
"\n",
"keyContext",
"=",
"append",
"(",
"keyContext",
",",
"k",
")",
"\n\n",
"// No key? Make an implicit hash and move on.",
"if",
"!",
"ok",
"{",
"p",
".",
"addImplicit",
"(",
"keyContext",
")",
"\n",
"hashContext",
"[",
"k",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n\n",
"// If the hash context is actually an array of tables, then set",
"// the hash context to the last element in that array.",
"//",
"// Otherwise, it better be a table, since this MUST be a key group (by",
"// virtue of it not being the last element in a key).",
"switch",
"t",
":=",
"hashContext",
"[",
"k",
"]",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
":",
"hashContext",
"=",
"t",
"[",
"len",
"(",
"t",
")",
"-",
"1",
"]",
"\n",
"case",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
":",
"hashContext",
"=",
"t",
"\n",
"default",
":",
"p",
".",
"panicf",
"(",
"\"",
"\"",
",",
"keyContext",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"p",
".",
"context",
"=",
"keyContext",
"\n",
"if",
"array",
"{",
"// If this is the first element for this array, then allocate a new",
"// list of tables for it.",
"k",
":=",
"key",
"[",
"len",
"(",
"key",
")",
"-",
"1",
"]",
"\n",
"if",
"_",
",",
"ok",
":=",
"hashContext",
"[",
"k",
"]",
";",
"!",
"ok",
"{",
"hashContext",
"[",
"k",
"]",
"=",
"make",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
",",
"5",
")",
"\n",
"}",
"\n\n",
"// Add a new table. But make sure the key hasn't already been used",
"// for something else.",
"if",
"hash",
",",
"ok",
":=",
"hashContext",
"[",
"k",
"]",
".",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"hashContext",
"[",
"k",
"]",
"=",
"append",
"(",
"hash",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
")",
"\n",
"}",
"else",
"{",
"p",
".",
"panicf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"keyContext",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"p",
".",
"setValue",
"(",
"key",
"[",
"len",
"(",
"key",
")",
"-",
"1",
"]",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
")",
"\n",
"}",
"\n",
"p",
".",
"context",
"=",
"append",
"(",
"p",
".",
"context",
",",
"key",
"[",
"len",
"(",
"key",
")",
"-",
"1",
"]",
")",
"\n",
"}"
]
| // establishContext sets the current context of the parser,
// where the context is either a hash or an array of hashes. Which one is
// set depends on the value of the `array` parameter.
//
// Establishing the context also makes sure that the key isn't a duplicate, and
// will create implicit hashes automatically. | [
"establishContext",
"sets",
"the",
"current",
"context",
"of",
"the",
"parser",
"where",
"the",
"context",
"is",
"either",
"a",
"hash",
"or",
"an",
"array",
"of",
"hashes",
".",
"Which",
"one",
"is",
"set",
"depends",
"on",
"the",
"value",
"of",
"the",
"array",
"parameter",
".",
"Establishing",
"the",
"context",
"also",
"makes",
"sure",
"that",
"the",
"key",
"isn",
"t",
"a",
"duplicate",
"and",
"will",
"create",
"implicit",
"hashes",
"automatically",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/parse.go#L347-L401 |
146,478 | BurntSushi/toml | parse.go | setValue | func (p *parser) setValue(key string, value interface{}) {
var tmpHash interface{}
var ok bool
hash := p.mapping
keyContext := make(Key, 0)
for _, k := range p.context {
keyContext = append(keyContext, k)
if tmpHash, ok = hash[k]; !ok {
p.bug("Context for key '%s' has not been established.", keyContext)
}
switch t := tmpHash.(type) {
case []map[string]interface{}:
// The context is a table of hashes. Pick the most recent table
// defined as the current hash.
hash = t[len(t)-1]
case map[string]interface{}:
hash = t
default:
p.bug("Expected hash to have type 'map[string]interface{}', but "+
"it has '%T' instead.", tmpHash)
}
}
keyContext = append(keyContext, key)
if _, ok := hash[key]; ok {
// Typically, if the given key has already been set, then we have
// to raise an error since duplicate keys are disallowed. However,
// it's possible that a key was previously defined implicitly. In this
// case, it is allowed to be redefined concretely. (See the
// `tests/valid/implicit-and-explicit-after.toml` test in `toml-test`.)
//
// But we have to make sure to stop marking it as an implicit. (So that
// another redefinition provokes an error.)
//
// Note that since it has already been defined (as a hash), we don't
// want to overwrite it. So our business is done.
if p.isImplicit(keyContext) {
p.removeImplicit(keyContext)
return
}
// Otherwise, we have a concrete key trying to override a previous
// key, which is *always* wrong.
p.panicf("Key '%s' has already been defined.", keyContext)
}
hash[key] = value
} | go | func (p *parser) setValue(key string, value interface{}) {
var tmpHash interface{}
var ok bool
hash := p.mapping
keyContext := make(Key, 0)
for _, k := range p.context {
keyContext = append(keyContext, k)
if tmpHash, ok = hash[k]; !ok {
p.bug("Context for key '%s' has not been established.", keyContext)
}
switch t := tmpHash.(type) {
case []map[string]interface{}:
// The context is a table of hashes. Pick the most recent table
// defined as the current hash.
hash = t[len(t)-1]
case map[string]interface{}:
hash = t
default:
p.bug("Expected hash to have type 'map[string]interface{}', but "+
"it has '%T' instead.", tmpHash)
}
}
keyContext = append(keyContext, key)
if _, ok := hash[key]; ok {
// Typically, if the given key has already been set, then we have
// to raise an error since duplicate keys are disallowed. However,
// it's possible that a key was previously defined implicitly. In this
// case, it is allowed to be redefined concretely. (See the
// `tests/valid/implicit-and-explicit-after.toml` test in `toml-test`.)
//
// But we have to make sure to stop marking it as an implicit. (So that
// another redefinition provokes an error.)
//
// Note that since it has already been defined (as a hash), we don't
// want to overwrite it. So our business is done.
if p.isImplicit(keyContext) {
p.removeImplicit(keyContext)
return
}
// Otherwise, we have a concrete key trying to override a previous
// key, which is *always* wrong.
p.panicf("Key '%s' has already been defined.", keyContext)
}
hash[key] = value
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"setValue",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"var",
"tmpHash",
"interface",
"{",
"}",
"\n",
"var",
"ok",
"bool",
"\n\n",
"hash",
":=",
"p",
".",
"mapping",
"\n",
"keyContext",
":=",
"make",
"(",
"Key",
",",
"0",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"p",
".",
"context",
"{",
"keyContext",
"=",
"append",
"(",
"keyContext",
",",
"k",
")",
"\n",
"if",
"tmpHash",
",",
"ok",
"=",
"hash",
"[",
"k",
"]",
";",
"!",
"ok",
"{",
"p",
".",
"bug",
"(",
"\"",
"\"",
",",
"keyContext",
")",
"\n",
"}",
"\n",
"switch",
"t",
":=",
"tmpHash",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
":",
"// The context is a table of hashes. Pick the most recent table",
"// defined as the current hash.",
"hash",
"=",
"t",
"[",
"len",
"(",
"t",
")",
"-",
"1",
"]",
"\n",
"case",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
":",
"hash",
"=",
"t",
"\n",
"default",
":",
"p",
".",
"bug",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"tmpHash",
")",
"\n",
"}",
"\n",
"}",
"\n",
"keyContext",
"=",
"append",
"(",
"keyContext",
",",
"key",
")",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"hash",
"[",
"key",
"]",
";",
"ok",
"{",
"// Typically, if the given key has already been set, then we have",
"// to raise an error since duplicate keys are disallowed. However,",
"// it's possible that a key was previously defined implicitly. In this",
"// case, it is allowed to be redefined concretely. (See the",
"// `tests/valid/implicit-and-explicit-after.toml` test in `toml-test`.)",
"//",
"// But we have to make sure to stop marking it as an implicit. (So that",
"// another redefinition provokes an error.)",
"//",
"// Note that since it has already been defined (as a hash), we don't",
"// want to overwrite it. So our business is done.",
"if",
"p",
".",
"isImplicit",
"(",
"keyContext",
")",
"{",
"p",
".",
"removeImplicit",
"(",
"keyContext",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Otherwise, we have a concrete key trying to override a previous",
"// key, which is *always* wrong.",
"p",
".",
"panicf",
"(",
"\"",
"\"",
",",
"keyContext",
")",
"\n",
"}",
"\n",
"hash",
"[",
"key",
"]",
"=",
"value",
"\n",
"}"
]
| // setValue sets the given key to the given value in the current context.
// It will make sure that the key hasn't already been defined, account for
// implicit key groups. | [
"setValue",
"sets",
"the",
"given",
"key",
"to",
"the",
"given",
"value",
"in",
"the",
"current",
"context",
".",
"It",
"will",
"make",
"sure",
"that",
"the",
"key",
"hasn",
"t",
"already",
"been",
"defined",
"account",
"for",
"implicit",
"key",
"groups",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/parse.go#L406-L453 |
146,479 | BurntSushi/toml | parse.go | addImplicit | func (p *parser) addImplicit(key Key) {
p.implicits[key.String()] = true
} | go | func (p *parser) addImplicit(key Key) {
p.implicits[key.String()] = true
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"addImplicit",
"(",
"key",
"Key",
")",
"{",
"p",
".",
"implicits",
"[",
"key",
".",
"String",
"(",
")",
"]",
"=",
"true",
"\n",
"}"
]
| // addImplicit sets the given Key as having been created implicitly. | [
"addImplicit",
"sets",
"the",
"given",
"Key",
"as",
"having",
"been",
"created",
"implicitly",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/parse.go#L472-L474 |
146,480 | BurntSushi/toml | parse.go | removeImplicit | func (p *parser) removeImplicit(key Key) {
p.implicits[key.String()] = false
} | go | func (p *parser) removeImplicit(key Key) {
p.implicits[key.String()] = false
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"removeImplicit",
"(",
"key",
"Key",
")",
"{",
"p",
".",
"implicits",
"[",
"key",
".",
"String",
"(",
")",
"]",
"=",
"false",
"\n",
"}"
]
| // removeImplicit stops tagging the given key as having been implicitly
// created. | [
"removeImplicit",
"stops",
"tagging",
"the",
"given",
"key",
"as",
"having",
"been",
"implicitly",
"created",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/parse.go#L478-L480 |
146,481 | BurntSushi/toml | parse.go | isImplicit | func (p *parser) isImplicit(key Key) bool {
return p.implicits[key.String()]
} | go | func (p *parser) isImplicit(key Key) bool {
return p.implicits[key.String()]
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"isImplicit",
"(",
"key",
"Key",
")",
"bool",
"{",
"return",
"p",
".",
"implicits",
"[",
"key",
".",
"String",
"(",
")",
"]",
"\n",
"}"
]
| // isImplicit returns true if the key group pointed to by the key was created
// implicitly. | [
"isImplicit",
"returns",
"true",
"if",
"the",
"key",
"group",
"pointed",
"to",
"by",
"the",
"key",
"was",
"created",
"implicitly",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/parse.go#L484-L486 |
146,482 | BurntSushi/toml | parse.go | current | func (p *parser) current() string {
if len(p.currentKey) == 0 {
return p.context.String()
}
if len(p.context) == 0 {
return p.currentKey
}
return fmt.Sprintf("%s.%s", p.context, p.currentKey)
} | go | func (p *parser) current() string {
if len(p.currentKey) == 0 {
return p.context.String()
}
if len(p.context) == 0 {
return p.currentKey
}
return fmt.Sprintf("%s.%s", p.context, p.currentKey)
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"current",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"p",
".",
"currentKey",
")",
"==",
"0",
"{",
"return",
"p",
".",
"context",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"p",
".",
"context",
")",
"==",
"0",
"{",
"return",
"p",
".",
"currentKey",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"context",
",",
"p",
".",
"currentKey",
")",
"\n",
"}"
]
| // current returns the full key name of the current context. | [
"current",
"returns",
"the",
"full",
"key",
"name",
"of",
"the",
"current",
"context",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/parse.go#L489-L497 |
146,483 | BurntSushi/toml | type_check.go | typeOfArray | func (p *parser) typeOfArray(types []tomlType) tomlType {
// Empty arrays are cool.
if len(types) == 0 {
return tomlArray
}
theType := types[0]
for _, t := range types[1:] {
if !typeEqual(theType, t) {
p.panicf("Array contains values of type '%s' and '%s', but "+
"arrays must be homogeneous.", theType, t)
}
}
return tomlArray
} | go | func (p *parser) typeOfArray(types []tomlType) tomlType {
// Empty arrays are cool.
if len(types) == 0 {
return tomlArray
}
theType := types[0]
for _, t := range types[1:] {
if !typeEqual(theType, t) {
p.panicf("Array contains values of type '%s' and '%s', but "+
"arrays must be homogeneous.", theType, t)
}
}
return tomlArray
} | [
"func",
"(",
"p",
"*",
"parser",
")",
"typeOfArray",
"(",
"types",
"[",
"]",
"tomlType",
")",
"tomlType",
"{",
"// Empty arrays are cool.",
"if",
"len",
"(",
"types",
")",
"==",
"0",
"{",
"return",
"tomlArray",
"\n",
"}",
"\n\n",
"theType",
":=",
"types",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"types",
"[",
"1",
":",
"]",
"{",
"if",
"!",
"typeEqual",
"(",
"theType",
",",
"t",
")",
"{",
"p",
".",
"panicf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"theType",
",",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"tomlArray",
"\n",
"}"
]
| // typeOfArray returns a tomlType for an array given a list of types of its
// values.
//
// In the current spec, if an array is homogeneous, then its type is always
// "Array". If the array is not homogeneous, an error is generated. | [
"typeOfArray",
"returns",
"a",
"tomlType",
"for",
"an",
"array",
"given",
"a",
"list",
"of",
"types",
"of",
"its",
"values",
".",
"In",
"the",
"current",
"spec",
"if",
"an",
"array",
"is",
"homogeneous",
"then",
"its",
"type",
"is",
"always",
"Array",
".",
"If",
"the",
"array",
"is",
"not",
"homogeneous",
"an",
"error",
"is",
"generated",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/type_check.go#L77-L91 |
146,484 | BurntSushi/toml | decode_meta.go | Type | func (md *MetaData) Type(key ...string) string {
fullkey := strings.Join(key, ".")
if typ, ok := md.types[fullkey]; ok {
return typ.typeString()
}
return ""
} | go | func (md *MetaData) Type(key ...string) string {
fullkey := strings.Join(key, ".")
if typ, ok := md.types[fullkey]; ok {
return typ.typeString()
}
return ""
} | [
"func",
"(",
"md",
"*",
"MetaData",
")",
"Type",
"(",
"key",
"...",
"string",
")",
"string",
"{",
"fullkey",
":=",
"strings",
".",
"Join",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"if",
"typ",
",",
"ok",
":=",
"md",
".",
"types",
"[",
"fullkey",
"]",
";",
"ok",
"{",
"return",
"typ",
".",
"typeString",
"(",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // Type returns a string representation of the type of the key specified.
//
// Type will return the empty string if given an empty key or a key that
// does not exist. Keys are case sensitive. | [
"Type",
"returns",
"a",
"string",
"representation",
"of",
"the",
"type",
"of",
"the",
"key",
"specified",
".",
"Type",
"will",
"return",
"the",
"empty",
"string",
"if",
"given",
"an",
"empty",
"key",
"or",
"a",
"key",
"that",
"does",
"not",
"exist",
".",
"Keys",
"are",
"case",
"sensitive",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/decode_meta.go#L46-L52 |
146,485 | BurntSushi/toml | decode_meta.go | Undecoded | func (md *MetaData) Undecoded() []Key {
undecoded := make([]Key, 0, len(md.keys))
for _, key := range md.keys {
if !md.decoded[key.String()] {
undecoded = append(undecoded, key)
}
}
return undecoded
} | go | func (md *MetaData) Undecoded() []Key {
undecoded := make([]Key, 0, len(md.keys))
for _, key := range md.keys {
if !md.decoded[key.String()] {
undecoded = append(undecoded, key)
}
}
return undecoded
} | [
"func",
"(",
"md",
"*",
"MetaData",
")",
"Undecoded",
"(",
")",
"[",
"]",
"Key",
"{",
"undecoded",
":=",
"make",
"(",
"[",
"]",
"Key",
",",
"0",
",",
"len",
"(",
"md",
".",
"keys",
")",
")",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"md",
".",
"keys",
"{",
"if",
"!",
"md",
".",
"decoded",
"[",
"key",
".",
"String",
"(",
")",
"]",
"{",
"undecoded",
"=",
"append",
"(",
"undecoded",
",",
"key",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"undecoded",
"\n",
"}"
]
| // Undecoded returns all keys that have not been decoded in the order in which
// they appear in the original TOML document.
//
// This includes keys that haven't been decoded because of a Primitive value.
// Once the Primitive value is decoded, the keys will be considered decoded.
//
// Also note that decoding into an empty interface will result in no decoding,
// and so no keys will be considered decoded.
//
// In this sense, the Undecoded keys correspond to keys in the TOML document
// that do not have a concrete type in your representation. | [
"Undecoded",
"returns",
"all",
"keys",
"that",
"have",
"not",
"been",
"decoded",
"in",
"the",
"order",
"in",
"which",
"they",
"appear",
"in",
"the",
"original",
"TOML",
"document",
".",
"This",
"includes",
"keys",
"that",
"haven",
"t",
"been",
"decoded",
"because",
"of",
"a",
"Primitive",
"value",
".",
"Once",
"the",
"Primitive",
"value",
"is",
"decoded",
"the",
"keys",
"will",
"be",
"considered",
"decoded",
".",
"Also",
"note",
"that",
"decoding",
"into",
"an",
"empty",
"interface",
"will",
"result",
"in",
"no",
"decoding",
"and",
"so",
"no",
"keys",
"will",
"be",
"considered",
"decoded",
".",
"In",
"this",
"sense",
"the",
"Undecoded",
"keys",
"correspond",
"to",
"keys",
"in",
"the",
"TOML",
"document",
"that",
"do",
"not",
"have",
"a",
"concrete",
"type",
"in",
"your",
"representation",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/decode_meta.go#L113-L121 |
146,486 | BurntSushi/toml | lex.go | backup | func (lx *lexer) backup() {
if lx.atEOF {
lx.atEOF = false
return
}
if lx.nprev < 1 {
panic("backed up too far")
}
w := lx.prevWidths[0]
lx.prevWidths[0] = lx.prevWidths[1]
lx.prevWidths[1] = lx.prevWidths[2]
lx.nprev--
lx.pos -= w
if lx.pos < len(lx.input) && lx.input[lx.pos] == '\n' {
lx.line--
}
} | go | func (lx *lexer) backup() {
if lx.atEOF {
lx.atEOF = false
return
}
if lx.nprev < 1 {
panic("backed up too far")
}
w := lx.prevWidths[0]
lx.prevWidths[0] = lx.prevWidths[1]
lx.prevWidths[1] = lx.prevWidths[2]
lx.nprev--
lx.pos -= w
if lx.pos < len(lx.input) && lx.input[lx.pos] == '\n' {
lx.line--
}
} | [
"func",
"(",
"lx",
"*",
"lexer",
")",
"backup",
"(",
")",
"{",
"if",
"lx",
".",
"atEOF",
"{",
"lx",
".",
"atEOF",
"=",
"false",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"lx",
".",
"nprev",
"<",
"1",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"w",
":=",
"lx",
".",
"prevWidths",
"[",
"0",
"]",
"\n",
"lx",
".",
"prevWidths",
"[",
"0",
"]",
"=",
"lx",
".",
"prevWidths",
"[",
"1",
"]",
"\n",
"lx",
".",
"prevWidths",
"[",
"1",
"]",
"=",
"lx",
".",
"prevWidths",
"[",
"2",
"]",
"\n",
"lx",
".",
"nprev",
"--",
"\n",
"lx",
".",
"pos",
"-=",
"w",
"\n",
"if",
"lx",
".",
"pos",
"<",
"len",
"(",
"lx",
".",
"input",
")",
"&&",
"lx",
".",
"input",
"[",
"lx",
".",
"pos",
"]",
"==",
"'\\n'",
"{",
"lx",
".",
"line",
"--",
"\n",
"}",
"\n",
"}"
]
| // backup steps back one rune. Can be called only twice between calls to next. | [
"backup",
"steps",
"back",
"one",
"rune",
".",
"Can",
"be",
"called",
"only",
"twice",
"between",
"calls",
"to",
"next",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L167-L183 |
146,487 | BurntSushi/toml | lex.go | accept | func (lx *lexer) accept(valid rune) bool {
if lx.next() == valid {
return true
}
lx.backup()
return false
} | go | func (lx *lexer) accept(valid rune) bool {
if lx.next() == valid {
return true
}
lx.backup()
return false
} | [
"func",
"(",
"lx",
"*",
"lexer",
")",
"accept",
"(",
"valid",
"rune",
")",
"bool",
"{",
"if",
"lx",
".",
"next",
"(",
")",
"==",
"valid",
"{",
"return",
"true",
"\n",
"}",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"return",
"false",
"\n",
"}"
]
| // accept consumes the next rune if it's equal to `valid`. | [
"accept",
"consumes",
"the",
"next",
"rune",
"if",
"it",
"s",
"equal",
"to",
"valid",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L186-L192 |
146,488 | BurntSushi/toml | lex.go | skip | func (lx *lexer) skip(pred func(rune) bool) {
for {
r := lx.next()
if pred(r) {
continue
}
lx.backup()
lx.ignore()
return
}
} | go | func (lx *lexer) skip(pred func(rune) bool) {
for {
r := lx.next()
if pred(r) {
continue
}
lx.backup()
lx.ignore()
return
}
} | [
"func",
"(",
"lx",
"*",
"lexer",
")",
"skip",
"(",
"pred",
"func",
"(",
"rune",
")",
"bool",
")",
"{",
"for",
"{",
"r",
":=",
"lx",
".",
"next",
"(",
")",
"\n",
"if",
"pred",
"(",
"r",
")",
"{",
"continue",
"\n",
"}",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"ignore",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
]
| // skip ignores all input that matches the given predicate. | [
"skip",
"ignores",
"all",
"input",
"that",
"matches",
"the",
"given",
"predicate",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L202-L212 |
146,489 | BurntSushi/toml | lex.go | lexTop | func lexTop(lx *lexer) stateFn {
r := lx.next()
if isWhitespace(r) || isNL(r) {
return lexSkip(lx, lexTop)
}
switch r {
case commentStart:
lx.push(lexTop)
return lexCommentStart
case tableStart:
return lexTableStart
case eof:
if lx.pos > lx.start {
return lx.errorf("unexpected EOF")
}
lx.emit(itemEOF)
return nil
}
// At this point, the only valid item can be a key, so we back up
// and let the key lexer do the rest.
lx.backup()
lx.push(lexTopEnd)
return lexKeyStart
} | go | func lexTop(lx *lexer) stateFn {
r := lx.next()
if isWhitespace(r) || isNL(r) {
return lexSkip(lx, lexTop)
}
switch r {
case commentStart:
lx.push(lexTop)
return lexCommentStart
case tableStart:
return lexTableStart
case eof:
if lx.pos > lx.start {
return lx.errorf("unexpected EOF")
}
lx.emit(itemEOF)
return nil
}
// At this point, the only valid item can be a key, so we back up
// and let the key lexer do the rest.
lx.backup()
lx.push(lexTopEnd)
return lexKeyStart
} | [
"func",
"lexTop",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"r",
":=",
"lx",
".",
"next",
"(",
")",
"\n",
"if",
"isWhitespace",
"(",
"r",
")",
"||",
"isNL",
"(",
"r",
")",
"{",
"return",
"lexSkip",
"(",
"lx",
",",
"lexTop",
")",
"\n",
"}",
"\n",
"switch",
"r",
"{",
"case",
"commentStart",
":",
"lx",
".",
"push",
"(",
"lexTop",
")",
"\n",
"return",
"lexCommentStart",
"\n",
"case",
"tableStart",
":",
"return",
"lexTableStart",
"\n",
"case",
"eof",
":",
"if",
"lx",
".",
"pos",
">",
"lx",
".",
"start",
"{",
"return",
"lx",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"lx",
".",
"emit",
"(",
"itemEOF",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// At this point, the only valid item can be a key, so we back up",
"// and let the key lexer do the rest.",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"push",
"(",
"lexTopEnd",
")",
"\n",
"return",
"lexKeyStart",
"\n",
"}"
]
| // lexTop consumes elements at the top level of TOML data. | [
"lexTop",
"consumes",
"elements",
"at",
"the",
"top",
"level",
"of",
"TOML",
"data",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L227-L251 |
146,490 | BurntSushi/toml | lex.go | lexBareTableName | func lexBareTableName(lx *lexer) stateFn {
r := lx.next()
if isBareKeyChar(r) {
return lexBareTableName
}
lx.backup()
lx.emit(itemText)
return lexTableNameEnd
} | go | func lexBareTableName(lx *lexer) stateFn {
r := lx.next()
if isBareKeyChar(r) {
return lexBareTableName
}
lx.backup()
lx.emit(itemText)
return lexTableNameEnd
} | [
"func",
"lexBareTableName",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"r",
":=",
"lx",
".",
"next",
"(",
")",
"\n",
"if",
"isBareKeyChar",
"(",
"r",
")",
"{",
"return",
"lexBareTableName",
"\n",
"}",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemText",
")",
"\n",
"return",
"lexTableNameEnd",
"\n",
"}"
]
| // lexBareTableName lexes the name of a table. It assumes that at least one
// valid character for the table has already been read. | [
"lexBareTableName",
"lexes",
"the",
"name",
"of",
"a",
"table",
".",
"It",
"assumes",
"that",
"at",
"least",
"one",
"valid",
"character",
"for",
"the",
"table",
"has",
"already",
"been",
"read",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L327-L335 |
146,491 | BurntSushi/toml | lex.go | lexTableNameEnd | func lexTableNameEnd(lx *lexer) stateFn {
lx.skip(isWhitespace)
switch r := lx.next(); {
case isWhitespace(r):
return lexTableNameEnd
case r == tableSep:
lx.ignore()
return lexTableNameStart
case r == tableEnd:
return lx.pop()
default:
return lx.errorf("expected '.' or ']' to end table name, "+
"but got %q instead", r)
}
} | go | func lexTableNameEnd(lx *lexer) stateFn {
lx.skip(isWhitespace)
switch r := lx.next(); {
case isWhitespace(r):
return lexTableNameEnd
case r == tableSep:
lx.ignore()
return lexTableNameStart
case r == tableEnd:
return lx.pop()
default:
return lx.errorf("expected '.' or ']' to end table name, "+
"but got %q instead", r)
}
} | [
"func",
"lexTableNameEnd",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"lx",
".",
"skip",
"(",
"isWhitespace",
")",
"\n",
"switch",
"r",
":=",
"lx",
".",
"next",
"(",
")",
";",
"{",
"case",
"isWhitespace",
"(",
"r",
")",
":",
"return",
"lexTableNameEnd",
"\n",
"case",
"r",
"==",
"tableSep",
":",
"lx",
".",
"ignore",
"(",
")",
"\n",
"return",
"lexTableNameStart",
"\n",
"case",
"r",
"==",
"tableEnd",
":",
"return",
"lx",
".",
"pop",
"(",
")",
"\n",
"default",
":",
"return",
"lx",
".",
"errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"}"
]
| // lexTableNameEnd reads the end of a piece of a table name, optionally
// consuming whitespace. | [
"lexTableNameEnd",
"reads",
"the",
"end",
"of",
"a",
"piece",
"of",
"a",
"table",
"name",
"optionally",
"consuming",
"whitespace",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L339-L353 |
146,492 | BurntSushi/toml | lex.go | lexKeyStart | func lexKeyStart(lx *lexer) stateFn {
r := lx.peek()
switch {
case r == keySep:
return lx.errorf("unexpected key separator %q", keySep)
case isWhitespace(r) || isNL(r):
lx.next()
return lexSkip(lx, lexKeyStart)
case r == stringStart || r == rawStringStart:
lx.ignore()
lx.emit(itemKeyStart)
lx.push(lexKeyEnd)
return lexValue // reuse string lexing
default:
lx.ignore()
lx.emit(itemKeyStart)
return lexBareKey
}
} | go | func lexKeyStart(lx *lexer) stateFn {
r := lx.peek()
switch {
case r == keySep:
return lx.errorf("unexpected key separator %q", keySep)
case isWhitespace(r) || isNL(r):
lx.next()
return lexSkip(lx, lexKeyStart)
case r == stringStart || r == rawStringStart:
lx.ignore()
lx.emit(itemKeyStart)
lx.push(lexKeyEnd)
return lexValue // reuse string lexing
default:
lx.ignore()
lx.emit(itemKeyStart)
return lexBareKey
}
} | [
"func",
"lexKeyStart",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"r",
":=",
"lx",
".",
"peek",
"(",
")",
"\n",
"switch",
"{",
"case",
"r",
"==",
"keySep",
":",
"return",
"lx",
".",
"errorf",
"(",
"\"",
"\"",
",",
"keySep",
")",
"\n",
"case",
"isWhitespace",
"(",
"r",
")",
"||",
"isNL",
"(",
"r",
")",
":",
"lx",
".",
"next",
"(",
")",
"\n",
"return",
"lexSkip",
"(",
"lx",
",",
"lexKeyStart",
")",
"\n",
"case",
"r",
"==",
"stringStart",
"||",
"r",
"==",
"rawStringStart",
":",
"lx",
".",
"ignore",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemKeyStart",
")",
"\n",
"lx",
".",
"push",
"(",
"lexKeyEnd",
")",
"\n",
"return",
"lexValue",
"// reuse string lexing",
"\n",
"default",
":",
"lx",
".",
"ignore",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemKeyStart",
")",
"\n",
"return",
"lexBareKey",
"\n",
"}",
"\n",
"}"
]
| // lexKeyStart consumes a key name up until the first non-whitespace character.
// lexKeyStart will ignore whitespace. | [
"lexKeyStart",
"consumes",
"a",
"key",
"name",
"up",
"until",
"the",
"first",
"non",
"-",
"whitespace",
"character",
".",
"lexKeyStart",
"will",
"ignore",
"whitespace",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L357-L375 |
146,493 | BurntSushi/toml | lex.go | lexArrayValue | func lexArrayValue(lx *lexer) stateFn {
r := lx.next()
switch {
case isWhitespace(r) || isNL(r):
return lexSkip(lx, lexArrayValue)
case r == commentStart:
lx.push(lexArrayValue)
return lexCommentStart
case r == comma:
return lx.errorf("unexpected comma")
case r == arrayEnd:
// NOTE(caleb): The spec isn't clear about whether you can have
// a trailing comma or not, so we'll allow it.
return lexArrayEnd
}
lx.backup()
lx.push(lexArrayValueEnd)
return lexValue
} | go | func lexArrayValue(lx *lexer) stateFn {
r := lx.next()
switch {
case isWhitespace(r) || isNL(r):
return lexSkip(lx, lexArrayValue)
case r == commentStart:
lx.push(lexArrayValue)
return lexCommentStart
case r == comma:
return lx.errorf("unexpected comma")
case r == arrayEnd:
// NOTE(caleb): The spec isn't clear about whether you can have
// a trailing comma or not, so we'll allow it.
return lexArrayEnd
}
lx.backup()
lx.push(lexArrayValueEnd)
return lexValue
} | [
"func",
"lexArrayValue",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"r",
":=",
"lx",
".",
"next",
"(",
")",
"\n",
"switch",
"{",
"case",
"isWhitespace",
"(",
"r",
")",
"||",
"isNL",
"(",
"r",
")",
":",
"return",
"lexSkip",
"(",
"lx",
",",
"lexArrayValue",
")",
"\n",
"case",
"r",
"==",
"commentStart",
":",
"lx",
".",
"push",
"(",
"lexArrayValue",
")",
"\n",
"return",
"lexCommentStart",
"\n",
"case",
"r",
"==",
"comma",
":",
"return",
"lx",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"r",
"==",
"arrayEnd",
":",
"// NOTE(caleb): The spec isn't clear about whether you can have",
"// a trailing comma or not, so we'll allow it.",
"return",
"lexArrayEnd",
"\n",
"}",
"\n\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"push",
"(",
"lexArrayValueEnd",
")",
"\n",
"return",
"lexValue",
"\n",
"}"
]
| // lexArrayValue consumes one value in an array. It assumes that '[' or ','
// have already been consumed. All whitespace and newlines are ignored. | [
"lexArrayValue",
"consumes",
"one",
"value",
"in",
"an",
"array",
".",
"It",
"assumes",
"that",
"[",
"or",
"have",
"already",
"been",
"consumed",
".",
"All",
"whitespace",
"and",
"newlines",
"are",
"ignored",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L471-L490 |
146,494 | BurntSushi/toml | lex.go | lexInlineTableEnd | func lexInlineTableEnd(lx *lexer) stateFn {
lx.ignore()
lx.emit(itemInlineTableEnd)
return lx.pop()
} | go | func lexInlineTableEnd(lx *lexer) stateFn {
lx.ignore()
lx.emit(itemInlineTableEnd)
return lx.pop()
} | [
"func",
"lexInlineTableEnd",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"lx",
".",
"ignore",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemInlineTableEnd",
")",
"\n",
"return",
"lx",
".",
"pop",
"(",
")",
"\n",
"}"
]
| // lexInlineTableEnd finishes the lexing of an inline table.
// It assumes that a '}' has just been consumed. | [
"lexInlineTableEnd",
"finishes",
"the",
"lexing",
"of",
"an",
"inline",
"table",
".",
"It",
"assumes",
"that",
"a",
"}",
"has",
"just",
"been",
"consumed",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L570-L574 |
146,495 | BurntSushi/toml | lex.go | lexMultilineString | func lexMultilineString(lx *lexer) stateFn {
switch lx.next() {
case eof:
return lx.errorf("unexpected EOF")
case '\\':
return lexMultilineStringEscape
case stringEnd:
if lx.accept(stringEnd) {
if lx.accept(stringEnd) {
lx.backup()
lx.backup()
lx.backup()
lx.emit(itemMultilineString)
lx.next()
lx.next()
lx.next()
lx.ignore()
return lx.pop()
}
lx.backup()
}
}
return lexMultilineString
} | go | func lexMultilineString(lx *lexer) stateFn {
switch lx.next() {
case eof:
return lx.errorf("unexpected EOF")
case '\\':
return lexMultilineStringEscape
case stringEnd:
if lx.accept(stringEnd) {
if lx.accept(stringEnd) {
lx.backup()
lx.backup()
lx.backup()
lx.emit(itemMultilineString)
lx.next()
lx.next()
lx.next()
lx.ignore()
return lx.pop()
}
lx.backup()
}
}
return lexMultilineString
} | [
"func",
"lexMultilineString",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"switch",
"lx",
".",
"next",
"(",
")",
"{",
"case",
"eof",
":",
"return",
"lx",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"'\\\\'",
":",
"return",
"lexMultilineStringEscape",
"\n",
"case",
"stringEnd",
":",
"if",
"lx",
".",
"accept",
"(",
"stringEnd",
")",
"{",
"if",
"lx",
".",
"accept",
"(",
"stringEnd",
")",
"{",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemMultilineString",
")",
"\n",
"lx",
".",
"next",
"(",
")",
"\n",
"lx",
".",
"next",
"(",
")",
"\n",
"lx",
".",
"next",
"(",
")",
"\n",
"lx",
".",
"ignore",
"(",
")",
"\n",
"return",
"lx",
".",
"pop",
"(",
")",
"\n",
"}",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"lexMultilineString",
"\n",
"}"
]
| // lexMultilineString consumes the inner contents of a string. It assumes that
// the beginning '"""' has already been consumed and ignored. | [
"lexMultilineString",
"consumes",
"the",
"inner",
"contents",
"of",
"a",
"string",
".",
"It",
"assumes",
"that",
"the",
"beginning",
"has",
"already",
"been",
"consumed",
"and",
"ignored",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L600-L623 |
146,496 | BurntSushi/toml | lex.go | lexRawString | func lexRawString(lx *lexer) stateFn {
r := lx.next()
switch {
case r == eof:
return lx.errorf("unexpected EOF")
case isNL(r):
return lx.errorf("strings cannot contain newlines")
case r == rawStringEnd:
lx.backup()
lx.emit(itemRawString)
lx.next()
lx.ignore()
return lx.pop()
}
return lexRawString
} | go | func lexRawString(lx *lexer) stateFn {
r := lx.next()
switch {
case r == eof:
return lx.errorf("unexpected EOF")
case isNL(r):
return lx.errorf("strings cannot contain newlines")
case r == rawStringEnd:
lx.backup()
lx.emit(itemRawString)
lx.next()
lx.ignore()
return lx.pop()
}
return lexRawString
} | [
"func",
"lexRawString",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"r",
":=",
"lx",
".",
"next",
"(",
")",
"\n",
"switch",
"{",
"case",
"r",
"==",
"eof",
":",
"return",
"lx",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"isNL",
"(",
"r",
")",
":",
"return",
"lx",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"r",
"==",
"rawStringEnd",
":",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemRawString",
")",
"\n",
"lx",
".",
"next",
"(",
")",
"\n",
"lx",
".",
"ignore",
"(",
")",
"\n",
"return",
"lx",
".",
"pop",
"(",
")",
"\n",
"}",
"\n",
"return",
"lexRawString",
"\n",
"}"
]
| // lexRawString consumes a raw string. Nothing can be escaped in such a string.
// It assumes that the beginning "'" has already been consumed and ignored. | [
"lexRawString",
"consumes",
"a",
"raw",
"string",
".",
"Nothing",
"can",
"be",
"escaped",
"in",
"such",
"a",
"string",
".",
"It",
"assumes",
"that",
"the",
"beginning",
"has",
"already",
"been",
"consumed",
"and",
"ignored",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L627-L642 |
146,497 | BurntSushi/toml | lex.go | lexMultilineRawString | func lexMultilineRawString(lx *lexer) stateFn {
switch lx.next() {
case eof:
return lx.errorf("unexpected EOF")
case rawStringEnd:
if lx.accept(rawStringEnd) {
if lx.accept(rawStringEnd) {
lx.backup()
lx.backup()
lx.backup()
lx.emit(itemRawMultilineString)
lx.next()
lx.next()
lx.next()
lx.ignore()
return lx.pop()
}
lx.backup()
}
}
return lexMultilineRawString
} | go | func lexMultilineRawString(lx *lexer) stateFn {
switch lx.next() {
case eof:
return lx.errorf("unexpected EOF")
case rawStringEnd:
if lx.accept(rawStringEnd) {
if lx.accept(rawStringEnd) {
lx.backup()
lx.backup()
lx.backup()
lx.emit(itemRawMultilineString)
lx.next()
lx.next()
lx.next()
lx.ignore()
return lx.pop()
}
lx.backup()
}
}
return lexMultilineRawString
} | [
"func",
"lexMultilineRawString",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"switch",
"lx",
".",
"next",
"(",
")",
"{",
"case",
"eof",
":",
"return",
"lx",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"rawStringEnd",
":",
"if",
"lx",
".",
"accept",
"(",
"rawStringEnd",
")",
"{",
"if",
"lx",
".",
"accept",
"(",
"rawStringEnd",
")",
"{",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemRawMultilineString",
")",
"\n",
"lx",
".",
"next",
"(",
")",
"\n",
"lx",
".",
"next",
"(",
")",
"\n",
"lx",
".",
"next",
"(",
")",
"\n",
"lx",
".",
"ignore",
"(",
")",
"\n",
"return",
"lx",
".",
"pop",
"(",
")",
"\n",
"}",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"lexMultilineRawString",
"\n",
"}"
]
| // lexMultilineRawString consumes a raw string. Nothing can be escaped in such
// a string. It assumes that the beginning "'''" has already been consumed and
// ignored. | [
"lexMultilineRawString",
"consumes",
"a",
"raw",
"string",
".",
"Nothing",
"can",
"be",
"escaped",
"in",
"such",
"a",
"string",
".",
"It",
"assumes",
"that",
"the",
"beginning",
"has",
"already",
"been",
"consumed",
"and",
"ignored",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L647-L668 |
146,498 | BurntSushi/toml | lex.go | lexMultilineStringEscape | func lexMultilineStringEscape(lx *lexer) stateFn {
// Handle the special case first:
if isNL(lx.next()) {
return lexMultilineString
}
lx.backup()
lx.push(lexMultilineString)
return lexStringEscape(lx)
} | go | func lexMultilineStringEscape(lx *lexer) stateFn {
// Handle the special case first:
if isNL(lx.next()) {
return lexMultilineString
}
lx.backup()
lx.push(lexMultilineString)
return lexStringEscape(lx)
} | [
"func",
"lexMultilineStringEscape",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"// Handle the special case first:",
"if",
"isNL",
"(",
"lx",
".",
"next",
"(",
")",
")",
"{",
"return",
"lexMultilineString",
"\n",
"}",
"\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"push",
"(",
"lexMultilineString",
")",
"\n",
"return",
"lexStringEscape",
"(",
"lx",
")",
"\n",
"}"
]
| // lexMultilineStringEscape consumes an escaped character. It assumes that the
// preceding '\\' has already been consumed. | [
"lexMultilineStringEscape",
"consumes",
"an",
"escaped",
"character",
".",
"It",
"assumes",
"that",
"the",
"preceding",
"\\\\",
"has",
"already",
"been",
"consumed",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L672-L680 |
146,499 | BurntSushi/toml | lex.go | lexNumberOrDate | func lexNumberOrDate(lx *lexer) stateFn {
r := lx.next()
if isDigit(r) {
return lexNumberOrDate
}
switch r {
case '-':
return lexDatetime
case '_':
return lexNumber
case '.', 'e', 'E':
return lexFloat
}
lx.backup()
lx.emit(itemInteger)
return lx.pop()
} | go | func lexNumberOrDate(lx *lexer) stateFn {
r := lx.next()
if isDigit(r) {
return lexNumberOrDate
}
switch r {
case '-':
return lexDatetime
case '_':
return lexNumber
case '.', 'e', 'E':
return lexFloat
}
lx.backup()
lx.emit(itemInteger)
return lx.pop()
} | [
"func",
"lexNumberOrDate",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"r",
":=",
"lx",
".",
"next",
"(",
")",
"\n",
"if",
"isDigit",
"(",
"r",
")",
"{",
"return",
"lexNumberOrDate",
"\n",
"}",
"\n",
"switch",
"r",
"{",
"case",
"'-'",
":",
"return",
"lexDatetime",
"\n",
"case",
"'_'",
":",
"return",
"lexNumber",
"\n",
"case",
"'.'",
",",
"'e'",
",",
"'E'",
":",
"return",
"lexFloat",
"\n",
"}",
"\n\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemInteger",
")",
"\n",
"return",
"lx",
".",
"pop",
"(",
")",
"\n",
"}"
]
| // lexNumberOrDate consumes either an integer, float or datetime. | [
"lexNumberOrDate",
"consumes",
"either",
"an",
"integer",
"float",
"or",
"datetime",
"."
]
| 3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005 | https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L751-L768 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.