diff --git a/main.go b/main.go new file mode 100644 index 0000000..01b7219 --- /dev/null +++ b/main.go @@ -0,0 +1,40 @@ +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 +}