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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
152,800 | JamesClonk/vultr | cmd/cli.go | NewCLI | func NewCLI() *CLI {
c := &CLI{cli.App("vultr", "A Vultr CLI")}
apiKey = c.String(cli.StringOpt{
Name: "k api-key",
Desc: "Vultr API-Key",
EnvVar: "VULTR_API_KEY",
HideValue: true,
})
return c
} | go | func NewCLI() *CLI {
c := &CLI{cli.App("vultr", "A Vultr CLI")}
apiKey = c.String(cli.StringOpt{
Name: "k api-key",
Desc: "Vultr API-Key",
EnvVar: "VULTR_API_KEY",
HideValue: true,
})
return c
} | [
"func",
"NewCLI",
"(",
")",
"*",
"CLI",
"{",
"c",
":=",
"&",
"CLI",
"{",
"cli",
".",
"App",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"}",
"\n\n",
"apiKey",
"=",
"c",
".",
"String",
"(",
"cli",
".",
"StringOpt",
"{",
"Name",
":",
"\"",
"\"",
"... | // NewCLI initializes new command line interface | [
"NewCLI",
"initializes",
"new",
"command",
"line",
"interface"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/cmd/cli.go#L13-L24 |
152,801 | JamesClonk/vultr | lib/snapshots.go | GetSnapshots | func (c *Client) GetSnapshots() (snapshotList []Snapshot, err error) {
var snapshotMap map[string]Snapshot
if err := c.get(`snapshot/list`, &snapshotMap); err != nil {
return nil, err
}
for _, snapshot := range snapshotMap {
snapshotList = append(snapshotList, snapshot)
}
sort.Sort(snapshots(snapshotList))
return snapshotList, nil
} | go | func (c *Client) GetSnapshots() (snapshotList []Snapshot, err error) {
var snapshotMap map[string]Snapshot
if err := c.get(`snapshot/list`, &snapshotMap); err != nil {
return nil, err
}
for _, snapshot := range snapshotMap {
snapshotList = append(snapshotList, snapshot)
}
sort.Sort(snapshots(snapshotList))
return snapshotList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetSnapshots",
"(",
")",
"(",
"snapshotList",
"[",
"]",
"Snapshot",
",",
"err",
"error",
")",
"{",
"var",
"snapshotMap",
"map",
"[",
"string",
"]",
"Snapshot",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`... | // GetSnapshots retrieves a list of all snapshots on Vultr account | [
"GetSnapshots",
"retrieves",
"a",
"list",
"of",
"all",
"snapshots",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/snapshots.go#L35-L46 |
152,802 | JamesClonk/vultr | lib/snapshots.go | CreateSnapshot | func (c *Client) CreateSnapshot(id, description string) (Snapshot, error) {
values := url.Values{
"SUBID": {id},
"description": {description},
}
var snapshot Snapshot
if err := c.post(`snapshot/create`, values, &snapshot); err != nil {
return Snapshot{}, err
}
snapshot.Description = description
return snapshot, nil
} | go | func (c *Client) CreateSnapshot(id, description string) (Snapshot, error) {
values := url.Values{
"SUBID": {id},
"description": {description},
}
var snapshot Snapshot
if err := c.post(`snapshot/create`, values, &snapshot); err != nil {
return Snapshot{}, err
}
snapshot.Description = description
return snapshot, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateSnapshot",
"(",
"id",
",",
"description",
"string",
")",
"(",
"Snapshot",
",",
"error",
")",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
... | // CreateSnapshot creates a new virtual machine snapshot | [
"CreateSnapshot",
"creates",
"a",
"new",
"virtual",
"machine",
"snapshot"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/snapshots.go#L49-L62 |
152,803 | JamesClonk/vultr | lib/scripts.go | UnmarshalJSON | func (s *StartupScript) UnmarshalJSON(data []byte) (err error) {
if s == nil {
*s = StartupScript{}
}
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
s.ID = fmt.Sprintf("%v", fields["SCRIPTID"])
s.Name = fmt.Sprintf("%v", fields["name"])
s.Type = fmt.Sprintf("%v", fields["type"])
s.Content = fmt.Sprintf("%v", fields["script"])
return
} | go | func (s *StartupScript) UnmarshalJSON(data []byte) (err error) {
if s == nil {
*s = StartupScript{}
}
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
s.ID = fmt.Sprintf("%v", fields["SCRIPTID"])
s.Name = fmt.Sprintf("%v", fields["name"])
s.Type = fmt.Sprintf("%v", fields["type"])
s.Content = fmt.Sprintf("%v", fields["script"])
return
} | [
"func",
"(",
"s",
"*",
"StartupScript",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"*",
"s",
"=",
"StartupScript",
"{",
"}",
"\n",
"}",
"\n\n",
"var",
"fields",
"map",
"["... | // UnmarshalJSON implements json.Unmarshaller on StartupScript.
// Necessary because the SCRIPTID field has inconsistent types. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaller",
"on",
"StartupScript",
".",
"Necessary",
"because",
"the",
"SCRIPTID",
"field",
"has",
"inconsistent",
"types",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L29-L45 |
152,804 | JamesClonk/vultr | lib/scripts.go | GetStartupScripts | func (c *Client) GetStartupScripts() (scripts []StartupScript, err error) {
var scriptMap map[string]StartupScript
if err := c.get(`startupscript/list`, &scriptMap); err != nil {
return nil, err
}
for _, script := range scriptMap {
if script.Type == "" {
script.Type = "boot" // set default script type
}
scripts = append(scripts, script)
}
sort.Sort(startupscripts(scripts))
return scripts, nil
} | go | func (c *Client) GetStartupScripts() (scripts []StartupScript, err error) {
var scriptMap map[string]StartupScript
if err := c.get(`startupscript/list`, &scriptMap); err != nil {
return nil, err
}
for _, script := range scriptMap {
if script.Type == "" {
script.Type = "boot" // set default script type
}
scripts = append(scripts, script)
}
sort.Sort(startupscripts(scripts))
return scripts, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetStartupScripts",
"(",
")",
"(",
"scripts",
"[",
"]",
"StartupScript",
",",
"err",
"error",
")",
"{",
"var",
"scriptMap",
"map",
"[",
"string",
"]",
"StartupScript",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"... | // GetStartupScripts returns a list of all startup scripts on the current Vultr account | [
"GetStartupScripts",
"returns",
"a",
"list",
"of",
"all",
"startup",
"scripts",
"on",
"the",
"current",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L48-L62 |
152,805 | JamesClonk/vultr | lib/scripts.go | GetStartupScript | func (c *Client) GetStartupScript(id string) (StartupScript, error) {
scripts, err := c.GetStartupScripts()
if err != nil {
return StartupScript{}, err
}
for _, s := range scripts {
if s.ID == id {
return s, nil
}
}
return StartupScript{}, nil
} | go | func (c *Client) GetStartupScript(id string) (StartupScript, error) {
scripts, err := c.GetStartupScripts()
if err != nil {
return StartupScript{}, err
}
for _, s := range scripts {
if s.ID == id {
return s, nil
}
}
return StartupScript{}, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetStartupScript",
"(",
"id",
"string",
")",
"(",
"StartupScript",
",",
"error",
")",
"{",
"scripts",
",",
"err",
":=",
"c",
".",
"GetStartupScripts",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"St... | // GetStartupScript returns the startup script with the given ID | [
"GetStartupScript",
"returns",
"the",
"startup",
"script",
"with",
"the",
"given",
"ID"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L65-L77 |
152,806 | JamesClonk/vultr | lib/scripts.go | CreateStartupScript | func (c *Client) CreateStartupScript(name, content, scriptType string) (StartupScript, error) {
values := url.Values{
"name": {name},
"script": {content},
"type": {scriptType},
}
var script StartupScript
if err := c.post(`startupscript/create`, values, &script); err != nil {
return StartupScript{}, err
}
script.Name = name
script.Content = content
script.Type = scriptType
return script, nil
} | go | func (c *Client) CreateStartupScript(name, content, scriptType string) (StartupScript, error) {
values := url.Values{
"name": {name},
"script": {content},
"type": {scriptType},
}
var script StartupScript
if err := c.post(`startupscript/create`, values, &script); err != nil {
return StartupScript{}, err
}
script.Name = name
script.Content = content
script.Type = scriptType
return script, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateStartupScript",
"(",
"name",
",",
"content",
",",
"scriptType",
"string",
")",
"(",
"StartupScript",
",",
"error",
")",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"name",
"}",
",... | // CreateStartupScript creates a new startup script | [
"CreateStartupScript",
"creates",
"a",
"new",
"startup",
"script"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L80-L96 |
152,807 | JamesClonk/vultr | lib/scripts.go | UpdateStartupScript | func (c *Client) UpdateStartupScript(script StartupScript) error {
values := url.Values{
"SCRIPTID": {script.ID},
}
if script.Name != "" {
values.Add("name", script.Name)
}
if script.Content != "" {
values.Add("script", script.Content)
}
if err := c.post(`startupscript/update`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) UpdateStartupScript(script StartupScript) error {
values := url.Values{
"SCRIPTID": {script.ID},
}
if script.Name != "" {
values.Add("name", script.Name)
}
if script.Content != "" {
values.Add("script", script.Content)
}
if err := c.post(`startupscript/update`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdateStartupScript",
"(",
"script",
"StartupScript",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"script",
".",
"ID",
"}",
",",
"}",
"\n",
"if",
"script",
".",
"Name",
... | // UpdateStartupScript updates an existing startup script | [
"UpdateStartupScript",
"updates",
"an",
"existing",
"startup",
"script"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/scripts.go#L99-L114 |
152,808 | JamesClonk/vultr | lib/reservedip.go | UnmarshalJSON | func (i *IP) UnmarshalJSON(data []byte) (err error) {
if i == nil {
*i = IP{}
}
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
value := fmt.Sprintf("%v", fields["SUBID"])
if len(value) == 0 || value == "<nil>" || value == "0" {
i.ID = ""
} else {
id, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
i.ID = strconv.FormatFloat(id, 'f', -1, 64)
}
value = fmt.Sprintf("%v", fields["DCID"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
region, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
i.RegionID = int(region)
value = fmt.Sprintf("%v", fields["attached_SUBID"])
if len(value) == 0 || value == "<nil>" || value == "0" || value == "false" {
i.AttachedTo = ""
} else {
attached, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
i.AttachedTo = strconv.FormatFloat(attached, 'f', -1, 64)
}
value = fmt.Sprintf("%v", fields["subnet_size"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
size, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
i.SubnetSize = int(size)
i.IPType = fmt.Sprintf("%v", fields["ip_type"])
i.Subnet = fmt.Sprintf("%v", fields["subnet"])
i.Label = fmt.Sprintf("%v", fields["label"])
return
} | go | func (i *IP) UnmarshalJSON(data []byte) (err error) {
if i == nil {
*i = IP{}
}
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
value := fmt.Sprintf("%v", fields["SUBID"])
if len(value) == 0 || value == "<nil>" || value == "0" {
i.ID = ""
} else {
id, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
i.ID = strconv.FormatFloat(id, 'f', -1, 64)
}
value = fmt.Sprintf("%v", fields["DCID"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
region, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
i.RegionID = int(region)
value = fmt.Sprintf("%v", fields["attached_SUBID"])
if len(value) == 0 || value == "<nil>" || value == "0" || value == "false" {
i.AttachedTo = ""
} else {
attached, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
i.AttachedTo = strconv.FormatFloat(attached, 'f', -1, 64)
}
value = fmt.Sprintf("%v", fields["subnet_size"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
size, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
i.SubnetSize = int(size)
i.IPType = fmt.Sprintf("%v", fields["ip_type"])
i.Subnet = fmt.Sprintf("%v", fields["subnet"])
i.Label = fmt.Sprintf("%v", fields["label"])
return
} | [
"func",
"(",
"i",
"*",
"IP",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"i",
"==",
"nil",
"{",
"*",
"i",
"=",
"IP",
"{",
"}",
"\n",
"}",
"\n\n",
"var",
"fields",
"map",
"[",
"string",
"]",
... | // UnmarshalJSON implements json.Unmarshaller on IP.
// This is needed because the Vultr API is inconsistent in it's JSON responses.
// Some fields can change type, from JSON number to JSON string and vice-versa. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaller",
"on",
"IP",
".",
"This",
"is",
"needed",
"because",
"the",
"Vultr",
"API",
"is",
"inconsistent",
"in",
"it",
"s",
"JSON",
"responses",
".",
"Some",
"fields",
"can",
"change",
"type",
"from",
"JSON",... | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L45-L102 |
152,809 | JamesClonk/vultr | lib/reservedip.go | ListReservedIP | func (c *Client) ListReservedIP() ([]IP, error) {
var ipMap map[string]IP
err := c.get(`reservedip/list`, &ipMap)
if err != nil {
return nil, err
}
ipList := make([]IP, 0)
for _, ip := range ipMap {
ipList = append(ipList, ip)
}
sort.Sort(ips(ipList))
return ipList, nil
} | go | func (c *Client) ListReservedIP() ([]IP, error) {
var ipMap map[string]IP
err := c.get(`reservedip/list`, &ipMap)
if err != nil {
return nil, err
}
ipList := make([]IP, 0)
for _, ip := range ipMap {
ipList = append(ipList, ip)
}
sort.Sort(ips(ipList))
return ipList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListReservedIP",
"(",
")",
"(",
"[",
"]",
"IP",
",",
"error",
")",
"{",
"var",
"ipMap",
"map",
"[",
"string",
"]",
"IP",
"\n\n",
"err",
":=",
"c",
".",
"get",
"(",
"`reservedip/list`",
",",
"&",
"ipMap",
")"... | // ListReservedIP returns a list of all available reserved IPs on Vultr account | [
"ListReservedIP",
"returns",
"a",
"list",
"of",
"all",
"available",
"reserved",
"IPs",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L105-L119 |
152,810 | JamesClonk/vultr | lib/reservedip.go | GetReservedIP | func (c *Client) GetReservedIP(id string) (IP, error) {
var ipMap map[string]IP
err := c.get(`reservedip/list`, &ipMap)
if err != nil {
return IP{}, err
}
if ip, ok := ipMap[id]; ok {
return ip, nil
}
return IP{}, fmt.Errorf("IP with ID %v not found", id)
} | go | func (c *Client) GetReservedIP(id string) (IP, error) {
var ipMap map[string]IP
err := c.get(`reservedip/list`, &ipMap)
if err != nil {
return IP{}, err
}
if ip, ok := ipMap[id]; ok {
return ip, nil
}
return IP{}, fmt.Errorf("IP with ID %v not found", id)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetReservedIP",
"(",
"id",
"string",
")",
"(",
"IP",
",",
"error",
")",
"{",
"var",
"ipMap",
"map",
"[",
"string",
"]",
"IP",
"\n\n",
"err",
":=",
"c",
".",
"get",
"(",
"`reservedip/list`",
",",
"&",
"ipMap",
... | // GetReservedIP returns reserved IP with given ID | [
"GetReservedIP",
"returns",
"reserved",
"IP",
"with",
"given",
"ID"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L122-L133 |
152,811 | JamesClonk/vultr | lib/reservedip.go | CreateReservedIP | func (c *Client) CreateReservedIP(regionID int, ipType string, label string) (string, error) {
values := url.Values{
"DCID": {fmt.Sprintf("%v", regionID)},
"ip_type": {ipType},
}
if len(label) > 0 {
values.Add("label", label)
}
result := IP{}
err := c.post(`reservedip/create`, values, &result)
if err != nil {
return "", err
}
return result.ID, nil
} | go | func (c *Client) CreateReservedIP(regionID int, ipType string, label string) (string, error) {
values := url.Values{
"DCID": {fmt.Sprintf("%v", regionID)},
"ip_type": {ipType},
}
if len(label) > 0 {
values.Add("label", label)
}
result := IP{}
err := c.post(`reservedip/create`, values, &result)
if err != nil {
return "", err
}
return result.ID, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateReservedIP",
"(",
"regionID",
"int",
",",
"ipType",
"string",
",",
"label",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"fmt",
"... | // CreateReservedIP creates a new reserved IP on Vultr account | [
"CreateReservedIP",
"creates",
"a",
"new",
"reserved",
"IP",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L136-L151 |
152,812 | JamesClonk/vultr | lib/reservedip.go | AttachReservedIP | func (c *Client) AttachReservedIP(ip string, serverID string) error {
values := url.Values{
"ip_address": {ip},
"attach_SUBID": {serverID},
}
return c.post(`reservedip/attach`, values, nil)
} | go | func (c *Client) AttachReservedIP(ip string, serverID string) error {
values := url.Values{
"ip_address": {ip},
"attach_SUBID": {serverID},
}
return c.post(`reservedip/attach`, values, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"AttachReservedIP",
"(",
"ip",
"string",
",",
"serverID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"ip",
"}",
",",
"\"",
"\"",
":",
"{",
"serverID",
"}",
"... | // AttachReservedIP attaches a reserved IP to a virtual machine | [
"AttachReservedIP",
"attaches",
"a",
"reserved",
"IP",
"to",
"a",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L162-L168 |
152,813 | JamesClonk/vultr | lib/reservedip.go | ConvertReservedIP | func (c *Client) ConvertReservedIP(serverID string, ip string) (string, error) {
values := url.Values{
"SUBID": {serverID},
"ip_address": {ip},
}
result := IP{}
err := c.post(`reservedip/convert`, values, &result)
if err != nil {
return "", err
}
return result.ID, err
} | go | func (c *Client) ConvertReservedIP(serverID string, ip string) (string, error) {
values := url.Values{
"SUBID": {serverID},
"ip_address": {ip},
}
result := IP{}
err := c.post(`reservedip/convert`, values, &result)
if err != nil {
return "", err
}
return result.ID, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ConvertReservedIP",
"(",
"serverID",
"string",
",",
"ip",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"serverID",
"}",
",",
"\"",
"\""... | // ConvertReservedIP converts an existing virtual machines IP to a reserved IP | [
"ConvertReservedIP",
"converts",
"an",
"existing",
"virtual",
"machines",
"IP",
"to",
"a",
"reserved",
"IP"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/reservedip.go#L180-L192 |
152,814 | JamesClonk/vultr | lib/ip.go | ListIPv4 | func (c *Client) ListIPv4(id string) (list []IPv4, err error) {
var ipMap map[string][]IPv4
if err := c.get(`server/list_ipv4?SUBID=`+id+`&public_network=yes`, &ipMap); err != nil {
return nil, err
}
for _, iplist := range ipMap {
for _, ip := range iplist {
list = append(list, ip)
}
}
sort.Sort(ipv4s(list))
return list, nil
} | go | func (c *Client) ListIPv4(id string) (list []IPv4, err error) {
var ipMap map[string][]IPv4
if err := c.get(`server/list_ipv4?SUBID=`+id+`&public_network=yes`, &ipMap); err != nil {
return nil, err
}
for _, iplist := range ipMap {
for _, ip := range iplist {
list = append(list, ip)
}
}
sort.Sort(ipv4s(list))
return list, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListIPv4",
"(",
"id",
"string",
")",
"(",
"list",
"[",
"]",
"IPv4",
",",
"err",
"error",
")",
"{",
"var",
"ipMap",
"map",
"[",
"string",
"]",
"[",
"]",
"IPv4",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"... | // ListIPv4 lists the IPv4 information of a virtual machine | [
"ListIPv4",
"lists",
"the",
"IPv4",
"information",
"of",
"a",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L68-L81 |
152,815 | JamesClonk/vultr | lib/ip.go | CreateIPv4 | func (c *Client) CreateIPv4(id string, reboot bool) error {
values := url.Values{
"SUBID": {id},
"reboot": {fmt.Sprintf("%t", reboot)},
}
if err := c.post(`server/create_ipv4`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) CreateIPv4(id string, reboot bool) error {
values := url.Values{
"SUBID": {id},
"reboot": {fmt.Sprintf("%t", reboot)},
}
if err := c.post(`server/create_ipv4`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateIPv4",
"(",
"id",
"string",
",",
"reboot",
"bool",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"fmt",
".",
"Sprintf",
"("... | // CreateIPv4 creates an IPv4 address and attaches it to a virtual machine | [
"CreateIPv4",
"creates",
"an",
"IPv4",
"address",
"and",
"attaches",
"it",
"to",
"a",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L84-L94 |
152,816 | JamesClonk/vultr | lib/ip.go | DeleteIPv4 | func (c *Client) DeleteIPv4(id, ip string) error {
values := url.Values{
"SUBID": {id},
"ip": {ip},
}
if err := c.post(`server/destroy_ipv4`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) DeleteIPv4(id, ip string) error {
values := url.Values{
"SUBID": {id},
"ip": {ip},
}
if err := c.post(`server/destroy_ipv4`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteIPv4",
"(",
"id",
",",
"ip",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"ip",
"}",
",",
"}",
"\n\n",
"if",
... | // DeleteIPv4 deletes an IPv4 address and detaches it from a virtual machine | [
"DeleteIPv4",
"deletes",
"an",
"IPv4",
"address",
"and",
"detaches",
"it",
"from",
"a",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L97-L107 |
152,817 | JamesClonk/vultr | lib/ip.go | ListIPv6 | func (c *Client) ListIPv6(id string) (list []IPv6, err error) {
var ipMap map[string][]IPv6
if err := c.get(`server/list_ipv6?SUBID=`+id, &ipMap); err != nil {
return nil, err
}
for _, iplist := range ipMap {
for _, ip := range iplist {
list = append(list, ip)
}
}
sort.Sort(ipv6s(list))
return list, nil
} | go | func (c *Client) ListIPv6(id string) (list []IPv6, err error) {
var ipMap map[string][]IPv6
if err := c.get(`server/list_ipv6?SUBID=`+id, &ipMap); err != nil {
return nil, err
}
for _, iplist := range ipMap {
for _, ip := range iplist {
list = append(list, ip)
}
}
sort.Sort(ipv6s(list))
return list, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListIPv6",
"(",
"id",
"string",
")",
"(",
"list",
"[",
"]",
"IPv6",
",",
"err",
"error",
")",
"{",
"var",
"ipMap",
"map",
"[",
"string",
"]",
"[",
"]",
"IPv6",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"... | // ListIPv6 lists the IPv4 information of a virtual machine | [
"ListIPv6",
"lists",
"the",
"IPv4",
"information",
"of",
"a",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L110-L123 |
152,818 | JamesClonk/vultr | lib/ip.go | ListIPv6ReverseDNS | func (c *Client) ListIPv6ReverseDNS(id string) (list []ReverseDNSIPv6, err error) {
var ipMap map[string][]ReverseDNSIPv6
if err := c.get(`server/reverse_list_ipv6?SUBID=`+id, &ipMap); err != nil {
return nil, err
}
for _, iplist := range ipMap {
for _, ip := range iplist {
list = append(list, ip)
}
}
sort.Sort(reverseDNSIPv6s(list))
return list, nil
} | go | func (c *Client) ListIPv6ReverseDNS(id string) (list []ReverseDNSIPv6, err error) {
var ipMap map[string][]ReverseDNSIPv6
if err := c.get(`server/reverse_list_ipv6?SUBID=`+id, &ipMap); err != nil {
return nil, err
}
for _, iplist := range ipMap {
for _, ip := range iplist {
list = append(list, ip)
}
}
sort.Sort(reverseDNSIPv6s(list))
return list, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListIPv6ReverseDNS",
"(",
"id",
"string",
")",
"(",
"list",
"[",
"]",
"ReverseDNSIPv6",
",",
"err",
"error",
")",
"{",
"var",
"ipMap",
"map",
"[",
"string",
"]",
"[",
"]",
"ReverseDNSIPv6",
"\n",
"if",
"err",
":... | // ListIPv6ReverseDNS lists the IPv6 reverse DNS entries of a virtual machine | [
"ListIPv6ReverseDNS",
"lists",
"the",
"IPv6",
"reverse",
"DNS",
"entries",
"of",
"a",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/ip.go#L126-L139 |
152,819 | JamesClonk/vultr | lib/bare_metal_plans.go | GetBareMetalPlans | func (c *Client) GetBareMetalPlans() ([]BareMetalPlan, error) {
var bareMetalPlanMap map[string]BareMetalPlan
if err := c.get(`plans/list_baremetal`, &bareMetalPlanMap); err != nil {
return nil, err
}
var b bareMetalPlans
for _, bareMetalPlan := range bareMetalPlanMap {
b = append(b, bareMetalPlan)
}
sort.Sort(bareMetalPlans(b))
return b, nil
} | go | func (c *Client) GetBareMetalPlans() ([]BareMetalPlan, error) {
var bareMetalPlanMap map[string]BareMetalPlan
if err := c.get(`plans/list_baremetal`, &bareMetalPlanMap); err != nil {
return nil, err
}
var b bareMetalPlans
for _, bareMetalPlan := range bareMetalPlanMap {
b = append(b, bareMetalPlan)
}
sort.Sort(bareMetalPlans(b))
return b, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetBareMetalPlans",
"(",
")",
"(",
"[",
"]",
"BareMetalPlan",
",",
"error",
")",
"{",
"var",
"bareMetalPlanMap",
"map",
"[",
"string",
"]",
"BareMetalPlan",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`plans/l... | // GetBareMetalPlans returns a list of all available bare metal plans on Vultr account. | [
"GetBareMetalPlans",
"returns",
"a",
"list",
"of",
"all",
"available",
"bare",
"metal",
"plans",
"on",
"Vultr",
"account",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal_plans.go#L57-L70 |
152,820 | JamesClonk/vultr | lib/bare_metal_plans.go | GetAvailableBareMetalPlansForRegion | func (c *Client) GetAvailableBareMetalPlansForRegion(id int) ([]int, error) {
var bareMetalPlanIDs []int
if err := c.get(fmt.Sprintf(`regions/availability?DCID=%v`, id), &bareMetalPlanIDs); err != nil {
return nil, err
}
return bareMetalPlanIDs, nil
} | go | func (c *Client) GetAvailableBareMetalPlansForRegion(id int) ([]int, error) {
var bareMetalPlanIDs []int
if err := c.get(fmt.Sprintf(`regions/availability?DCID=%v`, id), &bareMetalPlanIDs); err != nil {
return nil, err
}
return bareMetalPlanIDs, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetAvailableBareMetalPlansForRegion",
"(",
"id",
"int",
")",
"(",
"[",
"]",
"int",
",",
"error",
")",
"{",
"var",
"bareMetalPlanIDs",
"[",
"]",
"int",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"fmt",
".",
... | // GetAvailableBareMetalPlansForRegion returns available bare metal plans for specified region. | [
"GetAvailableBareMetalPlansForRegion",
"returns",
"available",
"bare",
"metal",
"plans",
"for",
"specified",
"region",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal_plans.go#L73-L79 |
152,821 | JamesClonk/vultr | lib/network.go | GetNetworks | func (c *Client) GetNetworks() (nets []Network, err error) {
var netMap map[string]Network
if err := c.get(`network/list`, &netMap); err != nil {
return nil, err
}
for _, net := range netMap {
nets = append(nets, net)
}
sort.Sort(networks(nets))
return nets, nil
} | go | func (c *Client) GetNetworks() (nets []Network, err error) {
var netMap map[string]Network
if err := c.get(`network/list`, &netMap); err != nil {
return nil, err
}
for _, net := range netMap {
nets = append(nets, net)
}
sort.Sort(networks(nets))
return nets, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetNetworks",
"(",
")",
"(",
"nets",
"[",
"]",
"Network",
",",
"err",
"error",
")",
"{",
"var",
"netMap",
"map",
"[",
"string",
"]",
"Network",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`network/list`",
... | // GetNetworks returns a list of Networks from Vultr account | [
"GetNetworks",
"returns",
"a",
"list",
"of",
"Networks",
"from",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/network.go#L36-L47 |
152,822 | JamesClonk/vultr | lib/network.go | CreateNetwork | func (c *Client) CreateNetwork(regionID int, description string, subnet *net.IPNet) (Network, error) {
var net string
var mask int
values := url.Values{
"DCID": {fmt.Sprintf("%v", regionID)},
"description": {description},
}
if subnet != nil && subnet.IP.To4() != nil {
net = subnet.IP.To4().String()
mask, _ = subnet.Mask.Size()
values.Add("v4_subnet", net)
values.Add("v4_subnet_mask", fmt.Sprintf("%v", mask))
}
var network Network
if err := c.post(`network/create`, values, &network); err != nil {
return Network{}, err
}
network.RegionID = regionID
network.Description = description
network.V4Subnet = net
network.V4SubnetMask = mask
return network, nil
} | go | func (c *Client) CreateNetwork(regionID int, description string, subnet *net.IPNet) (Network, error) {
var net string
var mask int
values := url.Values{
"DCID": {fmt.Sprintf("%v", regionID)},
"description": {description},
}
if subnet != nil && subnet.IP.To4() != nil {
net = subnet.IP.To4().String()
mask, _ = subnet.Mask.Size()
values.Add("v4_subnet", net)
values.Add("v4_subnet_mask", fmt.Sprintf("%v", mask))
}
var network Network
if err := c.post(`network/create`, values, &network); err != nil {
return Network{}, err
}
network.RegionID = regionID
network.Description = description
network.V4Subnet = net
network.V4SubnetMask = mask
return network, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateNetwork",
"(",
"regionID",
"int",
",",
"description",
"string",
",",
"subnet",
"*",
"net",
".",
"IPNet",
")",
"(",
"Network",
",",
"error",
")",
"{",
"var",
"net",
"string",
"\n",
"var",
"mask",
"int",
"\n... | // CreateNetwork creates new Network on Vultr | [
"CreateNetwork",
"creates",
"new",
"Network",
"on",
"Vultr"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/network.go#L50-L73 |
152,823 | JamesClonk/vultr | lib/client.go | NewClient | func NewClient(apiKey string, options *Options) *Client {
userAgent := "vultr-go/" + Version
transport := &http.Transport{
TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper),
}
client := http.DefaultClient
client.Transport = transport
endpoint, _ := url.Parse(DefaultEndpoint)
rate := 505 * time.Millisecond
attempts := 1
if options != nil {
if options.HTTPClient != nil {
client = options.HTTPClient
}
if options.UserAgent != "" {
userAgent = options.UserAgent
}
if options.Endpoint != "" {
endpoint, _ = url.Parse(options.Endpoint)
}
if options.RateLimitation != 0 {
rate = options.RateLimitation
}
if options.MaxRetries != 0 {
attempts = options.MaxRetries + 1
}
}
return &Client{
UserAgent: userAgent,
client: client,
Endpoint: endpoint,
APIKey: apiKey,
MaxAttempts: attempts,
bucket: ratelimit.NewBucket(rate, 1),
}
} | go | func NewClient(apiKey string, options *Options) *Client {
userAgent := "vultr-go/" + Version
transport := &http.Transport{
TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper),
}
client := http.DefaultClient
client.Transport = transport
endpoint, _ := url.Parse(DefaultEndpoint)
rate := 505 * time.Millisecond
attempts := 1
if options != nil {
if options.HTTPClient != nil {
client = options.HTTPClient
}
if options.UserAgent != "" {
userAgent = options.UserAgent
}
if options.Endpoint != "" {
endpoint, _ = url.Parse(options.Endpoint)
}
if options.RateLimitation != 0 {
rate = options.RateLimitation
}
if options.MaxRetries != 0 {
attempts = options.MaxRetries + 1
}
}
return &Client{
UserAgent: userAgent,
client: client,
Endpoint: endpoint,
APIKey: apiKey,
MaxAttempts: attempts,
bucket: ratelimit.NewBucket(rate, 1),
}
} | [
"func",
"NewClient",
"(",
"apiKey",
"string",
",",
"options",
"*",
"Options",
")",
"*",
"Client",
"{",
"userAgent",
":=",
"\"",
"\"",
"+",
"Version",
"\n",
"transport",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSNextProto",
":",
"make",
"(",
"map",
... | // NewClient creates new Vultr API client. Options are optional and can be nil. | [
"NewClient",
"creates",
"new",
"Vultr",
"API",
"client",
".",
"Options",
"are",
"optional",
"and",
"can",
"be",
"nil",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/client.go#L86-L123 |
152,824 | JamesClonk/vultr | lib/client.go | backoffDuration | func backoffDuration(retryCount int) time.Duration {
// Upper limit of delay at ~1 minute
if retryCount > 7 {
retryCount = 7
}
rand.Seed(time.Now().UnixNano())
delay := (1 << uint(retryCount)) * (rand.Intn(150) + 500)
return time.Duration(delay) * time.Millisecond
} | go | func backoffDuration(retryCount int) time.Duration {
// Upper limit of delay at ~1 minute
if retryCount > 7 {
retryCount = 7
}
rand.Seed(time.Now().UnixNano())
delay := (1 << uint(retryCount)) * (rand.Intn(150) + 500)
return time.Duration(delay) * time.Millisecond
} | [
"func",
"backoffDuration",
"(",
"retryCount",
"int",
")",
"time",
".",
"Duration",
"{",
"// Upper limit of delay at ~1 minute",
"if",
"retryCount",
">",
"7",
"{",
"retryCount",
"=",
"7",
"\n",
"}",
"\n\n",
"rand",
".",
"Seed",
"(",
"time",
".",
"Now",
"(",
... | // backoffDuration returns the duration to wait before retrying the request.
// Duration is an exponential function of the retry count with a jitter of ~0-30%. | [
"backoffDuration",
"returns",
"the",
"duration",
"to",
"wait",
"before",
"retrying",
"the",
"request",
".",
"Duration",
"is",
"an",
"exponential",
"function",
"of",
"the",
"retry",
"count",
"with",
"a",
"jitter",
"of",
"~0",
"-",
"30%",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/client.go#L240-L249 |
152,825 | JamesClonk/vultr | lib/client.go | isCodeRetryable | func isCodeRetryable(statusCode int) bool {
if _, ok := retryableStatusCodes[statusCode]; ok {
return true
}
return false
} | go | func isCodeRetryable(statusCode int) bool {
if _, ok := retryableStatusCodes[statusCode]; ok {
return true
}
return false
} | [
"func",
"isCodeRetryable",
"(",
"statusCode",
"int",
")",
"bool",
"{",
"if",
"_",
",",
"ok",
":=",
"retryableStatusCodes",
"[",
"statusCode",
"]",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // isCodeRetryable returns true if the given status code means that we should retry. | [
"isCodeRetryable",
"returns",
"true",
"if",
"the",
"given",
"status",
"code",
"means",
"that",
"we",
"should",
"retry",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/client.go#L252-L258 |
152,826 | JamesClonk/vultr | lib/regions.go | GetRegions | func (c *Client) GetRegions() ([]Region, error) {
var regionMap map[string]Region
if err := c.get(`regions/list`, ®ionMap); err != nil {
return nil, err
}
var regionList []Region
for _, os := range regionMap {
regionList = append(regionList, os)
}
sort.Sort(regions(regionList))
return regionList, nil
} | go | func (c *Client) GetRegions() ([]Region, error) {
var regionMap map[string]Region
if err := c.get(`regions/list`, ®ionMap); err != nil {
return nil, err
}
var regionList []Region
for _, os := range regionMap {
regionList = append(regionList, os)
}
sort.Sort(regions(regionList))
return regionList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetRegions",
"(",
")",
"(",
"[",
"]",
"Region",
",",
"error",
")",
"{",
"var",
"regionMap",
"map",
"[",
"string",
"]",
"Region",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`regions/list`",
",",
"&",
"re... | // GetRegions returns a list of all available Vultr regions | [
"GetRegions",
"returns",
"a",
"list",
"of",
"all",
"available",
"Vultr",
"regions"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/regions.go#L32-L44 |
152,827 | JamesClonk/vultr | lib/plans.go | GetPlans | func (c *Client) GetPlans() ([]Plan, error) {
var planMap map[string]Plan
if err := c.get(`plans/list`, &planMap); err != nil {
return nil, err
}
var p plans
for _, plan := range planMap {
p = append(p, plan)
}
sort.Sort(plans(p))
return p, nil
} | go | func (c *Client) GetPlans() ([]Plan, error) {
var planMap map[string]Plan
if err := c.get(`plans/list`, &planMap); err != nil {
return nil, err
}
var p plans
for _, plan := range planMap {
p = append(p, plan)
}
sort.Sort(plans(p))
return p, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetPlans",
"(",
")",
"(",
"[",
"]",
"Plan",
",",
"error",
")",
"{",
"var",
"planMap",
"map",
"[",
"string",
"]",
"Plan",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`plans/list`",
",",
"&",
"planMap",
... | // GetPlans returns a list of all available plans on Vultr account | [
"GetPlans",
"returns",
"a",
"list",
"of",
"all",
"available",
"plans",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/plans.go#L57-L70 |
152,828 | JamesClonk/vultr | lib/plans.go | GetAvailablePlansForRegion | func (c *Client) GetAvailablePlansForRegion(id int) (planIDs []int, err error) {
if err := c.get(fmt.Sprintf(`regions/availability?DCID=%v`, id), &planIDs); err != nil {
return nil, err
}
return
} | go | func (c *Client) GetAvailablePlansForRegion(id int) (planIDs []int, err error) {
if err := c.get(fmt.Sprintf(`regions/availability?DCID=%v`, id), &planIDs); err != nil {
return nil, err
}
return
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetAvailablePlansForRegion",
"(",
"id",
"int",
")",
"(",
"planIDs",
"[",
"]",
"int",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"fmt",
".",
"Sprintf",
"(",
"`regions/availability?DCID=... | // GetAvailablePlansForRegion returns available plans for specified region | [
"GetAvailablePlansForRegion",
"returns",
"available",
"plans",
"for",
"specified",
"region"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/plans.go#L73-L78 |
152,829 | JamesClonk/vultr | lib/iso.go | GetISO | func (c *Client) GetISO() ([]ISO, error) {
var isoMap map[string]ISO
if err := c.get(`iso/list`, &isoMap); err != nil {
return nil, err
}
var isoList []ISO
for _, iso := range isoMap {
isoList = append(isoList, iso)
}
sort.Sort(isos(isoList))
return isoList, nil
} | go | func (c *Client) GetISO() ([]ISO, error) {
var isoMap map[string]ISO
if err := c.get(`iso/list`, &isoMap); err != nil {
return nil, err
}
var isoList []ISO
for _, iso := range isoMap {
isoList = append(isoList, iso)
}
sort.Sort(isos(isoList))
return isoList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetISO",
"(",
")",
"(",
"[",
"]",
"ISO",
",",
"error",
")",
"{",
"var",
"isoMap",
"map",
"[",
"string",
"]",
"ISO",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`iso/list`",
",",
"&",
"isoMap",
")",
"... | // GetISO returns a list of all ISO images on Vultr account | [
"GetISO",
"returns",
"a",
"list",
"of",
"all",
"ISO",
"images",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/iso.go#L32-L44 |
152,830 | JamesClonk/vultr | lib/servers.go | GetServersByTag | func (c *Client) GetServersByTag(tag string) (serverList []Server, err error) {
var serverMap map[string]Server
if err := c.get(`server/list?tag=`+tag, &serverMap); err != nil {
return nil, err
}
for _, server := range serverMap {
serverList = append(serverList, server)
}
sort.Sort(servers(serverList))
return serverList, nil
} | go | func (c *Client) GetServersByTag(tag string) (serverList []Server, err error) {
var serverMap map[string]Server
if err := c.get(`server/list?tag=`+tag, &serverMap); err != nil {
return nil, err
}
for _, server := range serverMap {
serverList = append(serverList, server)
}
sort.Sort(servers(serverList))
return serverList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetServersByTag",
"(",
"tag",
"string",
")",
"(",
"serverList",
"[",
"]",
"Server",
",",
"err",
"error",
")",
"{",
"var",
"serverMap",
"map",
"[",
"string",
"]",
"Server",
"\n",
"if",
"err",
":=",
"c",
".",
"g... | // GetServersByTag returns a list of all virtual machines matching by tag | [
"GetServersByTag",
"returns",
"a",
"list",
"of",
"all",
"virtual",
"machines",
"matching",
"by",
"tag"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L243-L254 |
152,831 | JamesClonk/vultr | lib/servers.go | GetServer | func (c *Client) GetServer(id string) (server Server, err error) {
if err := c.get(`server/list?SUBID=`+id, &server); err != nil {
return Server{}, err
}
return server, nil
} | go | func (c *Client) GetServer(id string) (server Server, err error) {
if err := c.get(`server/list?SUBID=`+id, &server); err != nil {
return Server{}, err
}
return server, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetServer",
"(",
"id",
"string",
")",
"(",
"server",
"Server",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`server/list?SUBID=`",
"+",
"id",
",",
"&",
"server",
")",
";",
"err",
... | // GetServer returns the virtual machine with the given ID | [
"GetServer",
"returns",
"the",
"virtual",
"machine",
"with",
"the",
"given",
"ID"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L257-L262 |
152,832 | JamesClonk/vultr | lib/servers.go | RenameServer | func (c *Client) RenameServer(id, name string) error {
values := url.Values{
"SUBID": {id},
"label": {name},
}
if err := c.post(`server/label_set`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) RenameServer(id, name string) error {
values := url.Values{
"SUBID": {id},
"label": {name},
}
if err := c.post(`server/label_set`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"RenameServer",
"(",
"id",
",",
"name",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"name",
"}",
",",
"}",
"\n\n",
"... | // RenameServer renames an existing virtual machine | [
"RenameServer",
"renames",
"an",
"existing",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L357-L367 |
152,833 | JamesClonk/vultr | lib/servers.go | TagServer | func (c *Client) TagServer(id, tag string) error {
values := url.Values{
"SUBID": {id},
"tag": {tag},
}
if err := c.post(`server/tag_set`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) TagServer(id, tag string) error {
values := url.Values{
"SUBID": {id},
"tag": {tag},
}
if err := c.post(`server/tag_set`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"TagServer",
"(",
"id",
",",
"tag",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"tag",
"}",
",",
"}",
"\n\n",
"if",
... | // TagServer replaces the tag on an existing virtual machine | [
"TagServer",
"replaces",
"the",
"tag",
"on",
"an",
"existing",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L370-L380 |
152,834 | JamesClonk/vultr | lib/servers.go | StartServer | func (c *Client) StartServer(id string) error {
values := url.Values{
"SUBID": {id},
}
if err := c.post(`server/start`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) StartServer(id string) error {
values := url.Values{
"SUBID": {id},
}
if err := c.post(`server/start`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"StartServer",
"(",
"id",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"post",
"(",
"`server/start`",... | // StartServer starts an existing virtual machine | [
"StartServer",
"starts",
"an",
"existing",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L383-L392 |
152,835 | JamesClonk/vultr | lib/servers.go | ChangeOSofServer | func (c *Client) ChangeOSofServer(id string, osID int) error {
values := url.Values{
"SUBID": {id},
"OSID": {fmt.Sprintf("%v", osID)},
}
if err := c.post(`server/os_change`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) ChangeOSofServer(id string, osID int) error {
values := url.Values{
"SUBID": {id},
"OSID": {fmt.Sprintf("%v", osID)},
}
if err := c.post(`server/os_change`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ChangeOSofServer",
"(",
"id",
"string",
",",
"osID",
"int",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"fmt",
".",
"Sprintf",
... | // ChangeOSofServer changes the virtual machine to a different operating system | [
"ChangeOSofServer",
"changes",
"the",
"virtual",
"machine",
"to",
"a",
"different",
"operating",
"system"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L431-L441 |
152,836 | JamesClonk/vultr | lib/servers.go | AttachISOtoServer | func (c *Client) AttachISOtoServer(id string, isoID int) error {
values := url.Values{
"SUBID": {id},
"ISOID": {fmt.Sprintf("%v", isoID)},
}
if err := c.post(`server/iso_attach`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) AttachISOtoServer(id string, isoID int) error {
values := url.Values{
"SUBID": {id},
"ISOID": {fmt.Sprintf("%v", isoID)},
}
if err := c.post(`server/iso_attach`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"AttachISOtoServer",
"(",
"id",
"string",
",",
"isoID",
"int",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"fmt",
".",
"Sprintf",
... | // AttachISOtoServer attaches an ISO image to an existing virtual machine and reboots it | [
"AttachISOtoServer",
"attaches",
"an",
"ISO",
"image",
"to",
"an",
"existing",
"virtual",
"machine",
"and",
"reboots",
"it"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L458-L468 |
152,837 | JamesClonk/vultr | lib/servers.go | GetISOStatusofServer | func (c *Client) GetISOStatusofServer(id string) (isoStatus ISOStatus, err error) {
if err := c.get(`server/iso_status?SUBID=`+id, &isoStatus); err != nil {
return ISOStatus{}, err
}
return isoStatus, nil
} | go | func (c *Client) GetISOStatusofServer(id string) (isoStatus ISOStatus, err error) {
if err := c.get(`server/iso_status?SUBID=`+id, &isoStatus); err != nil {
return ISOStatus{}, err
}
return isoStatus, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetISOStatusofServer",
"(",
"id",
"string",
")",
"(",
"isoStatus",
"ISOStatus",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`server/iso_status?SUBID=`",
"+",
"id",
",",
"&",
"isoStatus",... | // GetISOStatusofServer retrieves the current ISO image state of an existing virtual machine | [
"GetISOStatusofServer",
"retrieves",
"the",
"current",
"ISO",
"image",
"state",
"of",
"an",
"existing",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L483-L488 |
152,838 | JamesClonk/vultr | lib/servers.go | RestoreBackup | func (c *Client) RestoreBackup(id, backupID string) error {
values := url.Values{
"SUBID": {id},
"BACKUPID": {backupID},
}
if err := c.post(`server/restore_backup`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) RestoreBackup(id, backupID string) error {
values := url.Values{
"SUBID": {id},
"BACKUPID": {backupID},
}
if err := c.post(`server/restore_backup`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"RestoreBackup",
"(",
"id",
",",
"backupID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"backupID",
"}",
",",
"}",
"\... | // RestoreBackup restore the specified backup to the virtual machine | [
"RestoreBackup",
"restore",
"the",
"specified",
"backup",
"to",
"the",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L491-L501 |
152,839 | JamesClonk/vultr | lib/servers.go | RestoreSnapshot | func (c *Client) RestoreSnapshot(id, snapshotID string) error {
values := url.Values{
"SUBID": {id},
"SNAPSHOTID": {snapshotID},
}
if err := c.post(`server/restore_snapshot`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) RestoreSnapshot(id, snapshotID string) error {
values := url.Values{
"SUBID": {id},
"SNAPSHOTID": {snapshotID},
}
if err := c.post(`server/restore_snapshot`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"RestoreSnapshot",
"(",
"id",
",",
"snapshotID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"snapshotID",
"}",
",",
"}"... | // RestoreSnapshot restore the specified snapshot to the virtual machine | [
"RestoreSnapshot",
"restore",
"the",
"specified",
"snapshot",
"to",
"the",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L504-L514 |
152,840 | JamesClonk/vultr | lib/servers.go | SetFirewallGroup | func (c *Client) SetFirewallGroup(id, firewallgroup string) error {
values := url.Values{
"SUBID": {id},
"FIREWALLGROUPID": {firewallgroup},
}
if err := c.post(`server/firewall_group_set`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) SetFirewallGroup(id, firewallgroup string) error {
values := url.Values{
"SUBID": {id},
"FIREWALLGROUPID": {firewallgroup},
}
if err := c.post(`server/firewall_group_set`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetFirewallGroup",
"(",
"id",
",",
"firewallgroup",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"firewallgroup",
"}",
","... | // SetFirewallGroup adds a virtual machine to a firewall group | [
"SetFirewallGroup",
"adds",
"a",
"virtual",
"machine",
"to",
"a",
"firewall",
"group"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L529-L539 |
152,841 | JamesClonk/vultr | lib/servers.go | BandwidthOfServer | func (c *Client) BandwidthOfServer(id string) (bandwidth []map[string]string, err error) {
var bandwidthMap map[string][][]string
if err := c.get(`server/bandwidth?SUBID=`+id, &bandwidthMap); err != nil {
return nil, err
}
// parse incoming bytes
for _, b := range bandwidthMap["incoming_bytes"] {
bMap := make(map[string]string)
bMap["date"] = b[0]
bMap["incoming"] = b[1]
bandwidth = append(bandwidth, bMap)
}
// parse outgoing bytes (we'll assume that incoming and outgoing dates are always a match)
for _, b := range bandwidthMap["outgoing_bytes"] {
for i := range bandwidth {
if bandwidth[i]["date"] == b[0] {
bandwidth[i]["outgoing"] = b[1]
break
}
}
}
return bandwidth, nil
} | go | func (c *Client) BandwidthOfServer(id string) (bandwidth []map[string]string, err error) {
var bandwidthMap map[string][][]string
if err := c.get(`server/bandwidth?SUBID=`+id, &bandwidthMap); err != nil {
return nil, err
}
// parse incoming bytes
for _, b := range bandwidthMap["incoming_bytes"] {
bMap := make(map[string]string)
bMap["date"] = b[0]
bMap["incoming"] = b[1]
bandwidth = append(bandwidth, bMap)
}
// parse outgoing bytes (we'll assume that incoming and outgoing dates are always a match)
for _, b := range bandwidthMap["outgoing_bytes"] {
for i := range bandwidth {
if bandwidth[i]["date"] == b[0] {
bandwidth[i]["outgoing"] = b[1]
break
}
}
}
return bandwidth, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"BandwidthOfServer",
"(",
"id",
"string",
")",
"(",
"bandwidth",
"[",
"]",
"map",
"[",
"string",
"]",
"string",
",",
"err",
"error",
")",
"{",
"var",
"bandwidthMap",
"map",
"[",
"string",
"]",
"[",
"]",
"[",
"]... | // BandwidthOfServer retrieves the bandwidth used by a virtual machine | [
"BandwidthOfServer",
"retrieves",
"the",
"bandwidth",
"used",
"by",
"a",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L547-L572 |
152,842 | JamesClonk/vultr | lib/servers.go | ChangeApplicationofServer | func (c *Client) ChangeApplicationofServer(id string, appID string) error {
values := url.Values{
"SUBID": {id},
"APPID": {appID},
}
if err := c.post(`server/app_change`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) ChangeApplicationofServer(id string, appID string) error {
values := url.Values{
"SUBID": {id},
"APPID": {appID},
}
if err := c.post(`server/app_change`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ChangeApplicationofServer",
"(",
"id",
"string",
",",
"appID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"appID",
"}",
... | // ChangeApplicationofServer changes the virtual machine to a different application | [
"ChangeApplicationofServer",
"changes",
"the",
"virtual",
"machine",
"to",
"a",
"different",
"application"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L575-L585 |
152,843 | JamesClonk/vultr | lib/servers.go | ListApplicationsforServer | func (c *Client) ListApplicationsforServer(id string) (apps []Application, err error) {
var appMap map[string]Application
if err := c.get(`server/app_change_list?SUBID=`+id, &appMap); err != nil {
return nil, err
}
for _, app := range appMap {
apps = append(apps, app)
}
sort.Sort(applications(apps))
return apps, nil
} | go | func (c *Client) ListApplicationsforServer(id string) (apps []Application, err error) {
var appMap map[string]Application
if err := c.get(`server/app_change_list?SUBID=`+id, &appMap); err != nil {
return nil, err
}
for _, app := range appMap {
apps = append(apps, app)
}
sort.Sort(applications(apps))
return apps, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListApplicationsforServer",
"(",
"id",
"string",
")",
"(",
"apps",
"[",
"]",
"Application",
",",
"err",
"error",
")",
"{",
"var",
"appMap",
"map",
"[",
"string",
"]",
"Application",
"\n",
"if",
"err",
":=",
"c",
... | // ListApplicationsforServer lists all available operating systems to which an existing virtual machine can be changed | [
"ListApplicationsforServer",
"lists",
"all",
"available",
"operating",
"systems",
"to",
"which",
"an",
"existing",
"virtual",
"machine",
"can",
"be",
"changed"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L588-L599 |
152,844 | JamesClonk/vultr | lib/servers.go | GetApplicationInfo | func (c *Client) GetApplicationInfo(id string) (appInfo AppInfo, err error) {
if err := c.get(`server/get_app_info?SUBID=`+id, &appInfo); err != nil {
return AppInfo{}, err
}
return appInfo, nil
} | go | func (c *Client) GetApplicationInfo(id string) (appInfo AppInfo, err error) {
if err := c.get(`server/get_app_info?SUBID=`+id, &appInfo); err != nil {
return AppInfo{}, err
}
return appInfo, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetApplicationInfo",
"(",
"id",
"string",
")",
"(",
"appInfo",
"AppInfo",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`server/get_app_info?SUBID=`",
"+",
"id",
",",
"&",
"appInfo",
")"... | // GetApplicationInfo retrieves the application information for the existing virtual machine | [
"GetApplicationInfo",
"retrieves",
"the",
"application",
"information",
"for",
"the",
"existing",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L602-L607 |
152,845 | JamesClonk/vultr | lib/servers.go | ListPrivateNetworksForServer | func (c *Client) ListPrivateNetworksForServer(id string) (nets []PrivateNetwork, err error) {
var netMap map[string]PrivateNetwork
if err := c.get(`server/private_networks?SUBID=`+id, &netMap); err != nil {
return nil, err
}
for _, net := range netMap {
nets = append(nets, net)
}
sort.Sort(privateNetworks(nets))
return nets, nil
} | go | func (c *Client) ListPrivateNetworksForServer(id string) (nets []PrivateNetwork, err error) {
var netMap map[string]PrivateNetwork
if err := c.get(`server/private_networks?SUBID=`+id, &netMap); err != nil {
return nil, err
}
for _, net := range netMap {
nets = append(nets, net)
}
sort.Sort(privateNetworks(nets))
return nets, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListPrivateNetworksForServer",
"(",
"id",
"string",
")",
"(",
"nets",
"[",
"]",
"PrivateNetwork",
",",
"err",
"error",
")",
"{",
"var",
"netMap",
"map",
"[",
"string",
"]",
"PrivateNetwork",
"\n",
"if",
"err",
":=",... | // ListPrivateNetworksForServer lists all the private networks to which an existing virtual machine is attached | [
"ListPrivateNetworksForServer",
"lists",
"all",
"the",
"private",
"networks",
"to",
"which",
"an",
"existing",
"virtual",
"machine",
"is",
"attached"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L625-L636 |
152,846 | JamesClonk/vultr | lib/servers.go | DisablePrivateNetworkForServer | func (c *Client) DisablePrivateNetworkForServer(id, networkID string) error {
values := url.Values{
"SUBID": {id},
"NETWORKID": {networkID},
}
return c.post(`server/private_network_disable`, values, nil)
} | go | func (c *Client) DisablePrivateNetworkForServer(id, networkID string) error {
values := url.Values{
"SUBID": {id},
"NETWORKID": {networkID},
}
return c.post(`server/private_network_disable`, values, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DisablePrivateNetworkForServer",
"(",
"id",
",",
"networkID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"networkID",
"}",... | // DisablePrivateNetworkForServer removes the given virtual machine from the given private network | [
"DisablePrivateNetworkForServer",
"removes",
"the",
"given",
"virtual",
"machine",
"from",
"the",
"given",
"private",
"network"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L639-L646 |
152,847 | JamesClonk/vultr | lib/servers.go | EnablePrivateNetworkForServer | func (c *Client) EnablePrivateNetworkForServer(id, networkID string) error {
values := url.Values{
"SUBID": {id},
}
if networkID != "" {
values.Add("NETWORKID", networkID)
}
return c.post(`server/private_network_enable`, values, nil)
} | go | func (c *Client) EnablePrivateNetworkForServer(id, networkID string) error {
values := url.Values{
"SUBID": {id},
}
if networkID != "" {
values.Add("NETWORKID", networkID)
}
return c.post(`server/private_network_enable`, values, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"EnablePrivateNetworkForServer",
"(",
"id",
",",
"networkID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"}",
"\n",
"if",
"networkID",
"!=",
"\""... | // EnablePrivateNetworkForServer enables private networking for the given virtual machine.
// If private networking is already enabled, then nothing occurs.
// If multiple private networks exist in the virtual machine's region, then the network ID must be specified. | [
"EnablePrivateNetworkForServer",
"enables",
"private",
"networking",
"for",
"the",
"given",
"virtual",
"machine",
".",
"If",
"private",
"networking",
"is",
"already",
"enabled",
"then",
"nothing",
"occurs",
".",
"If",
"multiple",
"private",
"networks",
"exist",
"in"... | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L651-L660 |
152,848 | JamesClonk/vultr | lib/servers.go | BackupGetSchedule | func (c *Client) BackupGetSchedule(id string) (*BackupScheduleResponse, error) {
var bsr = &BackupScheduleResponse{}
values := url.Values{
"SUBID": {id},
}
if err := c.post(`server/backup_get_schedule`, values, &bsr); err != nil {
return nil, err
}
return bsr, nil
} | go | func (c *Client) BackupGetSchedule(id string) (*BackupScheduleResponse, error) {
var bsr = &BackupScheduleResponse{}
values := url.Values{
"SUBID": {id},
}
if err := c.post(`server/backup_get_schedule`, values, &bsr); err != nil {
return nil, err
}
return bsr, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"BackupGetSchedule",
"(",
"id",
"string",
")",
"(",
"*",
"BackupScheduleResponse",
",",
"error",
")",
"{",
"var",
"bsr",
"=",
"&",
"BackupScheduleResponse",
"{",
"}",
"\n",
"values",
":=",
"url",
".",
"Values",
"{",
... | // BackupGetSchedule returns a virtual machines backup schedule | [
"BackupGetSchedule",
"returns",
"a",
"virtual",
"machines",
"backup",
"schedule"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L679-L688 |
152,849 | JamesClonk/vultr | lib/servers.go | BackupSetSchedule | func (c *Client) BackupSetSchedule(id string, bs BackupSchedule) error {
values := url.Values{
"SUBID": {id},
"cron_type": {bs.CronType},
"hour": {string(bs.Hour)},
"dow": {string(bs.Dow)},
"dom": {string(bs.Dom)},
}
return c.post(`server/backup_set_schedule`, values, nil)
} | go | func (c *Client) BackupSetSchedule(id string, bs BackupSchedule) error {
values := url.Values{
"SUBID": {id},
"cron_type": {bs.CronType},
"hour": {string(bs.Hour)},
"dow": {string(bs.Dow)},
"dom": {string(bs.Dom)},
}
return c.post(`server/backup_set_schedule`, values, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"BackupSetSchedule",
"(",
"id",
"string",
",",
"bs",
"BackupSchedule",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"bs",
".",
"Cro... | // BackupSetSchedule sets the backup schedule given a BackupSchedule struct | [
"BackupSetSchedule",
"sets",
"the",
"backup",
"schedule",
"given",
"a",
"BackupSchedule",
"struct"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L691-L700 |
152,850 | JamesClonk/vultr | lib/servers.go | ChangePlanOfServer | func (c *Client) ChangePlanOfServer(id string, planID int) error {
values := url.Values{
"SUBID": {id},
"VPSPLANID": {fmt.Sprintf("%v", planID)},
}
if err := c.post(`server/upgrade_plan`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) ChangePlanOfServer(id string, planID int) error {
values := url.Values{
"SUBID": {id},
"VPSPLANID": {fmt.Sprintf("%v", planID)},
}
if err := c.post(`server/upgrade_plan`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ChangePlanOfServer",
"(",
"id",
"string",
",",
"planID",
"int",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"fmt",
".",
"Sprintf"... | // ChangePlanOfServer changes the virtual machine to a different plan | [
"ChangePlanOfServer",
"changes",
"the",
"virtual",
"machine",
"to",
"a",
"different",
"plan"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L703-L713 |
152,851 | JamesClonk/vultr | lib/servers.go | ListUpgradePlansForServer | func (c *Client) ListUpgradePlansForServer(id string) (planIDs []int, err error) {
if err := c.get(`server/upgrade_plan_list?SUBID=`+id, &planIDs); err != nil {
return nil, err
}
return
} | go | func (c *Client) ListUpgradePlansForServer(id string) (planIDs []int, err error) {
if err := c.get(`server/upgrade_plan_list?SUBID=`+id, &planIDs); err != nil {
return nil, err
}
return
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListUpgradePlansForServer",
"(",
"id",
"string",
")",
"(",
"planIDs",
"[",
"]",
"int",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`server/upgrade_plan_list?SUBID=`",
"+",
"id",
",",
"... | // ListUpgradePlansForServer retrieves a list of the VPSPLANIDs for which a virtual machine can be upgraded.
// An empty response means that there are currently no upgrades available | [
"ListUpgradePlansForServer",
"retrieves",
"a",
"list",
"of",
"the",
"VPSPLANIDs",
"for",
"which",
"a",
"virtual",
"machine",
"can",
"be",
"upgraded",
".",
"An",
"empty",
"response",
"means",
"that",
"there",
"are",
"currently",
"no",
"upgrades",
"available"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/servers.go#L717-L722 |
152,852 | JamesClonk/vultr | lib/firewall.go | UnmarshalJSON | func (r *FirewallRule) UnmarshalJSON(data []byte) (err error) {
if r == nil {
*r = FirewallRule{}
}
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
value := fmt.Sprintf("%v", fields["rulenumber"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
number, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
r.RuleNumber = int(number)
value = fmt.Sprintf("%v", fields["subnet_size"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
subnetSize, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
r.Action = fmt.Sprintf("%v", fields["action"])
r.Protocol = fmt.Sprintf("%v", fields["protocol"])
r.Port = fmt.Sprintf("%v", fields["port"])
r.Notes = fmt.Sprintf("%v", fields["notes"])
subnet := fmt.Sprintf("%v", fields["subnet"])
if subnet == "<nil>" {
subnet = ""
}
if len(subnet) > 0 {
_, r.Network, err = net.ParseCIDR(fmt.Sprintf("%s/%d", subnet, subnetSize))
if err != nil {
return fmt.Errorf("Failed to parse subnet from Vultr API")
}
} else {
// This case is used to create a valid default CIDR when the Vultr API does not return a subnet/subnet size at all, e.g. the response after creating a new rule.
_, r.Network, _ = net.ParseCIDR("0.0.0.0/0")
}
return
} | go | func (r *FirewallRule) UnmarshalJSON(data []byte) (err error) {
if r == nil {
*r = FirewallRule{}
}
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
value := fmt.Sprintf("%v", fields["rulenumber"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
number, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
r.RuleNumber = int(number)
value = fmt.Sprintf("%v", fields["subnet_size"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
subnetSize, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
r.Action = fmt.Sprintf("%v", fields["action"])
r.Protocol = fmt.Sprintf("%v", fields["protocol"])
r.Port = fmt.Sprintf("%v", fields["port"])
r.Notes = fmt.Sprintf("%v", fields["notes"])
subnet := fmt.Sprintf("%v", fields["subnet"])
if subnet == "<nil>" {
subnet = ""
}
if len(subnet) > 0 {
_, r.Network, err = net.ParseCIDR(fmt.Sprintf("%s/%d", subnet, subnetSize))
if err != nil {
return fmt.Errorf("Failed to parse subnet from Vultr API")
}
} else {
// This case is used to create a valid default CIDR when the Vultr API does not return a subnet/subnet size at all, e.g. the response after creating a new rule.
_, r.Network, _ = net.ParseCIDR("0.0.0.0/0")
}
return
} | [
"func",
"(",
"r",
"*",
"FirewallRule",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"r",
"==",
"nil",
"{",
"*",
"r",
"=",
"FirewallRule",
"{",
"}",
"\n",
"}",
"\n\n",
"var",
"fields",
"map",
"[",
... | // UnmarshalJSON implements json.Unmarshaller on FirewallRule.
// This is needed because the Vultr API is inconsistent in it's JSON responses.
// Some fields can change type, from JSON number to JSON string and vice-versa. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaller",
"on",
"FirewallRule",
".",
"This",
"is",
"needed",
"because",
"the",
"Vultr",
"API",
"is",
"inconsistent",
"in",
"it",
"s",
"JSON",
"responses",
".",
"Some",
"fields",
"can",
"change",
"type",
"from",... | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L55-L104 |
152,853 | JamesClonk/vultr | lib/firewall.go | GetFirewallGroups | func (c *Client) GetFirewallGroups() ([]FirewallGroup, error) {
var groupMap map[string]FirewallGroup
if err := c.get(`firewall/group_list`, &groupMap); err != nil {
return nil, err
}
var groupList []FirewallGroup
for _, g := range groupMap {
groupList = append(groupList, g)
}
sort.Sort(firewallGroups(groupList))
return groupList, nil
} | go | func (c *Client) GetFirewallGroups() ([]FirewallGroup, error) {
var groupMap map[string]FirewallGroup
if err := c.get(`firewall/group_list`, &groupMap); err != nil {
return nil, err
}
var groupList []FirewallGroup
for _, g := range groupMap {
groupList = append(groupList, g)
}
sort.Sort(firewallGroups(groupList))
return groupList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetFirewallGroups",
"(",
")",
"(",
"[",
"]",
"FirewallGroup",
",",
"error",
")",
"{",
"var",
"groupMap",
"map",
"[",
"string",
"]",
"FirewallGroup",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`firewall/group_... | // GetFirewallGroups returns a list of all available firewall groups on Vultr | [
"GetFirewallGroups",
"returns",
"a",
"list",
"of",
"all",
"available",
"firewall",
"groups",
"on",
"Vultr"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L107-L119 |
152,854 | JamesClonk/vultr | lib/firewall.go | GetFirewallGroup | func (c *Client) GetFirewallGroup(id string) (FirewallGroup, error) {
groups, err := c.GetFirewallGroups()
if err != nil {
return FirewallGroup{}, err
}
for _, g := range groups {
if g.ID == id {
return g, nil
}
}
return FirewallGroup{}, fmt.Errorf("Firewall group with ID %v not found", id)
} | go | func (c *Client) GetFirewallGroup(id string) (FirewallGroup, error) {
groups, err := c.GetFirewallGroups()
if err != nil {
return FirewallGroup{}, err
}
for _, g := range groups {
if g.ID == id {
return g, nil
}
}
return FirewallGroup{}, fmt.Errorf("Firewall group with ID %v not found", id)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetFirewallGroup",
"(",
"id",
"string",
")",
"(",
"FirewallGroup",
",",
"error",
")",
"{",
"groups",
",",
"err",
":=",
"c",
".",
"GetFirewallGroups",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Fir... | // GetFirewallGroup returns the firewall group with given ID | [
"GetFirewallGroup",
"returns",
"the",
"firewall",
"group",
"with",
"given",
"ID"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L122-L134 |
152,855 | JamesClonk/vultr | lib/firewall.go | CreateFirewallGroup | func (c *Client) CreateFirewallGroup(description string) (string, error) {
values := url.Values{}
// Optional description
if len(description) > 0 {
values.Add("description", description)
}
var result FirewallGroup
err := c.post(`firewall/group_create`, values, &result)
if err != nil {
return "", err
}
return result.ID, nil
} | go | func (c *Client) CreateFirewallGroup(description string) (string, error) {
values := url.Values{}
// Optional description
if len(description) > 0 {
values.Add("description", description)
}
var result FirewallGroup
err := c.post(`firewall/group_create`, values, &result)
if err != nil {
return "", err
}
return result.ID, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateFirewallGroup",
"(",
"description",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"// Optional description",
"if",
"len",
"(",
"description",
")",
... | // CreateFirewallGroup creates a new firewall group in Vultr account | [
"CreateFirewallGroup",
"creates",
"a",
"new",
"firewall",
"group",
"in",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L137-L151 |
152,856 | JamesClonk/vultr | lib/firewall.go | DeleteFirewallGroup | func (c *Client) DeleteFirewallGroup(groupID string) error {
values := url.Values{
"FIREWALLGROUPID": {groupID},
}
if err := c.post(`firewall/group_delete`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) DeleteFirewallGroup(groupID string) error {
values := url.Values{
"FIREWALLGROUPID": {groupID},
}
if err := c.post(`firewall/group_delete`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteFirewallGroup",
"(",
"groupID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"groupID",
"}",
",",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"post",
"(",
... | // DeleteFirewallGroup deletes an existing firewall group | [
"DeleteFirewallGroup",
"deletes",
"an",
"existing",
"firewall",
"group"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L154-L163 |
152,857 | JamesClonk/vultr | lib/firewall.go | SetFirewallGroupDescription | func (c *Client) SetFirewallGroupDescription(groupID, description string) error {
values := url.Values{
"FIREWALLGROUPID": {groupID},
"description": {description},
}
if err := c.post(`firewall/group_set_description`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) SetFirewallGroupDescription(groupID, description string) error {
values := url.Values{
"FIREWALLGROUPID": {groupID},
"description": {description},
}
if err := c.post(`firewall/group_set_description`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetFirewallGroupDescription",
"(",
"groupID",
",",
"description",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"groupID",
"}",
",",
"\"",
"\"",
":",
"{",
"descripti... | // SetFirewallGroupDescription sets the description of an existing firewall group | [
"SetFirewallGroupDescription",
"sets",
"the",
"description",
"of",
"an",
"existing",
"firewall",
"group"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L166-L176 |
152,858 | JamesClonk/vultr | lib/firewall.go | GetFirewallRules | func (c *Client) GetFirewallRules(groupID string) ([]FirewallRule, error) {
var ruleMap map[string]FirewallRule
ipTypes := []string{"v4", "v6"}
for _, ipType := range ipTypes {
args := fmt.Sprintf("direction=in&FIREWALLGROUPID=%s&ip_type=%s",
groupID, ipType)
if err := c.get(`firewall/rule_list?`+args, &ruleMap); err != nil {
return nil, err
}
}
var ruleList []FirewallRule
for _, r := range ruleMap {
ruleList = append(ruleList, r)
}
sort.Sort(firewallRules(ruleList))
return ruleList, nil
} | go | func (c *Client) GetFirewallRules(groupID string) ([]FirewallRule, error) {
var ruleMap map[string]FirewallRule
ipTypes := []string{"v4", "v6"}
for _, ipType := range ipTypes {
args := fmt.Sprintf("direction=in&FIREWALLGROUPID=%s&ip_type=%s",
groupID, ipType)
if err := c.get(`firewall/rule_list?`+args, &ruleMap); err != nil {
return nil, err
}
}
var ruleList []FirewallRule
for _, r := range ruleMap {
ruleList = append(ruleList, r)
}
sort.Sort(firewallRules(ruleList))
return ruleList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetFirewallRules",
"(",
"groupID",
"string",
")",
"(",
"[",
"]",
"FirewallRule",
",",
"error",
")",
"{",
"var",
"ruleMap",
"map",
"[",
"string",
"]",
"FirewallRule",
"\n",
"ipTypes",
":=",
"[",
"]",
"string",
"{",... | // GetFirewallRules returns a list of rules for the given firewall group | [
"GetFirewallRules",
"returns",
"a",
"list",
"of",
"rules",
"for",
"the",
"given",
"firewall",
"group"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L179-L196 |
152,859 | JamesClonk/vultr | lib/firewall.go | DeleteFirewallRule | func (c *Client) DeleteFirewallRule(ruleNumber int, groupID string) error {
values := url.Values{
"FIREWALLGROUPID": {groupID},
"rulenumber": {fmt.Sprintf("%v", ruleNumber)},
}
if err := c.post(`firewall/rule_delete`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) DeleteFirewallRule(ruleNumber int, groupID string) error {
values := url.Values{
"FIREWALLGROUPID": {groupID},
"rulenumber": {fmt.Sprintf("%v", ruleNumber)},
}
if err := c.post(`firewall/rule_delete`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteFirewallRule",
"(",
"ruleNumber",
"int",
",",
"groupID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"groupID",
"}",
",",
"\"",
"\"",
":",
"{",
"fmt",
".... | // DeleteFirewallRule deletes an existing firewall rule | [
"DeleteFirewallRule",
"deletes",
"an",
"existing",
"firewall",
"rule"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/firewall.go#L248-L258 |
152,860 | JamesClonk/vultr | lib/applications.go | GetApplications | func (c *Client) GetApplications() ([]Application, error) {
var appMap map[string]Application
if err := c.get(`app/list`, &appMap); err != nil {
return nil, err
}
var appList []Application
for _, app := range appMap {
appList = append(appList, app)
}
sort.Sort(applications(appList))
return appList, nil
} | go | func (c *Client) GetApplications() ([]Application, error) {
var appMap map[string]Application
if err := c.get(`app/list`, &appMap); err != nil {
return nil, err
}
var appList []Application
for _, app := range appMap {
appList = append(appList, app)
}
sort.Sort(applications(appList))
return appList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetApplications",
"(",
")",
"(",
"[",
"]",
"Application",
",",
"error",
")",
"{",
"var",
"appMap",
"map",
"[",
"string",
"]",
"Application",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`app/list`",
",",
"&... | // GetApplications returns a list of all available applications on Vultr | [
"GetApplications",
"returns",
"a",
"list",
"of",
"all",
"available",
"applications",
"on",
"Vultr"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/applications.go#L26-L38 |
152,861 | JamesClonk/vultr | lib/bare_metal.go | GetBareMetalServers | func (c *Client) GetBareMetalServers() ([]BareMetalServer, error) {
var bareMetalServerMap map[string]BareMetalServer
if err := c.get(`baremetal/list`, &bareMetalServerMap); err != nil {
return nil, err
}
var bareMetalServerList []BareMetalServer
for _, bareMetalServer := range bareMetalServerMap {
bareMetalServerList = append(bareMetalServerList, bareMetalServer)
}
sort.Sort(bareMetalServers(bareMetalServerList))
return bareMetalServerList, nil
} | go | func (c *Client) GetBareMetalServers() ([]BareMetalServer, error) {
var bareMetalServerMap map[string]BareMetalServer
if err := c.get(`baremetal/list`, &bareMetalServerMap); err != nil {
return nil, err
}
var bareMetalServerList []BareMetalServer
for _, bareMetalServer := range bareMetalServerMap {
bareMetalServerList = append(bareMetalServerList, bareMetalServer)
}
sort.Sort(bareMetalServers(bareMetalServerList))
return bareMetalServerList, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetBareMetalServers",
"(",
")",
"(",
"[",
"]",
"BareMetalServer",
",",
"error",
")",
"{",
"var",
"bareMetalServerMap",
"map",
"[",
"string",
"]",
"BareMetalServer",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"... | // GetBareMetalServers returns a list of current bare metal servers on the Vultr account. | [
"GetBareMetalServers",
"returns",
"a",
"list",
"of",
"current",
"bare",
"metal",
"servers",
"on",
"the",
"Vultr",
"account",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L153-L165 |
152,862 | JamesClonk/vultr | lib/bare_metal.go | GetBareMetalServer | func (c *Client) GetBareMetalServer(id string) (BareMetalServer, error) {
var b BareMetalServer
if err := c.get(`baremetal/list?SUBID=`+id, &b); err != nil {
return BareMetalServer{}, err
}
return b, nil
} | go | func (c *Client) GetBareMetalServer(id string) (BareMetalServer, error) {
var b BareMetalServer
if err := c.get(`baremetal/list?SUBID=`+id, &b); err != nil {
return BareMetalServer{}, err
}
return b, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetBareMetalServer",
"(",
"id",
"string",
")",
"(",
"BareMetalServer",
",",
"error",
")",
"{",
"var",
"b",
"BareMetalServer",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`baremetal/list?SUBID=`",
"+",
"id",
",",... | // GetBareMetalServer returns the bare metal server with the given ID. | [
"GetBareMetalServer",
"returns",
"the",
"bare",
"metal",
"server",
"with",
"the",
"given",
"ID",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L183-L189 |
152,863 | JamesClonk/vultr | lib/bare_metal.go | CreateBareMetalServer | func (c *Client) CreateBareMetalServer(name string, regionID, planID, osID int, options *BareMetalServerOptions) (BareMetalServer, error) {
values := url.Values{
"label": {name},
"DCID": {fmt.Sprintf("%v", regionID)},
"METALPLANID": {fmt.Sprintf("%v", planID)},
"OSID": {fmt.Sprintf("%v", osID)},
}
if options != nil {
if options.Script != 0 {
values.Add("SCRIPTID", fmt.Sprintf("%v", options.Script))
}
if options.UserData != "" {
values.Add("userdata", base64.StdEncoding.EncodeToString([]byte(options.UserData)))
}
if options.Snapshot != "" {
values.Add("SNAPSHOTID", options.Snapshot)
}
if options.SSHKey != "" {
values.Add("SSHKEYID", options.SSHKey)
}
values.Add("enable_ipv6", "no")
if options.IPV6 {
values.Set("enable_ipv6", "yes")
}
values.Add("notify_activate", "yes")
if options.DontNotifyOnActivate {
values.Set("notify_activate", "no")
}
if options.Hostname != "" {
values.Add("hostname", options.Hostname)
}
if options.Tag != "" {
values.Add("tag", options.Tag)
}
if options.AppID != "" {
values.Add("APPID", options.AppID)
}
}
var b BareMetalServer
if err := c.post(`baremetal/create`, values, &b); err != nil {
return BareMetalServer{}, err
}
b.Name = name
b.RegionID = regionID
b.PlanID = planID
return b, nil
} | go | func (c *Client) CreateBareMetalServer(name string, regionID, planID, osID int, options *BareMetalServerOptions) (BareMetalServer, error) {
values := url.Values{
"label": {name},
"DCID": {fmt.Sprintf("%v", regionID)},
"METALPLANID": {fmt.Sprintf("%v", planID)},
"OSID": {fmt.Sprintf("%v", osID)},
}
if options != nil {
if options.Script != 0 {
values.Add("SCRIPTID", fmt.Sprintf("%v", options.Script))
}
if options.UserData != "" {
values.Add("userdata", base64.StdEncoding.EncodeToString([]byte(options.UserData)))
}
if options.Snapshot != "" {
values.Add("SNAPSHOTID", options.Snapshot)
}
if options.SSHKey != "" {
values.Add("SSHKEYID", options.SSHKey)
}
values.Add("enable_ipv6", "no")
if options.IPV6 {
values.Set("enable_ipv6", "yes")
}
values.Add("notify_activate", "yes")
if options.DontNotifyOnActivate {
values.Set("notify_activate", "no")
}
if options.Hostname != "" {
values.Add("hostname", options.Hostname)
}
if options.Tag != "" {
values.Add("tag", options.Tag)
}
if options.AppID != "" {
values.Add("APPID", options.AppID)
}
}
var b BareMetalServer
if err := c.post(`baremetal/create`, values, &b); err != nil {
return BareMetalServer{}, err
}
b.Name = name
b.RegionID = regionID
b.PlanID = planID
return b, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateBareMetalServer",
"(",
"name",
"string",
",",
"regionID",
",",
"planID",
",",
"osID",
"int",
",",
"options",
"*",
"BareMetalServerOptions",
")",
"(",
"BareMetalServer",
",",
"error",
")",
"{",
"values",
":=",
"u... | // CreateBareMetalServer creates a new bare metal server on Vultr. BareMetalServerOptions are optional settings. | [
"CreateBareMetalServer",
"creates",
"a",
"new",
"bare",
"metal",
"server",
"on",
"Vultr",
".",
"BareMetalServerOptions",
"are",
"optional",
"settings",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L192-L249 |
152,864 | JamesClonk/vultr | lib/bare_metal.go | RenameBareMetalServer | func (c *Client) RenameBareMetalServer(id, name string) error {
values := url.Values{
"SUBID": {id},
"label": {name},
}
return c.post(`baremetal/label_set`, values, nil)
} | go | func (c *Client) RenameBareMetalServer(id, name string) error {
values := url.Values{
"SUBID": {id},
"label": {name},
}
return c.post(`baremetal/label_set`, values, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"RenameBareMetalServer",
"(",
"id",
",",
"name",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"name",
"}",
",",
"}",
"\... | // RenameBareMetalServer renames an existing bare metal server. | [
"RenameBareMetalServer",
"renames",
"an",
"existing",
"bare",
"metal",
"server",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L252-L259 |
152,865 | JamesClonk/vultr | lib/bare_metal.go | TagBareMetalServer | func (c *Client) TagBareMetalServer(id, tag string) error {
values := url.Values{
"SUBID": {id},
"tag": {tag},
}
return c.post(`baremetal/tag_set`, values, nil)
} | go | func (c *Client) TagBareMetalServer(id, tag string) error {
values := url.Values{
"SUBID": {id},
"tag": {tag},
}
return c.post(`baremetal/tag_set`, values, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"TagBareMetalServer",
"(",
"id",
",",
"tag",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"tag",
"}",
",",
"}",
"\n\n",... | // TagBareMetalServer replaces the tag on an existing bare metal server. | [
"TagBareMetalServer",
"replaces",
"the",
"tag",
"on",
"an",
"existing",
"bare",
"metal",
"server",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L262-L269 |
152,866 | JamesClonk/vultr | lib/bare_metal.go | ReinstallBareMetalServer | func (c *Client) ReinstallBareMetalServer(id string) error {
values := url.Values{
"SUBID": {id},
}
return c.post(`baremetal/reinstall`, values, nil)
} | go | func (c *Client) ReinstallBareMetalServer(id string) error {
values := url.Values{
"SUBID": {id},
}
return c.post(`baremetal/reinstall`, values, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ReinstallBareMetalServer",
"(",
"id",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"}",
"\n\n",
"return",
"c",
".",
"post",
"(",
"`baremetal/reins... | // ReinstallBareMetalServer reinstalls the operating system on an existing bare metal server. | [
"ReinstallBareMetalServer",
"reinstalls",
"the",
"operating",
"system",
"on",
"an",
"existing",
"bare",
"metal",
"server",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L290-L296 |
152,867 | JamesClonk/vultr | lib/bare_metal.go | ListOSforBareMetalServer | func (c *Client) ListOSforBareMetalServer(id string) ([]OS, error) {
var osMap map[string]OS
if err := c.get(`baremetal/os_change_list?SUBID=`+id, &osMap); err != nil {
return nil, err
}
var os []OS
for _, o := range osMap {
os = append(os, o)
}
sort.Sort(oses(os))
return os, nil
} | go | func (c *Client) ListOSforBareMetalServer(id string) ([]OS, error) {
var osMap map[string]OS
if err := c.get(`baremetal/os_change_list?SUBID=`+id, &osMap); err != nil {
return nil, err
}
var os []OS
for _, o := range osMap {
os = append(os, o)
}
sort.Sort(oses(os))
return os, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListOSforBareMetalServer",
"(",
"id",
"string",
")",
"(",
"[",
"]",
"OS",
",",
"error",
")",
"{",
"var",
"osMap",
"map",
"[",
"string",
"]",
"OS",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`baremetal/os_... | // ListOSforBareMetalServer lists all available operating systems to which an existing bare metal server can be changed. | [
"ListOSforBareMetalServer",
"lists",
"all",
"available",
"operating",
"systems",
"to",
"which",
"an",
"existing",
"bare",
"metal",
"server",
"can",
"be",
"changed",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L309-L321 |
152,868 | JamesClonk/vultr | lib/bare_metal.go | BandwidthOfBareMetalServer | func (c *Client) BandwidthOfBareMetalServer(id string) ([]map[string]string, error) {
var bandwidthMap map[string][][]interface{}
if err := c.get(`server/bandwidth?SUBID=`+id, &bandwidthMap); err != nil {
return nil, err
}
var bandwidth []map[string]string
// parse incoming bytes
for _, b := range bandwidthMap["incoming_bytes"] {
bMap := make(map[string]string)
bMap["date"] = fmt.Sprintf("%v", b[0])
var bytes int64
switch b[1].(type) {
case float64:
bytes = int64(b[1].(float64))
case int64:
bytes = b[1].(int64)
}
bMap["incoming"] = fmt.Sprintf("%v", bytes)
bandwidth = append(bandwidth, bMap)
}
// parse outgoing bytes (we'll assume that incoming and outgoing dates are always a match)
for _, b := range bandwidthMap["outgoing_bytes"] {
for i := range bandwidth {
if bandwidth[i]["date"] == fmt.Sprintf("%v", b[0]) {
var bytes int64
switch b[1].(type) {
case float64:
bytes = int64(b[1].(float64))
case int64:
bytes = b[1].(int64)
}
bandwidth[i]["outgoing"] = fmt.Sprintf("%v", bytes)
break
}
}
}
return bandwidth, nil
} | go | func (c *Client) BandwidthOfBareMetalServer(id string) ([]map[string]string, error) {
var bandwidthMap map[string][][]interface{}
if err := c.get(`server/bandwidth?SUBID=`+id, &bandwidthMap); err != nil {
return nil, err
}
var bandwidth []map[string]string
// parse incoming bytes
for _, b := range bandwidthMap["incoming_bytes"] {
bMap := make(map[string]string)
bMap["date"] = fmt.Sprintf("%v", b[0])
var bytes int64
switch b[1].(type) {
case float64:
bytes = int64(b[1].(float64))
case int64:
bytes = b[1].(int64)
}
bMap["incoming"] = fmt.Sprintf("%v", bytes)
bandwidth = append(bandwidth, bMap)
}
// parse outgoing bytes (we'll assume that incoming and outgoing dates are always a match)
for _, b := range bandwidthMap["outgoing_bytes"] {
for i := range bandwidth {
if bandwidth[i]["date"] == fmt.Sprintf("%v", b[0]) {
var bytes int64
switch b[1].(type) {
case float64:
bytes = int64(b[1].(float64))
case int64:
bytes = b[1].(int64)
}
bandwidth[i]["outgoing"] = fmt.Sprintf("%v", bytes)
break
}
}
}
return bandwidth, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"BandwidthOfBareMetalServer",
"(",
"id",
"string",
")",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"var",
"bandwidthMap",
"map",
"[",
"string",
"]",
"[",
"]",
"[",
"]",
"interface... | // BandwidthOfBareMetalServer retrieves the bandwidth used by a bare metal server. | [
"BandwidthOfBareMetalServer",
"retrieves",
"the",
"bandwidth",
"used",
"by",
"a",
"bare",
"metal",
"server",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L333-L373 |
152,869 | JamesClonk/vultr | lib/bare_metal.go | ChangeApplicationofBareMetalServer | func (c *Client) ChangeApplicationofBareMetalServer(id string, appID string) error {
values := url.Values{
"SUBID": {id},
"APPID": {appID},
}
return c.post(`baremetal/app_change`, values, nil)
} | go | func (c *Client) ChangeApplicationofBareMetalServer(id string, appID string) error {
values := url.Values{
"SUBID": {id},
"APPID": {appID},
}
return c.post(`baremetal/app_change`, values, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ChangeApplicationofBareMetalServer",
"(",
"id",
"string",
",",
"appID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"appID"... | // ChangeApplicationofBareMetalServer changes the bare metal server to a different application. | [
"ChangeApplicationofBareMetalServer",
"changes",
"the",
"bare",
"metal",
"server",
"to",
"a",
"different",
"application",
"."
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/bare_metal.go#L376-L383 |
152,870 | JamesClonk/vultr | lib/dns.go | GetDNSDomains | func (c *Client) GetDNSDomains() (domains []DNSDomain, err error) {
if err := c.get(`dns/list`, &domains); err != nil {
return nil, err
}
sort.Sort(dnsdomains(domains))
return domains, nil
} | go | func (c *Client) GetDNSDomains() (domains []DNSDomain, err error) {
if err := c.get(`dns/list`, &domains); err != nil {
return nil, err
}
sort.Sort(dnsdomains(domains))
return domains, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetDNSDomains",
"(",
")",
"(",
"domains",
"[",
"]",
"DNSDomain",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`dns/list`",
",",
"&",
"domains",
")",
";",
"err",
"!=",
"nil",
"{",
... | // GetDNSDomains returns a list of available domains on Vultr account | [
"GetDNSDomains",
"returns",
"a",
"list",
"of",
"available",
"domains",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L54-L60 |
152,871 | JamesClonk/vultr | lib/dns.go | GetDNSRecords | func (c *Client) GetDNSRecords(domain string) (records []DNSRecord, err error) {
if err := c.get(`dns/records?domain=`+domain, &records); err != nil {
return nil, err
}
sort.Sort(dnsrecords(records))
return records, nil
} | go | func (c *Client) GetDNSRecords(domain string) (records []DNSRecord, err error) {
if err := c.get(`dns/records?domain=`+domain, &records); err != nil {
return nil, err
}
sort.Sort(dnsrecords(records))
return records, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetDNSRecords",
"(",
"domain",
"string",
")",
"(",
"records",
"[",
"]",
"DNSRecord",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`dns/records?domain=`",
"+",
"domain",
",",
"&",
"rec... | // GetDNSRecords returns a list of all DNS records of a particular domain | [
"GetDNSRecords",
"returns",
"a",
"list",
"of",
"all",
"DNS",
"records",
"of",
"a",
"particular",
"domain"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L63-L69 |
152,872 | JamesClonk/vultr | lib/dns.go | CreateDNSDomain | func (c *Client) CreateDNSDomain(domain, serverIP string) error {
values := url.Values{
"domain": {domain},
"serverip": {serverIP},
}
if err := c.post(`dns/create_domain`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) CreateDNSDomain(domain, serverIP string) error {
values := url.Values{
"domain": {domain},
"serverip": {serverIP},
}
if err := c.post(`dns/create_domain`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateDNSDomain",
"(",
"domain",
",",
"serverIP",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"domain",
"}",
",",
"\"",
"\"",
":",
"{",
"serverIP",
"}",
",",
... | // CreateDNSDomain creates a new DNS domain name on Vultr | [
"CreateDNSDomain",
"creates",
"a",
"new",
"DNS",
"domain",
"name",
"on",
"Vultr"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L72-L82 |
152,873 | JamesClonk/vultr | lib/dns.go | DeleteDNSDomain | func (c *Client) DeleteDNSDomain(domain string) error {
values := url.Values{
"domain": {domain},
}
if err := c.post(`dns/delete_domain`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) DeleteDNSDomain(domain string) error {
values := url.Values{
"domain": {domain},
}
if err := c.post(`dns/delete_domain`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteDNSDomain",
"(",
"domain",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"domain",
"}",
",",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"post",
"(",
"`dns... | // DeleteDNSDomain deletes an existing DNS domain name | [
"DeleteDNSDomain",
"deletes",
"an",
"existing",
"DNS",
"domain",
"name"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L85-L94 |
152,874 | JamesClonk/vultr | lib/dns.go | CreateDNSRecord | func (c *Client) CreateDNSRecord(domain, name, rtype, data string, priority, ttl int) error {
values := url.Values{
"domain": {domain},
"name": {name},
"type": {rtype},
"data": {data},
"priority": {fmt.Sprintf("%v", priority)},
"ttl": {fmt.Sprintf("%v", ttl)},
}
if err := c.post(`dns/create_record`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) CreateDNSRecord(domain, name, rtype, data string, priority, ttl int) error {
values := url.Values{
"domain": {domain},
"name": {name},
"type": {rtype},
"data": {data},
"priority": {fmt.Sprintf("%v", priority)},
"ttl": {fmt.Sprintf("%v", ttl)},
}
if err := c.post(`dns/create_record`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateDNSRecord",
"(",
"domain",
",",
"name",
",",
"rtype",
",",
"data",
"string",
",",
"priority",
",",
"ttl",
"int",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"domai... | // CreateDNSRecord creates a new DNS record | [
"CreateDNSRecord",
"creates",
"a",
"new",
"DNS",
"record"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L97-L111 |
152,875 | JamesClonk/vultr | lib/dns.go | UpdateDNSRecord | func (c *Client) UpdateDNSRecord(domain string, dnsrecord DNSRecord) error {
values := url.Values{
"domain": {domain},
"RECORDID": {fmt.Sprintf("%v", dnsrecord.RecordID)},
}
if dnsrecord.Name != "" {
values.Add("name", dnsrecord.Name)
}
if dnsrecord.Data != "" {
values.Add("data", dnsrecord.Data)
}
if dnsrecord.Priority != 0 {
values.Add("priority", fmt.Sprintf("%v", dnsrecord.Priority))
}
if dnsrecord.TTL != 0 {
values.Add("ttl", fmt.Sprintf("%v", dnsrecord.TTL))
}
if err := c.post(`dns/update_record`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) UpdateDNSRecord(domain string, dnsrecord DNSRecord) error {
values := url.Values{
"domain": {domain},
"RECORDID": {fmt.Sprintf("%v", dnsrecord.RecordID)},
}
if dnsrecord.Name != "" {
values.Add("name", dnsrecord.Name)
}
if dnsrecord.Data != "" {
values.Add("data", dnsrecord.Data)
}
if dnsrecord.Priority != 0 {
values.Add("priority", fmt.Sprintf("%v", dnsrecord.Priority))
}
if dnsrecord.TTL != 0 {
values.Add("ttl", fmt.Sprintf("%v", dnsrecord.TTL))
}
if err := c.post(`dns/update_record`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdateDNSRecord",
"(",
"domain",
"string",
",",
"dnsrecord",
"DNSRecord",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"domain",
"}",
",",
"\"",
"\"",
":",
"{",
"fmt",
".... | // UpdateDNSRecord updates an existing DNS record | [
"UpdateDNSRecord",
"updates",
"an",
"existing",
"DNS",
"record"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L114-L137 |
152,876 | JamesClonk/vultr | lib/dns.go | DeleteDNSRecord | func (c *Client) DeleteDNSRecord(domain string, recordID int) error {
values := url.Values{
"domain": {domain},
"RECORDID": {fmt.Sprintf("%v", recordID)},
}
if err := c.post(`dns/delete_record`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) DeleteDNSRecord(domain string, recordID int) error {
values := url.Values{
"domain": {domain},
"RECORDID": {fmt.Sprintf("%v", recordID)},
}
if err := c.post(`dns/delete_record`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteDNSRecord",
"(",
"domain",
"string",
",",
"recordID",
"int",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"domain",
"}",
",",
"\"",
"\"",
":",
"{",
"fmt",
".",
"S... | // DeleteDNSRecord deletes an existing DNS record | [
"DeleteDNSRecord",
"deletes",
"an",
"existing",
"DNS",
"record"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/dns.go#L140-L150 |
152,877 | JamesClonk/vultr | lib/block_storage.go | UnmarshalJSON | func (b *BlockStorage) UnmarshalJSON(data []byte) (err error) {
if b == nil {
*b = BlockStorage{}
}
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
value := fmt.Sprintf("%v", fields["SUBID"])
if len(value) == 0 || value == "<nil>" || value == "0" {
b.ID = ""
} else {
id, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
b.ID = strconv.FormatFloat(id, 'f', -1, 64)
}
value = fmt.Sprintf("%v", fields["DCID"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
region, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
b.RegionID = int(region)
value = fmt.Sprintf("%v", fields["size_gb"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
size, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
b.SizeGB = int(size)
value = fmt.Sprintf("%v", fields["attached_to_SUBID"])
if len(value) == 0 || value == "<nil>" || value == "0" {
b.AttachedTo = ""
} else {
attached, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
b.AttachedTo = strconv.FormatFloat(attached, 'f', -1, 64)
}
b.Name = fmt.Sprintf("%v", fields["label"])
b.Created = fmt.Sprintf("%v", fields["date_created"])
b.Status = fmt.Sprintf("%v", fields["status"])
b.Cost = fmt.Sprintf("%v", fields["cost_per_month"])
return
} | go | func (b *BlockStorage) UnmarshalJSON(data []byte) (err error) {
if b == nil {
*b = BlockStorage{}
}
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
value := fmt.Sprintf("%v", fields["SUBID"])
if len(value) == 0 || value == "<nil>" || value == "0" {
b.ID = ""
} else {
id, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
b.ID = strconv.FormatFloat(id, 'f', -1, 64)
}
value = fmt.Sprintf("%v", fields["DCID"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
region, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
b.RegionID = int(region)
value = fmt.Sprintf("%v", fields["size_gb"])
if len(value) == 0 || value == "<nil>" {
value = "0"
}
size, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
b.SizeGB = int(size)
value = fmt.Sprintf("%v", fields["attached_to_SUBID"])
if len(value) == 0 || value == "<nil>" || value == "0" {
b.AttachedTo = ""
} else {
attached, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
b.AttachedTo = strconv.FormatFloat(attached, 'f', -1, 64)
}
b.Name = fmt.Sprintf("%v", fields["label"])
b.Created = fmt.Sprintf("%v", fields["date_created"])
b.Status = fmt.Sprintf("%v", fields["status"])
b.Cost = fmt.Sprintf("%v", fields["cost_per_month"])
return
} | [
"func",
"(",
"b",
"*",
"BlockStorage",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"b",
"==",
"nil",
"{",
"*",
"b",
"=",
"BlockStorage",
"{",
"}",
"\n",
"}",
"\n\n",
"var",
"fields",
"map",
"[",
... | // UnmarshalJSON implements json.Unmarshaller on BlockStorage.
// This is needed because the Vultr API is inconsistent in it's JSON responses.
// Some fields can change type, from JSON number to JSON string and vice-versa. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaller",
"on",
"BlockStorage",
".",
"This",
"is",
"needed",
"because",
"the",
"Vultr",
"API",
"is",
"inconsistent",
"in",
"it",
"s",
"JSON",
"responses",
".",
"Some",
"fields",
"can",
"change",
"type",
"from",... | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/block_storage.go#L46-L104 |
152,878 | JamesClonk/vultr | lib/block_storage.go | GetBlockStorages | func (c *Client) GetBlockStorages() (storages []BlockStorage, err error) {
if err := c.get(`block/list`, &storages); err != nil {
return nil, err
}
sort.Sort(blockstorages(storages))
return storages, nil
} | go | func (c *Client) GetBlockStorages() (storages []BlockStorage, err error) {
if err := c.get(`block/list`, &storages); err != nil {
return nil, err
}
sort.Sort(blockstorages(storages))
return storages, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetBlockStorages",
"(",
")",
"(",
"storages",
"[",
"]",
"BlockStorage",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`block/list`",
",",
"&",
"storages",
")",
";",
"err",
"!=",
"nil... | // GetBlockStorages returns a list of all active block storages on Vultr account | [
"GetBlockStorages",
"returns",
"a",
"list",
"of",
"all",
"active",
"block",
"storages",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/block_storage.go#L107-L113 |
152,879 | JamesClonk/vultr | lib/block_storage.go | GetBlockStorage | func (c *Client) GetBlockStorage(id string) (BlockStorage, error) {
storages, err := c.GetBlockStorages()
if err != nil {
return BlockStorage{}, err
}
for _, s := range storages {
if s.ID == id {
return s, nil
}
}
return BlockStorage{}, fmt.Errorf("BlockStorage with ID %v not found", id)
} | go | func (c *Client) GetBlockStorage(id string) (BlockStorage, error) {
storages, err := c.GetBlockStorages()
if err != nil {
return BlockStorage{}, err
}
for _, s := range storages {
if s.ID == id {
return s, nil
}
}
return BlockStorage{}, fmt.Errorf("BlockStorage with ID %v not found", id)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetBlockStorage",
"(",
"id",
"string",
")",
"(",
"BlockStorage",
",",
"error",
")",
"{",
"storages",
",",
"err",
":=",
"c",
".",
"GetBlockStorages",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Bloc... | // GetBlockStorage returns block storage with given ID | [
"GetBlockStorage",
"returns",
"block",
"storage",
"with",
"given",
"ID"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/block_storage.go#L116-L128 |
152,880 | JamesClonk/vultr | lib/block_storage.go | CreateBlockStorage | func (c *Client) CreateBlockStorage(name string, regionID, size int) (BlockStorage, error) {
values := url.Values{
"label": {name},
"DCID": {fmt.Sprintf("%v", regionID)},
"size_gb": {fmt.Sprintf("%v", size)},
}
var storage BlockStorage
if err := c.post(`block/create`, values, &storage); err != nil {
return BlockStorage{}, err
}
storage.RegionID = regionID
storage.Name = name
storage.SizeGB = size
return storage, nil
} | go | func (c *Client) CreateBlockStorage(name string, regionID, size int) (BlockStorage, error) {
values := url.Values{
"label": {name},
"DCID": {fmt.Sprintf("%v", regionID)},
"size_gb": {fmt.Sprintf("%v", size)},
}
var storage BlockStorage
if err := c.post(`block/create`, values, &storage); err != nil {
return BlockStorage{}, err
}
storage.RegionID = regionID
storage.Name = name
storage.SizeGB = size
return storage, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateBlockStorage",
"(",
"name",
"string",
",",
"regionID",
",",
"size",
"int",
")",
"(",
"BlockStorage",
",",
"error",
")",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"name",
"}",
... | // CreateBlockStorage creates a new block storage on Vultr account | [
"CreateBlockStorage",
"creates",
"a",
"new",
"block",
"storage",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/block_storage.go#L131-L147 |
152,881 | JamesClonk/vultr | lib/block_storage.go | ResizeBlockStorage | func (c *Client) ResizeBlockStorage(id string, size int) error {
values := url.Values{
"SUBID": {id},
"size_gb": {fmt.Sprintf("%v", size)},
}
if err := c.post(`block/resize`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) ResizeBlockStorage(id string, size int) error {
values := url.Values{
"SUBID": {id},
"size_gb": {fmt.Sprintf("%v", size)},
}
if err := c.post(`block/resize`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ResizeBlockStorage",
"(",
"id",
"string",
",",
"size",
"int",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"fmt",
".",
"Sprintf",
... | // ResizeBlockStorage resizes an existing block storage | [
"ResizeBlockStorage",
"resizes",
"an",
"existing",
"block",
"storage"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/block_storage.go#L150-L160 |
152,882 | JamesClonk/vultr | lib/block_storage.go | AttachBlockStorage | func (c *Client) AttachBlockStorage(id, serverID string) error {
values := url.Values{
"SUBID": {id},
"attach_to_SUBID": {serverID},
}
if err := c.post(`block/attach`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) AttachBlockStorage(id, serverID string) error {
values := url.Values{
"SUBID": {id},
"attach_to_SUBID": {serverID},
}
if err := c.post(`block/attach`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"AttachBlockStorage",
"(",
"id",
",",
"serverID",
"string",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"id",
"}",
",",
"\"",
"\"",
":",
"{",
"serverID",
"}",
",",
"}",... | // AttachBlockStorage attaches block storage to an existing virtual machine | [
"AttachBlockStorage",
"attaches",
"block",
"storage",
"to",
"an",
"existing",
"virtual",
"machine"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/block_storage.go#L176-L186 |
152,883 | JamesClonk/vultr | lib/backup.go | Less | func (bs backups) Less(i, j int) bool {
timeLayout := "2006-01-02 15:04:05" // oh my : https://golang.org/src/time/format.go
t1, _ := time.Parse(timeLayout, bs[i].Created)
t2, _ := time.Parse(timeLayout, bs[j].Created)
return t1.After(t2)
} | go | func (bs backups) Less(i, j int) bool {
timeLayout := "2006-01-02 15:04:05" // oh my : https://golang.org/src/time/format.go
t1, _ := time.Parse(timeLayout, bs[i].Created)
t2, _ := time.Parse(timeLayout, bs[j].Created)
return t1.After(t2)
} | [
"func",
"(",
"bs",
"backups",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"timeLayout",
":=",
"\"",
"\"",
"// oh my : https://golang.org/src/time/format.go",
"\n",
"t1",
",",
"_",
":=",
"time",
".",
"Parse",
"(",
"timeLayout",
",",
"bs",
"[... | // sort by most recent | [
"sort",
"by",
"most",
"recent"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/backup.go#L25-L30 |
152,884 | JamesClonk/vultr | lib/backup.go | GetBackups | func (c *Client) GetBackups(id string, backupid string) ([]Backup, error) {
var backupMap map[string]Backup
values := url.Values{
"SUBID": {id},
"BACKUPID": {backupid},
}
if err := c.post(`backup/list`, values, &backupMap); err != nil {
return nil, err
}
var backup []Backup
for _, b := range backupMap {
fmt.Println(b)
backup = append(backup, b)
}
sort.Sort(backups(backup))
return backup, nil
} | go | func (c *Client) GetBackups(id string, backupid string) ([]Backup, error) {
var backupMap map[string]Backup
values := url.Values{
"SUBID": {id},
"BACKUPID": {backupid},
}
if err := c.post(`backup/list`, values, &backupMap); err != nil {
return nil, err
}
var backup []Backup
for _, b := range backupMap {
fmt.Println(b)
backup = append(backup, b)
}
sort.Sort(backups(backup))
return backup, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetBackups",
"(",
"id",
"string",
",",
"backupid",
"string",
")",
"(",
"[",
"]",
"Backup",
",",
"error",
")",
"{",
"var",
"backupMap",
"map",
"[",
"string",
"]",
"Backup",
"\n",
"values",
":=",
"url",
".",
"Va... | // GetBackups retrieves a list of all backups on Vultr account | [
"GetBackups",
"retrieves",
"a",
"list",
"of",
"all",
"backups",
"on",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/backup.go#L33-L51 |
152,885 | JamesClonk/vultr | lib/sshkeys.go | GetSSHKeys | func (c *Client) GetSSHKeys() (keys []SSHKey, err error) {
var keyMap map[string]SSHKey
if err := c.get(`sshkey/list`, &keyMap); err != nil {
return nil, err
}
for _, key := range keyMap {
keys = append(keys, key)
}
sort.Sort(sshkeys(keys))
return keys, nil
} | go | func (c *Client) GetSSHKeys() (keys []SSHKey, err error) {
var keyMap map[string]SSHKey
if err := c.get(`sshkey/list`, &keyMap); err != nil {
return nil, err
}
for _, key := range keyMap {
keys = append(keys, key)
}
sort.Sort(sshkeys(keys))
return keys, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetSSHKeys",
"(",
")",
"(",
"keys",
"[",
"]",
"SSHKey",
",",
"err",
"error",
")",
"{",
"var",
"keyMap",
"map",
"[",
"string",
"]",
"SSHKey",
"\n",
"if",
"err",
":=",
"c",
".",
"get",
"(",
"`sshkey/list`",
",... | // GetSSHKeys returns a list of SSHKeys from Vultr account | [
"GetSSHKeys",
"returns",
"a",
"list",
"of",
"SSHKeys",
"from",
"Vultr",
"account"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/sshkeys.go#L24-L35 |
152,886 | JamesClonk/vultr | lib/sshkeys.go | CreateSSHKey | func (c *Client) CreateSSHKey(name, key string) (SSHKey, error) {
values := url.Values{
"name": {name},
"ssh_key": {key},
}
var sshKey SSHKey
if err := c.post(`sshkey/create`, values, &sshKey); err != nil {
return SSHKey{}, err
}
sshKey.Name = name
sshKey.Key = key
return sshKey, nil
} | go | func (c *Client) CreateSSHKey(name, key string) (SSHKey, error) {
values := url.Values{
"name": {name},
"ssh_key": {key},
}
var sshKey SSHKey
if err := c.post(`sshkey/create`, values, &sshKey); err != nil {
return SSHKey{}, err
}
sshKey.Name = name
sshKey.Key = key
return sshKey, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateSSHKey",
"(",
"name",
",",
"key",
"string",
")",
"(",
"SSHKey",
",",
"error",
")",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"name",
"}",
",",
"\"",
"\"",
":",
"{",
"key",... | // CreateSSHKey creates new SSHKey on Vultr | [
"CreateSSHKey",
"creates",
"new",
"SSHKey",
"on",
"Vultr"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/sshkeys.go#L38-L52 |
152,887 | JamesClonk/vultr | lib/sshkeys.go | UpdateSSHKey | func (c *Client) UpdateSSHKey(key SSHKey) error {
values := url.Values{
"SSHKEYID": {key.ID},
}
if key.Name != "" {
values.Add("name", key.Name)
}
if key.Key != "" {
values.Add("ssh_key", key.Key)
}
if err := c.post(`sshkey/update`, values, nil); err != nil {
return err
}
return nil
} | go | func (c *Client) UpdateSSHKey(key SSHKey) error {
values := url.Values{
"SSHKEYID": {key.ID},
}
if key.Name != "" {
values.Add("name", key.Name)
}
if key.Key != "" {
values.Add("ssh_key", key.Key)
}
if err := c.post(`sshkey/update`, values, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"UpdateSSHKey",
"(",
"key",
"SSHKey",
")",
"error",
"{",
"values",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"key",
".",
"ID",
"}",
",",
"}",
"\n",
"if",
"key",
".",
"Name",
"!=",
"\"",
"\"",
... | // UpdateSSHKey updates an existing SSHKey entry | [
"UpdateSSHKey",
"updates",
"an",
"existing",
"SSHKey",
"entry"
] | fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91 | https://github.com/JamesClonk/vultr/blob/fed59ad207c9bda0a5dfe4d18de53ccbb3d80c91/lib/sshkeys.go#L55-L70 |
152,888 | peterbourgon/diskv | diskv.go | New | func New(o Options) *Diskv {
if o.BasePath == "" {
o.BasePath = defaultBasePath
}
if o.AdvancedTransform == nil {
if o.Transform == nil {
o.AdvancedTransform = defaultAdvancedTransform
} else {
o.AdvancedTransform = convertToAdvancedTransform(o.Transform)
}
if o.InverseTransform == nil {
o.InverseTransform = defaultInverseTransform
}
} else {
if o.InverseTransform == nil {
panic("You must provide an InverseTransform function in advanced mode")
}
}
if o.PathPerm == 0 {
o.PathPerm = defaultPathPerm
}
if o.FilePerm == 0 {
o.FilePerm = defaultFilePerm
}
d := &Diskv{
Options: o,
cache: map[string][]byte{},
cacheSize: 0,
}
if d.Index != nil && d.IndexLess != nil {
d.Index.Initialize(d.IndexLess, d.Keys(nil))
}
return d
} | go | func New(o Options) *Diskv {
if o.BasePath == "" {
o.BasePath = defaultBasePath
}
if o.AdvancedTransform == nil {
if o.Transform == nil {
o.AdvancedTransform = defaultAdvancedTransform
} else {
o.AdvancedTransform = convertToAdvancedTransform(o.Transform)
}
if o.InverseTransform == nil {
o.InverseTransform = defaultInverseTransform
}
} else {
if o.InverseTransform == nil {
panic("You must provide an InverseTransform function in advanced mode")
}
}
if o.PathPerm == 0 {
o.PathPerm = defaultPathPerm
}
if o.FilePerm == 0 {
o.FilePerm = defaultFilePerm
}
d := &Diskv{
Options: o,
cache: map[string][]byte{},
cacheSize: 0,
}
if d.Index != nil && d.IndexLess != nil {
d.Index.Initialize(d.IndexLess, d.Keys(nil))
}
return d
} | [
"func",
"New",
"(",
"o",
"Options",
")",
"*",
"Diskv",
"{",
"if",
"o",
".",
"BasePath",
"==",
"\"",
"\"",
"{",
"o",
".",
"BasePath",
"=",
"defaultBasePath",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"AdvancedTransform",
"==",
"nil",
"{",
"if",
"o",
".",
... | // New returns an initialized Diskv structure, ready to use.
// If the path identified by baseDir already contains data,
// it will be accessible, but not yet cached. | [
"New",
"returns",
"an",
"initialized",
"Diskv",
"structure",
"ready",
"to",
"use",
".",
"If",
"the",
"path",
"identified",
"by",
"baseDir",
"already",
"contains",
"data",
"it",
"will",
"be",
"accessible",
"but",
"not",
"yet",
"cached",
"."
] | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L104-L142 |
152,889 | peterbourgon/diskv | diskv.go | convertToAdvancedTransform | func convertToAdvancedTransform(oldFunc func(s string) []string) AdvancedTransformFunction {
return func(s string) *PathKey {
return &PathKey{Path: oldFunc(s), FileName: s}
}
} | go | func convertToAdvancedTransform(oldFunc func(s string) []string) AdvancedTransformFunction {
return func(s string) *PathKey {
return &PathKey{Path: oldFunc(s), FileName: s}
}
} | [
"func",
"convertToAdvancedTransform",
"(",
"oldFunc",
"func",
"(",
"s",
"string",
")",
"[",
"]",
"string",
")",
"AdvancedTransformFunction",
"{",
"return",
"func",
"(",
"s",
"string",
")",
"*",
"PathKey",
"{",
"return",
"&",
"PathKey",
"{",
"Path",
":",
"o... | // convertToAdvancedTransform takes a classic Transform function and
// converts it to the new AdvancedTransform | [
"convertToAdvancedTransform",
"takes",
"a",
"classic",
"Transform",
"function",
"and",
"converts",
"it",
"to",
"the",
"new",
"AdvancedTransform"
] | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L146-L150 |
152,890 | peterbourgon/diskv | diskv.go | Write | func (d *Diskv) Write(key string, val []byte) error {
return d.WriteStream(key, bytes.NewReader(val), false)
} | go | func (d *Diskv) Write(key string, val []byte) error {
return d.WriteStream(key, bytes.NewReader(val), false)
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"Write",
"(",
"key",
"string",
",",
"val",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"d",
".",
"WriteStream",
"(",
"key",
",",
"bytes",
".",
"NewReader",
"(",
"val",
")",
",",
"false",
")",
"\n",
"}"
] | // Write synchronously writes the key-value pair to disk, making it immediately
// available for reads. Write relies on the filesystem to perform an eventual
// sync to physical media. If you need stronger guarantees, see WriteStream. | [
"Write",
"synchronously",
"writes",
"the",
"key",
"-",
"value",
"pair",
"to",
"disk",
"making",
"it",
"immediately",
"available",
"for",
"reads",
".",
"Write",
"relies",
"on",
"the",
"filesystem",
"to",
"perform",
"an",
"eventual",
"sync",
"to",
"physical",
... | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L155-L157 |
152,891 | peterbourgon/diskv | diskv.go | WriteString | func (d *Diskv) WriteString(key string, val string) error {
return d.Write(key, []byte(val))
} | go | func (d *Diskv) WriteString(key string, val string) error {
return d.Write(key, []byte(val))
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"WriteString",
"(",
"key",
"string",
",",
"val",
"string",
")",
"error",
"{",
"return",
"d",
".",
"Write",
"(",
"key",
",",
"[",
"]",
"byte",
"(",
"val",
")",
")",
"\n",
"}"
] | // WriteString writes a string key-value pair to disk | [
"WriteString",
"writes",
"a",
"string",
"key",
"-",
"value",
"pair",
"to",
"disk"
] | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L160-L162 |
152,892 | peterbourgon/diskv | diskv.go | WriteStream | func (d *Diskv) WriteStream(key string, r io.Reader, sync bool) error {
if len(key) <= 0 {
return errEmptyKey
}
pathKey := d.transform(key)
// Ensure keys cannot evaluate to paths that would not exist
for _, pathPart := range pathKey.Path {
if strings.ContainsRune(pathPart, os.PathSeparator) {
return errBadKey
}
}
if strings.ContainsRune(pathKey.FileName, os.PathSeparator) {
return errBadKey
}
d.mu.Lock()
defer d.mu.Unlock()
return d.writeStreamWithLock(pathKey, r, sync)
} | go | func (d *Diskv) WriteStream(key string, r io.Reader, sync bool) error {
if len(key) <= 0 {
return errEmptyKey
}
pathKey := d.transform(key)
// Ensure keys cannot evaluate to paths that would not exist
for _, pathPart := range pathKey.Path {
if strings.ContainsRune(pathPart, os.PathSeparator) {
return errBadKey
}
}
if strings.ContainsRune(pathKey.FileName, os.PathSeparator) {
return errBadKey
}
d.mu.Lock()
defer d.mu.Unlock()
return d.writeStreamWithLock(pathKey, r, sync)
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"WriteStream",
"(",
"key",
"string",
",",
"r",
"io",
".",
"Reader",
",",
"sync",
"bool",
")",
"error",
"{",
"if",
"len",
"(",
"key",
")",
"<=",
"0",
"{",
"return",
"errEmptyKey",
"\n",
"}",
"\n\n",
"pathKey",
... | // WriteStream writes the data represented by the io.Reader to the disk, under
// the provided key. If sync is true, WriteStream performs an explicit sync on
// the file as soon as it's written.
//
// bytes.Buffer provides io.Reader semantics for basic data types. | [
"WriteStream",
"writes",
"the",
"data",
"represented",
"by",
"the",
"io",
".",
"Reader",
"to",
"the",
"disk",
"under",
"the",
"provided",
"key",
".",
"If",
"sync",
"is",
"true",
"WriteStream",
"performs",
"an",
"explicit",
"sync",
"on",
"the",
"file",
"as"... | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L175-L197 |
152,893 | peterbourgon/diskv | diskv.go | createKeyFileWithLock | func (d *Diskv) createKeyFileWithLock(pathKey *PathKey) (*os.File, error) {
if d.TempDir != "" {
if err := os.MkdirAll(d.TempDir, d.PathPerm); err != nil {
return nil, fmt.Errorf("temp mkdir: %s", err)
}
f, err := ioutil.TempFile(d.TempDir, "")
if err != nil {
return nil, fmt.Errorf("temp file: %s", err)
}
if err := f.Chmod(d.FilePerm); err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return nil, fmt.Errorf("chmod: %s", err)
}
return f, nil
}
mode := os.O_WRONLY | os.O_CREATE | os.O_TRUNC // overwrite if exists
f, err := os.OpenFile(d.completeFilename(pathKey), mode, d.FilePerm)
if err != nil {
return nil, fmt.Errorf("open file: %s", err)
}
return f, nil
} | go | func (d *Diskv) createKeyFileWithLock(pathKey *PathKey) (*os.File, error) {
if d.TempDir != "" {
if err := os.MkdirAll(d.TempDir, d.PathPerm); err != nil {
return nil, fmt.Errorf("temp mkdir: %s", err)
}
f, err := ioutil.TempFile(d.TempDir, "")
if err != nil {
return nil, fmt.Errorf("temp file: %s", err)
}
if err := f.Chmod(d.FilePerm); err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return nil, fmt.Errorf("chmod: %s", err)
}
return f, nil
}
mode := os.O_WRONLY | os.O_CREATE | os.O_TRUNC // overwrite if exists
f, err := os.OpenFile(d.completeFilename(pathKey), mode, d.FilePerm)
if err != nil {
return nil, fmt.Errorf("open file: %s", err)
}
return f, nil
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"createKeyFileWithLock",
"(",
"pathKey",
"*",
"PathKey",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"if",
"d",
".",
"TempDir",
"!=",
"\"",
"\"",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(... | // createKeyFileWithLock either creates the key file directly, or
// creates a temporary file in TempDir if it is set. | [
"createKeyFileWithLock",
"either",
"creates",
"the",
"key",
"file",
"directly",
"or",
"creates",
"a",
"temporary",
"file",
"in",
"TempDir",
"if",
"it",
"is",
"set",
"."
] | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L201-L225 |
152,894 | peterbourgon/diskv | diskv.go | writeStreamWithLock | func (d *Diskv) writeStreamWithLock(pathKey *PathKey, r io.Reader, sync bool) error {
if err := d.ensurePathWithLock(pathKey); err != nil {
return fmt.Errorf("ensure path: %s", err)
}
f, err := d.createKeyFileWithLock(pathKey)
if err != nil {
return fmt.Errorf("create key file: %s", err)
}
wc := io.WriteCloser(&nopWriteCloser{f})
if d.Compression != nil {
wc, err = d.Compression.Writer(f)
if err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("compression writer: %s", err)
}
}
if _, err := io.Copy(wc, r); err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("i/o copy: %s", err)
}
if err := wc.Close(); err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("compression close: %s", err)
}
if sync {
if err := f.Sync(); err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("file sync: %s", err)
}
}
if err := f.Close(); err != nil {
return fmt.Errorf("file close: %s", err)
}
fullPath := d.completeFilename(pathKey)
if f.Name() != fullPath {
if err := os.Rename(f.Name(), fullPath); err != nil {
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("rename: %s", err)
}
}
if d.Index != nil {
d.Index.Insert(pathKey.originalKey)
}
d.bustCacheWithLock(pathKey.originalKey) // cache only on read
return nil
} | go | func (d *Diskv) writeStreamWithLock(pathKey *PathKey, r io.Reader, sync bool) error {
if err := d.ensurePathWithLock(pathKey); err != nil {
return fmt.Errorf("ensure path: %s", err)
}
f, err := d.createKeyFileWithLock(pathKey)
if err != nil {
return fmt.Errorf("create key file: %s", err)
}
wc := io.WriteCloser(&nopWriteCloser{f})
if d.Compression != nil {
wc, err = d.Compression.Writer(f)
if err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("compression writer: %s", err)
}
}
if _, err := io.Copy(wc, r); err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("i/o copy: %s", err)
}
if err := wc.Close(); err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("compression close: %s", err)
}
if sync {
if err := f.Sync(); err != nil {
f.Close() // error deliberately ignored
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("file sync: %s", err)
}
}
if err := f.Close(); err != nil {
return fmt.Errorf("file close: %s", err)
}
fullPath := d.completeFilename(pathKey)
if f.Name() != fullPath {
if err := os.Rename(f.Name(), fullPath); err != nil {
os.Remove(f.Name()) // error deliberately ignored
return fmt.Errorf("rename: %s", err)
}
}
if d.Index != nil {
d.Index.Insert(pathKey.originalKey)
}
d.bustCacheWithLock(pathKey.originalKey) // cache only on read
return nil
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"writeStreamWithLock",
"(",
"pathKey",
"*",
"PathKey",
",",
"r",
"io",
".",
"Reader",
",",
"sync",
"bool",
")",
"error",
"{",
"if",
"err",
":=",
"d",
".",
"ensurePathWithLock",
"(",
"pathKey",
")",
";",
"err",
"!=... | // writeStream does no input validation checking. | [
"writeStream",
"does",
"no",
"input",
"validation",
"checking",
"."
] | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L228-L287 |
152,895 | peterbourgon/diskv | diskv.go | Import | func (d *Diskv) Import(srcFilename, dstKey string, move bool) (err error) {
if dstKey == "" {
return errEmptyKey
}
if fi, err := os.Stat(srcFilename); err != nil {
return err
} else if fi.IsDir() {
return errImportDirectory
}
dstPathKey := d.transform(dstKey)
d.mu.Lock()
defer d.mu.Unlock()
if err := d.ensurePathWithLock(dstPathKey); err != nil {
return fmt.Errorf("ensure path: %s", err)
}
if move {
if err := syscall.Rename(srcFilename, d.completeFilename(dstPathKey)); err == nil {
d.bustCacheWithLock(dstPathKey.originalKey)
return nil
} else if err != syscall.EXDEV {
// If it failed due to being on a different device, fall back to copying
return err
}
}
f, err := os.Open(srcFilename)
if err != nil {
return err
}
defer f.Close()
err = d.writeStreamWithLock(dstPathKey, f, false)
if err == nil && move {
err = os.Remove(srcFilename)
}
return err
} | go | func (d *Diskv) Import(srcFilename, dstKey string, move bool) (err error) {
if dstKey == "" {
return errEmptyKey
}
if fi, err := os.Stat(srcFilename); err != nil {
return err
} else if fi.IsDir() {
return errImportDirectory
}
dstPathKey := d.transform(dstKey)
d.mu.Lock()
defer d.mu.Unlock()
if err := d.ensurePathWithLock(dstPathKey); err != nil {
return fmt.Errorf("ensure path: %s", err)
}
if move {
if err := syscall.Rename(srcFilename, d.completeFilename(dstPathKey)); err == nil {
d.bustCacheWithLock(dstPathKey.originalKey)
return nil
} else if err != syscall.EXDEV {
// If it failed due to being on a different device, fall back to copying
return err
}
}
f, err := os.Open(srcFilename)
if err != nil {
return err
}
defer f.Close()
err = d.writeStreamWithLock(dstPathKey, f, false)
if err == nil && move {
err = os.Remove(srcFilename)
}
return err
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"Import",
"(",
"srcFilename",
",",
"dstKey",
"string",
",",
"move",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"if",
"dstKey",
"==",
"\"",
"\"",
"{",
"return",
"errEmptyKey",
"\n",
"}",
"\n\n",
"if",
"fi",
",",... | // Import imports the source file into diskv under the destination key. If the
// destination key already exists, it's overwritten. If move is true, the
// source file is removed after a successful import. | [
"Import",
"imports",
"the",
"source",
"file",
"into",
"diskv",
"under",
"the",
"destination",
"key",
".",
"If",
"the",
"destination",
"key",
"already",
"exists",
"it",
"s",
"overwritten",
".",
"If",
"move",
"is",
"true",
"the",
"source",
"file",
"is",
"rem... | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L292-L332 |
152,896 | peterbourgon/diskv | diskv.go | Read | func (d *Diskv) Read(key string) ([]byte, error) {
rc, err := d.ReadStream(key, false)
if err != nil {
return []byte{}, err
}
defer rc.Close()
return ioutil.ReadAll(rc)
} | go | func (d *Diskv) Read(key string) ([]byte, error) {
rc, err := d.ReadStream(key, false)
if err != nil {
return []byte{}, err
}
defer rc.Close()
return ioutil.ReadAll(rc)
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"Read",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"rc",
",",
"err",
":=",
"d",
".",
"ReadStream",
"(",
"key",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // Read reads the key and returns the value.
// If the key is available in the cache, Read won't touch the disk.
// If the key is not in the cache, Read will have the side-effect of
// lazily caching the value. | [
"Read",
"reads",
"the",
"key",
"and",
"returns",
"the",
"value",
".",
"If",
"the",
"key",
"is",
"available",
"in",
"the",
"cache",
"Read",
"won",
"t",
"touch",
"the",
"disk",
".",
"If",
"the",
"key",
"is",
"not",
"in",
"the",
"cache",
"Read",
"will",... | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L338-L345 |
152,897 | peterbourgon/diskv | diskv.go | ReadString | func (d *Diskv) ReadString(key string) string {
value, _ := d.Read(key)
return string(value)
} | go | func (d *Diskv) ReadString(key string) string {
value, _ := d.Read(key)
return string(value)
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"ReadString",
"(",
"key",
"string",
")",
"string",
"{",
"value",
",",
"_",
":=",
"d",
".",
"Read",
"(",
"key",
")",
"\n",
"return",
"string",
"(",
"value",
")",
"\n",
"}"
] | // ReadString reads the key and returns a string value
// In case of error, an empty string is returned | [
"ReadString",
"reads",
"the",
"key",
"and",
"returns",
"a",
"string",
"value",
"In",
"case",
"of",
"error",
"an",
"empty",
"string",
"is",
"returned"
] | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L349-L352 |
152,898 | peterbourgon/diskv | diskv.go | readWithRLock | func (d *Diskv) readWithRLock(pathKey *PathKey) (io.ReadCloser, error) {
filename := d.completeFilename(pathKey)
fi, err := os.Stat(filename)
if err != nil {
return nil, err
}
if fi.IsDir() {
return nil, os.ErrNotExist
}
f, err := os.Open(filename)
if err != nil {
return nil, err
}
var r io.Reader
if d.CacheSizeMax > 0 {
r = newSiphon(f, d, pathKey.originalKey)
} else {
r = &closingReader{f}
}
var rc = io.ReadCloser(ioutil.NopCloser(r))
if d.Compression != nil {
rc, err = d.Compression.Reader(r)
if err != nil {
return nil, err
}
}
return rc, nil
} | go | func (d *Diskv) readWithRLock(pathKey *PathKey) (io.ReadCloser, error) {
filename := d.completeFilename(pathKey)
fi, err := os.Stat(filename)
if err != nil {
return nil, err
}
if fi.IsDir() {
return nil, os.ErrNotExist
}
f, err := os.Open(filename)
if err != nil {
return nil, err
}
var r io.Reader
if d.CacheSizeMax > 0 {
r = newSiphon(f, d, pathKey.originalKey)
} else {
r = &closingReader{f}
}
var rc = io.ReadCloser(ioutil.NopCloser(r))
if d.Compression != nil {
rc, err = d.Compression.Reader(r)
if err != nil {
return nil, err
}
}
return rc, nil
} | [
"func",
"(",
"d",
"*",
"Diskv",
")",
"readWithRLock",
"(",
"pathKey",
"*",
"PathKey",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"filename",
":=",
"d",
".",
"completeFilename",
"(",
"pathKey",
")",
"\n\n",
"fi",
",",
"err",
":=",
"os"... | // read ignores the cache, and returns an io.ReadCloser representing the
// decompressed data for the given key, streamed from the disk. Clients should
// acquire a read lock on the Diskv and check the cache themselves before
// calling read. | [
"read",
"ignores",
"the",
"cache",
"and",
"returns",
"an",
"io",
".",
"ReadCloser",
"representing",
"the",
"decompressed",
"data",
"for",
"the",
"given",
"key",
"streamed",
"from",
"the",
"disk",
".",
"Clients",
"should",
"acquire",
"a",
"read",
"lock",
"on"... | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L393-L425 |
152,899 | peterbourgon/diskv | diskv.go | newSiphon | func newSiphon(f *os.File, d *Diskv, key string) io.Reader {
return &siphon{
f: f,
d: d,
key: key,
buf: &bytes.Buffer{},
}
} | go | func newSiphon(f *os.File, d *Diskv, key string) io.Reader {
return &siphon{
f: f,
d: d,
key: key,
buf: &bytes.Buffer{},
}
} | [
"func",
"newSiphon",
"(",
"f",
"*",
"os",
".",
"File",
",",
"d",
"*",
"Diskv",
",",
"key",
"string",
")",
"io",
".",
"Reader",
"{",
"return",
"&",
"siphon",
"{",
"f",
":",
"f",
",",
"d",
":",
"d",
",",
"key",
":",
"key",
",",
"buf",
":",
"&... | // newSiphon constructs a siphoning reader that represents the passed file.
// When a successful series of reads ends in an EOF, the siphon will write
// the buffered data to Diskv's cache under the given key. | [
"newSiphon",
"constructs",
"a",
"siphoning",
"reader",
"that",
"represents",
"the",
"passed",
"file",
".",
"When",
"a",
"successful",
"series",
"of",
"reads",
"ends",
"in",
"an",
"EOF",
"the",
"siphon",
"will",
"write",
"the",
"buffered",
"data",
"to",
"Disk... | 0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6 | https://github.com/peterbourgon/diskv/blob/0be1b92a6df0e4f5cb0a5d15fb7f643d0ad93ce6/diskv.go#L455-L462 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.