You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
910 B
40 lines
910 B
package main |
|
|
|
import ( |
|
"bytes" |
|
"log" |
|
"net/http" |
|
"io/ioutil" |
|
"strings" |
|
"encoding/json" |
|
/* |
|
"fmt" |
|
*/ |
|
) |
|
|
|
/*droplet_api := io.Post("") |
|
*/ |
|
|
|
func main() { |
|
url_slice := []string{"https://api.digitalocean.com/v2/droplets/", get_droplet_id("foo"), "/actions"} |
|
droplet_actions_url := strings.Join(url_slice, "") |
|
post_body, _ := json.Marshal(map[string]string{"type": "power_off"}) |
|
response_body := bytes.NewBuffer(post_body) |
|
http_response, err := http.Post(droplet_actions_url, "application/json", response_body) |
|
if err != nil { |
|
log.Fatalf("Respones Error: %v", err) |
|
} |
|
defer http_response.Body.Close() |
|
body, err := ioutil.ReadAll(response_body) |
|
if err != nil { |
|
log.Fatalln(err) |
|
} |
|
response_body_string := string(body) |
|
log.Printf(response_body_string) |
|
} |
|
|
|
func get_droplet_id(hostname string) string { |
|
// var droplet_id string = "253365345" |
|
var droplet_id string = "253365347" |
|
return droplet_id |
|
}
|
|
|